@@ -6,7 +6,7 @@ import { API_URL } from "../config";
66import { INVALID_PARAMS , INVALID_QUERY , NOT_FOUND } from "../error" ;
77import MissionModel from "../models/mission" ;
88import RequestModel from "../models/request" ;
9- import { Mission } from "../types" ;
9+ import { Mission , Publisher } from "../types" ;
1010import { PublisherRequest } from "../types/passport" ;
1111import { diacriticSensitiveRegex } from "../utils" ;
1212
@@ -40,6 +40,7 @@ router.use(async (req: PublisherRequest, res: Response, next: NextFunction) => {
4040
4141router . get ( "/" , passport . authenticate ( [ "apikey" , "api" ] , { session : false } ) , async ( req : PublisherRequest , res : Response , next : NextFunction ) => {
4242 try {
43+ const user = req . user as Publisher ;
4344 const query = zod
4445 . object ( {
4546 keywords : zod . string ( ) . optional ( ) ,
@@ -60,15 +61,15 @@ router.get("/", passport.authenticate(["apikey", "api"], { session: false }), as
6061 return res . status ( 400 ) . send ( { ok : false , code : INVALID_QUERY , message : query . error } ) ;
6162 }
6263
63- if ( ! req . user . publishers || ! req . user . publishers . length ) {
64+ if ( ! user . publishers || ! user . publishers . length ) {
6465 res . locals = { code : NO_PARTNER , message : NO_PARTNER_MESSAGE } ;
6566 return res . status ( 400 ) . send ( { ok : false , code : NO_PARTNER , message : NO_PARTNER_MESSAGE } ) ;
6667 }
6768
6869 const where = {
6970 statusCode : "ACCEPTED" ,
7071 deleted : false ,
71- publisherId : { $in : req . user . publishers . map ( ( e : { publisher : string } ) => e . publisher ) } ,
72+ publisherId : { $in : user . publishers . map ( ( e ) => e . publisherId ) } ,
7273 } as { [ key : string ] : any } ;
7374
7475 if ( query . data . keywords ) {
@@ -94,8 +95,8 @@ router.get("/", passport.authenticate(["apikey", "api"], { session: false }), as
9495 where . snu = true ;
9596 }
9697
97- if ( req . user . moderator ) {
98- where [ `moderation_${ req . user . _id } _status` ] = "ACCEPTED" ;
98+ if ( user . moderator ) {
99+ where [ `moderation_${ user . _id } _status` ] = "ACCEPTED" ;
99100 }
100101
101102 const $facet = { } as { [ key : string ] : any } ;
@@ -131,7 +132,7 @@ router.get("/", passport.authenticate(["apikey", "api"], { session: false }), as
131132 return res . status ( 200 ) . send ( {
132133 ok : true ,
133134 total,
134- data : data . map ( ( e : Mission ) => buildData ( e , req . user . _id , req . user . moderator ) ) ,
135+ data : data . map ( ( e : Mission ) => buildData ( e , user . _id . toString ( ) , user . moderator ) ) ,
135136 facets,
136137 skip : query . data . skip ,
137138 limit : query . data . limit ,
@@ -143,6 +144,7 @@ router.get("/", passport.authenticate(["apikey", "api"], { session: false }), as
143144
144145router . get ( "/:id" , passport . authenticate ( [ "apikey" , "api" ] , { session : false } ) , async ( req : PublisherRequest , res : Response , next : NextFunction ) => {
145146 try {
147+ const user = req . user as Publisher ;
146148 const params = zod
147149 . object ( {
148150 id : zod . string ( ) ,
@@ -160,7 +162,7 @@ router.get("/:id", passport.authenticate(["apikey", "api"], { session: false }),
160162 }
161163
162164 res . locals = { total : 1 } ;
163- return res . status ( 200 ) . send ( { ok : true , data : buildData ( mission , req . user . _id , req . user . moderator ) } ) ;
165+ return res . status ( 200 ) . send ( { ok : true , data : buildData ( mission , user . _id . toString ( ) , user . moderator ) } ) ;
164166 } catch ( error : any ) {
165167 next ( error ) ;
166168 }
0 commit comments