fixed code
This commit is contained in:
45
src/modules/host/handlers/acceptAgreement.ts
Normal file
45
src/modules/host/handlers/acceptAgreement.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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);
|
||||
|
||||
/**
|
||||
* Add suggestion handler for host applications
|
||||
* Allows Minglar Admin, Co_Admin, and Account Manager to add suggestions
|
||||
* Types: Setup Profile, Review Account, Add Payment Details, Agreement
|
||||
*/
|
||||
export const handler = safeHandler(async (
|
||||
event: APIGatewayProxyEvent,
|
||||
context?: Context
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Verify authentication token
|
||||
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.');
|
||||
}
|
||||
|
||||
// Verify token and get user info
|
||||
const userInfo = await verifyHostToken(token);
|
||||
|
||||
|
||||
// Add suggestion using service
|
||||
await hostService.acceptMinglarAgreement(userInfo.id);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Application accepted successfully',
|
||||
data: null,
|
||||
}),
|
||||
};
|
||||
});
|
||||
@@ -179,16 +179,39 @@ export class HostService {
|
||||
return true;
|
||||
}
|
||||
|
||||
async addPaymentDetails(data: AddPaymentDetailsDTO): Promise<AddPaymentDetailsDTO> {
|
||||
const addedPaymentDetails = await this.prisma.hostBankDetails.create({
|
||||
data,
|
||||
});
|
||||
async addPaymentDetails(data: AddPaymentDetailsDTO) {
|
||||
return await this.prisma.$transaction(async (tx) => {
|
||||
const addedPaymentDetails = await tx.hostBankDetails.create({
|
||||
data,
|
||||
});
|
||||
|
||||
if (!addedPaymentDetails) {
|
||||
throw new ApiError(400, 'Failed to add payment details');
|
||||
}
|
||||
if (!addedPaymentDetails) {
|
||||
throw new ApiError(400, 'Failed to add payment details');
|
||||
}
|
||||
|
||||
return addedPaymentDetails;
|
||||
await tx.hostHeader.update({
|
||||
where: { id: data.hostXid },
|
||||
data: {
|
||||
stepper: STEPPER.BANK_DETAILS_UPDATED
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async acceptMinglarAgreement(user_xid: number) {
|
||||
const hostDetails = await this.prisma.hostHeader.findFirst({
|
||||
where: { userXid: user_xid },
|
||||
select: {
|
||||
id: true,
|
||||
userXid: true,
|
||||
}
|
||||
})
|
||||
await this.prisma.hostHeader.update({
|
||||
where: { id: hostDetails.id },
|
||||
data: {
|
||||
stepper: STEPPER.AGREEMENT_ACCEPTED
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async addOrUpdateCompanyDetails(
|
||||
|
||||
@@ -58,6 +58,9 @@ export class GetMinglarLoginResponseDTO {
|
||||
mobileNumber: string | null;
|
||||
isActive: boolean;
|
||||
roleXid: number;
|
||||
isProfileUpdated: boolean;
|
||||
profileImage: string;
|
||||
userStatus: string;
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
|
||||
@@ -69,6 +72,9 @@ export class GetMinglarLoginResponseDTO {
|
||||
this.mobileNumber = user.mobileNumber;
|
||||
this.isActive = user.isActive;
|
||||
this.roleXid = user.roleXid;
|
||||
this.profileImage = user.profileImage;
|
||||
this.isProfileUpdated = user.isProfileUpdated;
|
||||
this.userStatus = user.userStatus;
|
||||
this.accessToken = accessToken;
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
||||
import { safeHandler } from '../../../common/utils/handlers/safeHandler';
|
||||
import { PrismaService } from '../../../common/database/prisma.service';
|
||||
import { safeHandler } from '../../../common/utils/handlers/safeHandler';
|
||||
import ApiError from '../../../common/utils/helper/ApiError';
|
||||
import { GetMinglarLoginResponseDTO } from '../dto/minglar.dto';
|
||||
import { MinglarService } from '../services/minglar.service';
|
||||
import { TokenService } from "../services/token.service";
|
||||
import { GetMinglarLoginResponseDTO } from '../dto/minglar.dto';
|
||||
import ApiError from '../../../common/utils/helper/ApiError';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
const minglarSerivce = new MinglarService(prismaService);
|
||||
|
||||
@@ -131,7 +131,7 @@ export class MinglarService {
|
||||
|
||||
async loginForMinglar(emailAddress: string, userPassword: string) {
|
||||
const existingUser = await this.prisma.user.findUnique({
|
||||
where: { emailAddress: emailAddress, isActive: true },
|
||||
where: { emailAddress: emailAddress, isActive: true, userStatus: USER_STATUS.ACTIVE }
|
||||
});
|
||||
|
||||
if (!existingUser) {
|
||||
@@ -539,8 +539,6 @@ export class MinglarService {
|
||||
inviteDetails: {
|
||||
some: {
|
||||
isMinglarInvitation: true,
|
||||
is_accepted: true,
|
||||
invitation_status: MINGLAR_INVITATION_STATUS.ACCEPTED,
|
||||
isActive: true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user