Skip to content

Commit cd506b9

Browse files
Mise à jour de la méthode findAndCount pour renvoyer un tableau de données et un compteur
1 parent 1323f6a commit cd506b9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/_common/abstracts/abstract.service.schema.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ export abstract class AbstractServiceSchema extends AbstractService implements S
6565
}
6666
}
6767
let count = await this._model.countDocuments(filter).exec()
68-
let total = await this._model.find<T & Query<T, T, any, T>>(filter, projection, options).exec()
68+
let data = await this._model.find<T & Query<T, T, any, T>>(filter, projection, options).exec()
6969
if (this.eventEmitter) {
7070
const afterEvents = await this.eventEmitter?.emitAsync(
7171
[this.moduleName.toLowerCase(), this.serviceName.toLowerCase(), 'service', 'afterFindAndCount'].join(EventEmitterSeparator),
72-
{ total, count },
72+
{ data, count },
7373
)
7474
for (const afterEvent of afterEvents) {
75-
if (afterEvent?.total) total = { ...total, ...afterEvent.total }
75+
if (afterEvent?.data) data = { ...data, ...afterEvent.data }
7676
if (afterEvent?.count) count += afterEvent.count
7777
}
7878
}
79-
return [total, count]
79+
return [data, count]
8080
}
8181

8282
public async findById<T extends AbstractSchema | Document>(

src/management/identities/identities.controller.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('IdentitiesController', () => {
4545
() => Promise.resolve({ ...IdentitiesDtoStub(), _id, state: IdentityState.TO_COMPLETE }),
4646
],
4747
findAndCount: [
48-
() => Promise.resolve({ data: [{ ...IdentitiesDtoStub(), _id }], total: 1 }),
48+
() => Promise.resolve([[{ ...IdentitiesDtoStub(), _id }], 1]),
4949
() => Promise.reject(new Error('Error')), // Function that throws an error
5050
],
5151
findOne: [() => Promise.resolve({ ...IdentitiesDtoStub(), _id }), () => Promise.reject(new Error('Error'))],

0 commit comments

Comments
 (0)