@@ -19,6 +19,7 @@ export const POST_SubscriptionValidator = [
1919 body ( "state" ) . exists ( ) . isBoolean ( ) ,
2020 body ( "expiry" ) . optional ( ) . isISO8601 ( ) ,
2121 body ( "tier" ) . optional ( ) . isString ( ) . isLength ( { max : 128 } ) ,
22+ body ( "subscriptionIdentifier" ) . optional ( ) . custom ( ( value ) => typeof value === "string" || typeof value === "number" ) ,
2223] ;
2324
2425const POST_Subscription = async ( req : Request , res : Response ) : Promise < void > => {
@@ -31,6 +32,7 @@ const POST_Subscription = async (req: Request, res: Response): Promise<void> =>
3132 const state = req . body . state ;
3233 const tier = req . body . tier ;
3334 const expiry = req . body . expiry ;
35+ const subscriptionIdentifier = req . body . subscriptionIdentifier ;
3436 if ( state === true && ! expiry ) {
3537 const errors = [
3638 {
@@ -53,14 +55,17 @@ const POST_Subscription = async (req: Request, res: Response): Promise<void> =>
5355 res . status ( statusCodes . clientInputError ) . json ( new ErrorResponse ( errorMessages . clientInputError , { errors } ) ) ;
5456 return ;
5557 }
56- const query = {
58+ const query : any = {
5759 $set : {
5860 isSubscribed : state ,
5961 subscriptionActivatedAt : moment ( ) . toDate ( ) ,
6062 subscriptionExpiry : moment ( expiry ) . toDate ( ) ,
6163 subscriptionTier : tier || null ,
6264 } ,
6365 } ;
66+ if ( typeof subscriptionIdentifier !== 'undefined' ) {
67+ query . $set . subscriptionIdentifier = subscriptionIdentifier ;
68+ }
6469 await UserModel . updateOne ( { _id : target } , query ) ;
6570 res . status ( statusCodes . success ) . json ( new SuccessResponse ( ) ) ;
6671 flushUserInfoFromRedis ( target ) ;
0 commit comments