made updateSuggestionAsReviewed lambda api
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { verifyHostToken } from '@/common/middlewares/jwt/authForHost';
|
||||
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';
|
||||
import { HostService } from '../../../services/host.service';
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
const hostService = new HostService(prismaService);
|
||||
|
||||
export const handler = safeHandler(async (
|
||||
event: APIGatewayProxyEvent,
|
||||
context?: Context
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
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 verifyHostToken(token);
|
||||
|
||||
let body: any = {};
|
||||
try {
|
||||
body = event.body ? JSON.parse(event.body) : {};
|
||||
} catch (err) {
|
||||
throw new ApiError(400, 'Invalid JSON in request body');
|
||||
}
|
||||
|
||||
const { activityPqqHeaderXid, activityPQQSuggestionId } = body;
|
||||
|
||||
if (!activityPqqHeaderXid) {
|
||||
throw new ApiError(400, 'activityPqqHeaderXid is required');
|
||||
}
|
||||
|
||||
await hostService.markPQQSuggestionReviewed(
|
||||
userInfo.id,
|
||||
Number(activityPqqHeaderXid),
|
||||
Number(activityPQQSuggestionId)
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: 201,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Suggestion reviewed successfully',
|
||||
data: null,
|
||||
}),
|
||||
};
|
||||
});
|
||||
@@ -936,6 +936,22 @@ export class HostService {
|
||||
});
|
||||
}
|
||||
|
||||
async markPQQSuggestionReviewed(user_xid: number, activityPqqHeaderXid: number, activityPQQSuggestionId: number) {
|
||||
return await this.prisma.activityPQQSuggestions.update({
|
||||
where: {
|
||||
id: activityPQQSuggestionId,
|
||||
activityPqqHeaderXid: activityPqqHeaderXid,
|
||||
isActive: true,
|
||||
isReviewed: false
|
||||
},
|
||||
data: {
|
||||
isReviewed: true,
|
||||
reviewedByXid: user_xid,
|
||||
reviewedOn: new Date()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async getAllPQQQuesAndSubmittedAns() {
|
||||
return await this.prisma.activityPQQheader.findMany({
|
||||
where: { isActive: true },
|
||||
|
||||
Reference in New Issue
Block a user