diff --git a/serverless/functions/minglaradmin.yml b/serverless/functions/minglaradmin.yml index 031979e..349ecba 100644 --- a/serverless/functions/minglaradmin.yml +++ b/serverless/functions/minglaradmin.yml @@ -94,7 +94,6 @@ updateMinglarProfile: path: /minglaradmin/update-profile method: patch - prepopulateRole: handler: src/modules/minglaradmin/handlers/prepopulateRole.handler memorySize: 384 @@ -313,6 +312,22 @@ acceptHostApplication: path: /minglaradmin/hosthub/hosts/accept-host-application method: patch +RejectPQQByAM: + handler: src/modules/minglaradmin/handlers/hosthub/hosts/rejectPQQbyAM.handler + memorySize: 384 + package: + patterns: + - 'src/modules/minglaradmin/handlers/hosthub/hosts/**' + - 'src/modules/minglaradmin/services/**' + - ${file(./serverless/patterns/base.yml):pattern1} + - ${file(./serverless/patterns/base.yml):pattern2} + - ${file(./serverless/patterns/base.yml):pattern3} + - ${file(./serverless/patterns/base.yml):pattern4} + events: + - httpApi: + path: /minglaradmin/hosthub/hosts/reject-pqq-by-am + method: patch + acceptHostApplicationMinglar: handler: src/modules/minglaradmin/handlers/hosthub/onboarding/acceptHostAppMinglar.handler memorySize: 384 diff --git a/src/modules/minglaradmin/handlers/hosthub/hosts/rejectPQQbyAM.ts b/src/modules/minglaradmin/handlers/hosthub/hosts/rejectPQQbyAM.ts new file mode 100644 index 0000000..9eedab3 --- /dev/null +++ b/src/modules/minglaradmin/handlers/hosthub/hosts/rejectPQQbyAM.ts @@ -0,0 +1,50 @@ +import { verifyMinglarAdminToken } from '@/common/middlewares/jwt/authForMinglarAdmin'; +import { MinglarService } from '@/modules/minglaradmin/services/minglar.service'; +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { PrismaService } from '../../../../../common/database/prisma.service'; +import { safeHandler } from '../../../../../common/utils/handlers/safeHandler'; +import ApiError from '../../../../../common/utils/helper/ApiError'; + +const prismaService = new PrismaService(); +const minglarService = new MinglarService(prismaService); + +export const handler = safeHandler(async ( + event: APIGatewayProxyEvent, + context?: Context +): Promise => { + const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token']; + if (!token) throw new ApiError(401, 'This is a protected route. Please provide a valid token.'); + + const userInfo = await verifyMinglarAdminToken(token); + + let body: any = {}; + try { + body = event.body ? JSON.parse(event.body) : {}; + } catch (err) { + throw new ApiError(400, 'Invalid JSON in request body'); + } + + const { activityId } = body; + + if (!activityId) { + throw new ApiError(400, 'activityId is required'); + } + + await minglarService.rejectPQQbyAM( + userInfo.id, + Number(activityId), + ); + + return { + statusCode: 201, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Rejected successfully', + data: null, + }), + }; +}); diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index cf38303..e478f76 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -4,6 +4,8 @@ import { USER_STATUS, } from '@/common/utils/constants/common.constant'; import { + ACTIVITY_DISPLAY_STATUS, + ACTIVITY_INTERNAL_STATUS, HOST_STATUS_DISPLAY, HOST_STATUS_INTERNAL, STEPPER, @@ -1221,4 +1223,16 @@ export class MinglarService { }, }); } + + async rejectPQQbyAM(user_xid: number, activityId: number) { + return await this.prisma.activities.update({ + where: { + id: activityId + }, + data: { + activityInternalStatus: ACTIVITY_INTERNAL_STATUS.REJECTED, + activityDisplayStatus: ACTIVITY_DISPLAY_STATUS.REJECTED, + } + }) + } }