|
|
@@ -30,14 +30,78 @@ module.exports = (crowi) => {
|
|
|
|
|
|
const paginationResult = await inAppNotificationService.getLatestNotificationsByUser(user._id, requestLimit, offset);
|
|
|
|
|
|
- // TODO: serialize actionUsers as well by #80112
|
|
|
+ interface IdocType {
|
|
|
+ status: string,
|
|
|
+ _id: string
|
|
|
+ action: string,
|
|
|
+ target: [],
|
|
|
+ user: [],
|
|
|
+ createdAt: Date,
|
|
|
+ targetModel: string,
|
|
|
+ actionUsers: Array<typeof User>,
|
|
|
+ id: string,
|
|
|
+ }
|
|
|
+
|
|
|
+ interface InewPaginationResult {
|
|
|
+ docs: Array<IdocType | null>,
|
|
|
+ totalDocs: number,
|
|
|
+ offset: number,
|
|
|
+ limit: number,
|
|
|
+ totalPages: number,
|
|
|
+ page: number,
|
|
|
+ pagingCounter: number,
|
|
|
+ hasPrevPage: boolean,
|
|
|
+ hasNextPage: boolean,
|
|
|
+ prevPage: number | null,
|
|
|
+ nextPage: number | null,
|
|
|
+ }
|
|
|
+
|
|
|
+ const newPaginationResult: InewPaginationResult = {
|
|
|
+ docs: [],
|
|
|
+ totalDocs: paginationResult.totalDocs,
|
|
|
+ offset: paginationResult.offset,
|
|
|
+ limit: paginationResult.limit,
|
|
|
+ totalPages: paginationResult.totalPages,
|
|
|
+ page: paginationResult.page,
|
|
|
+ pagingCounter: paginationResult.pagingCounter,
|
|
|
+ hasPrevPage: paginationResult.hasPrevPage,
|
|
|
+ hasNextPage: paginationResult.hasNextPage,
|
|
|
+ prevPage: paginationResult.prevPage,
|
|
|
+ nextPage: paginationResult.nextPage,
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
paginationResult.docs.forEach((doc) => {
|
|
|
+ let seriarizedUser;
|
|
|
if (doc.user != null && doc.user instanceof User) {
|
|
|
- doc.user = serializeUserSecurely(doc.user);
|
|
|
+ seriarizedUser = serializeUserSecurely(doc.user);
|
|
|
}
|
|
|
+
|
|
|
+ const serializedActionUsers = doc.actionUsers.map((actionUser) => {
|
|
|
+ return serializeUserSecurely(actionUser);
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log('serializedActionUsers', serializedActionUsers);
|
|
|
+
|
|
|
+ newPaginationResult.docs.push({
|
|
|
+ status: doc.status,
|
|
|
+ _id: doc._id,
|
|
|
+ action: doc.action,
|
|
|
+ target: doc.target,
|
|
|
+ user: seriarizedUser,
|
|
|
+ createdAt: doc.createdAt,
|
|
|
+ targetModel: doc.targetModel,
|
|
|
+ actionUsers: serializedActionUsers,
|
|
|
+ id: doc.status,
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ console.log('serializedActionUsers', serializedActionUsers);
|
|
|
+
|
|
|
+ // console.log('newPaginationResult', newPaginationResult);
|
|
|
});
|
|
|
|
|
|
- return res.apiv3(paginationResult);
|
|
|
+ return res.apiv3(newPaginationResult);
|
|
|
|
|
|
});
|
|
|
|