Skip to content
Snippets Groups Projects
Commit 8b17c4bd authored by Ivan Alglave's avatar Ivan Alglave
Browse files

Changed findAll to use Promise and return actual group JSON object and not...

Changed findAll to use Promise and return actual group JSON object and not observer containing the object
parent ab81cd0c
No related branches found
No related tags found
1 merge request!2Crud groups
......@@ -13,8 +13,13 @@ export class GroupsDao {
private readonly _groupModel: Model<Group>,
) {}
find = (): Observable<Group[]> =>
from(this._groupModel.find({})).pipe(map((groups) => [].concat(groups)));
find = (): Promise<Group[]> =>
new Promise((resolve, reject) => {
this._groupModel.find({}, {}, {}, (err, value) => {
if (err) reject(err.message);
resolve(value);
});
});
findById = (id: string): Observable<Group | void> =>
from(this._groupModel.findById(id));
......
......@@ -18,7 +18,7 @@ export class GroupsController {
constructor(private readonly _groupsService: GroupsService) {}
@Get()
findAll(): Observable<GroupEntity[] | void> {
findAll(): Promise<GroupEntity[] | void> {
return this._groupsService.findAll();
}
......
......@@ -23,12 +23,7 @@ import { GroupEntity } from './entities/group.entity';
export class GroupsService {
constructor(private readonly _groupsDao: GroupsDao) {}
findAll = (): Observable<GroupEntity[] | void> =>
this._groupsDao.find().pipe(
filter(Boolean),
map((groups) => (groups || []).map((group) => new GroupEntity(group))),
defaultIfEmpty(undefined),
);
findAll = (): Promise<GroupEntity[] | void> => this._groupsDao.find();
findOne = (id: string): Observable<GroupEntity> =>
this._groupsDao.findById(id).pipe(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment