Add ActivityTrack model to schema and update User and Activities models to include activityTracks relation. Modify seed data to reflect new interest names and activity types. Implement activity reference number generation in HostService for activity creation.
This commit is contained in:
@@ -38,6 +38,20 @@ interface HostDocumentInput {
|
||||
documentName: string;
|
||||
filePath: string; // S3 URL
|
||||
}
|
||||
export async function generateActivityRefNumber(tx: any) {
|
||||
const lastrecord = await tx.activities.findFirst({
|
||||
orderBy: {
|
||||
id: 'desc',
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
|
||||
const nextId = lastrecord ? lastrecord.id + 1 : 1;
|
||||
|
||||
return `ACT-${String(nextId).padStart(6, '0')}`;;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class HostService {
|
||||
@@ -330,6 +344,7 @@ export class HostService {
|
||||
where: { id: data.hostXid },
|
||||
data: {
|
||||
stepper: STEPPER.BANK_DETAILS_UPDATED,
|
||||
currencyXid: data.currencyXid
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -1206,42 +1221,48 @@ export class HostService {
|
||||
activityTypeXid: number,
|
||||
frequenciesXid?: number,
|
||||
) {
|
||||
// Find host header for this user
|
||||
const host = await this.prisma.hostHeader.findFirst({
|
||||
where: { userXid: userId, isActive: true },
|
||||
});
|
||||
if (!host) {
|
||||
throw new ApiError(404, 'Host not found for the user');
|
||||
}
|
||||
|
||||
// Validate activityType exists
|
||||
const activityType = await this.prisma.activityTypes.findUnique({
|
||||
where: { id: activityTypeXid },
|
||||
});
|
||||
if (!activityType) {
|
||||
throw new ApiError(404, 'Activity type not found');
|
||||
}
|
||||
return await this.prisma.$transaction(async (tx) => {
|
||||
|
||||
// Optionally validate frequency
|
||||
if (frequenciesXid) {
|
||||
const freq = await this.prisma.frequencies.findUnique({
|
||||
where: { id: frequenciesXid },
|
||||
// Fetch host
|
||||
const host = await tx.hostHeader.findFirst({
|
||||
where: { userXid: userId, isActive: true },
|
||||
});
|
||||
if (!freq) throw new ApiError(404, 'Frequency not found');
|
||||
}
|
||||
if (!host) throw new ApiError(404, 'Host not found for the user');
|
||||
|
||||
const created = await this.prisma.activities.create({
|
||||
data: {
|
||||
hostXid: host.id,
|
||||
activityTypeXid: activityTypeXid,
|
||||
frequenciesXid: frequenciesXid || null,
|
||||
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.DRAFT_PQ,
|
||||
activityDisplayStatus: ACTIVITY_DISPLAY_STATUS.DRAFT_PQ,
|
||||
amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.DRAFT_PQ,
|
||||
amDisplayStatus: ACTIVITY_AM_DISPLAY_STATUS.DRAFT_PQ,
|
||||
},
|
||||
// Validate activityType
|
||||
const activityType = await tx.activityTypes.findUnique({
|
||||
where: { id: activityTypeXid },
|
||||
});
|
||||
if (!activityType) throw new ApiError(404, 'Activity type not found');
|
||||
|
||||
// Validate frequency
|
||||
if (frequenciesXid) {
|
||||
const freq = await tx.frequencies.findUnique({
|
||||
where: { id: frequenciesXid },
|
||||
});
|
||||
if (!freq) throw new ApiError(404, 'Frequency not found');
|
||||
}
|
||||
|
||||
// Generate reference number
|
||||
const referenceNumber = await generateActivityRefNumber(tx);
|
||||
|
||||
// Create activity
|
||||
const created = await tx.activities.create({
|
||||
data: {
|
||||
hostXid: host.id,
|
||||
activityTypeXid,
|
||||
frequenciesXid: frequenciesXid || null,
|
||||
activityInternalStatus: ACTIVITY_INTERNAL_STATUS.DRAFT_PQ,
|
||||
activityDisplayStatus: ACTIVITY_DISPLAY_STATUS.DRAFT_PQ,
|
||||
amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.DRAFT_PQ,
|
||||
amDisplayStatus: ACTIVITY_AM_DISPLAY_STATUS.DRAFT_PQ,
|
||||
activityRefNumber: referenceNumber,
|
||||
},
|
||||
});
|
||||
|
||||
return created;
|
||||
});
|
||||
|
||||
return created;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -192,6 +192,18 @@ export class MinglarService {
|
||||
isActive: true,
|
||||
userStatus: USER_STATUS.ACTIVE,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
emailAddress: true,
|
||||
mobileNumber: true,
|
||||
roleXid: true,
|
||||
isProfileUpdated: true,
|
||||
userStatus: true,
|
||||
profileImage: true,
|
||||
userPassword: true,
|
||||
}
|
||||
});
|
||||
|
||||
if (!existingUser) {
|
||||
@@ -214,6 +226,16 @@ export class MinglarService {
|
||||
throw new ApiError(401, 'Invalid credentials');
|
||||
}
|
||||
|
||||
if (existingUser?.profileImage) {
|
||||
const key = existingUser.profileImage.startsWith("http")
|
||||
? existingUser.profileImage.split(".com/")[1]
|
||||
: existingUser.profileImage;
|
||||
|
||||
existingUser.profileImage = await getPresignedUrl(bucket, key);
|
||||
}
|
||||
|
||||
delete existingUser.userPassword;
|
||||
|
||||
return existingUser;
|
||||
}
|
||||
|
||||
@@ -742,19 +764,36 @@ export class MinglarService {
|
||||
}
|
||||
|
||||
/** APPLICATION STATUS FILTER (NEW) **/
|
||||
const APPLICATION_STATUS_MAP: Record<string, string> = {
|
||||
"New": MINGLAR_STATUS_INTERNAL.AM_TO_REVIEW && MINGLAR_STATUS_DISPLAY.NEW,
|
||||
"To_Review": MINGLAR_STATUS_INTERNAL.AM_TO_REVIEW && MINGLAR_STATUS_DISPLAY.TO_REVIEW,
|
||||
"Enchancing": MINGLAR_STATUS_INTERNAL.AM_REJECTED,
|
||||
const APPLICATION_STATUS_MAP: Record<
|
||||
string,
|
||||
{ internal: string; display: string }
|
||||
> = {
|
||||
New: {
|
||||
internal: MINGLAR_STATUS_INTERNAL.AM_TO_REVIEW,
|
||||
display: MINGLAR_STATUS_DISPLAY.NEW,
|
||||
},
|
||||
To_Review: {
|
||||
internal: MINGLAR_STATUS_INTERNAL.AM_TO_REVIEW,
|
||||
display: MINGLAR_STATUS_DISPLAY.TO_REVIEW,
|
||||
},
|
||||
Enhancing: {
|
||||
internal: MINGLAR_STATUS_INTERNAL.AM_REJECTED,
|
||||
display: MINGLAR_STATUS_DISPLAY.ENHANCING,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
if (applicationStatus?.trim()) {
|
||||
const key = applicationStatus.trim();
|
||||
if (APPLICATION_STATUS_MAP[key]) {
|
||||
filters.adminStatusInternal = APPLICATION_STATUS_MAP[key];
|
||||
const statusObj = APPLICATION_STATUS_MAP[key];
|
||||
|
||||
if (statusObj) {
|
||||
filters.adminStatusInternal = statusObj.internal;
|
||||
filters.adminStatusDisplay = statusObj.display;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** ROLE-BASED FILTER **/
|
||||
if (userRoleXid === ROLE.CO_ADMIN || userRoleXid === ROLE.ACCOUNT_MANAGER) {
|
||||
filters.accountManagerXid = userId;
|
||||
@@ -1513,7 +1552,21 @@ export class MinglarService {
|
||||
async getAMdetailById(id: number) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: id, isActive: true, userStatus: USER_STATUS.ACTIVE },
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
emailAddress: true,
|
||||
isdCode: true,
|
||||
mobileNumber: true,
|
||||
roleXid: true,
|
||||
userStatus: true,
|
||||
isProfileUpdated: true,
|
||||
dateOfBirth: true,
|
||||
profileImage: true,
|
||||
isEmailVerfied: true,
|
||||
isMobileVerfied: true,
|
||||
isBiometric: true,
|
||||
userAddressDetails: {
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -11,15 +11,11 @@ export class PrePopulateService {
|
||||
isActive: true,
|
||||
deletedAt: null,
|
||||
},
|
||||
include: {
|
||||
BankBranches: {
|
||||
select: {
|
||||
id: true,
|
||||
branchAddress: true,
|
||||
ifscCode: true,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
bankName: true,
|
||||
},
|
||||
orderBy: { bankName: 'asc' }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,7 +24,6 @@ export class PrePopulateService {
|
||||
where: {
|
||||
bankXid,
|
||||
isActive: true,
|
||||
deletedAt: null
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -60,6 +55,12 @@ export class PrePopulateService {
|
||||
isActive: true,
|
||||
deletedAt: null,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
currencyName: true,
|
||||
currencySymbol: true,
|
||||
},
|
||||
orderBy: { currencyName: 'asc' }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,27 +69,41 @@ export class PrePopulateService {
|
||||
where: { isActive: true },
|
||||
include: {
|
||||
pqqsubCategories: {
|
||||
include: {
|
||||
where: { isActive: true },
|
||||
select: {
|
||||
id: true,
|
||||
subCategoryName: true,
|
||||
categoryXid: true,
|
||||
displayOrder: true,
|
||||
questions: {
|
||||
include: {
|
||||
where: { isActive: true },
|
||||
select: {
|
||||
id: true,
|
||||
questionName: true,
|
||||
maxPoints: true,
|
||||
displayOrder: true,
|
||||
PQQAnswers: {
|
||||
orderBy: {
|
||||
displayOrder: 'asc'
|
||||
where: { isActive: true },
|
||||
orderBy: { displayOrder: 'asc' },
|
||||
select: {
|
||||
id: true,
|
||||
answerName: true,
|
||||
answerPoints: true,
|
||||
displayOrder: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
displayOrder: 'asc'
|
||||
}
|
||||
}
|
||||
orderBy: { displayOrder: 'asc' }
|
||||
},
|
||||
},
|
||||
orderBy: { displayOrder: 'asc' }
|
||||
}
|
||||
orderBy: { displayOrder: 'asc' },
|
||||
},
|
||||
},
|
||||
orderBy: { displayOrder: 'asc' }
|
||||
orderBy: { displayOrder: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async getAllDocumentTypeWithCountryStateCity() {
|
||||
const [documentDetails, countryDetails, stateDetails, companyTypeDetails] =
|
||||
await this.prisma.$transaction([
|
||||
|
||||
Reference in New Issue
Block a user