Merge branch 'mayankSprint2' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into paritosh-main1
This commit is contained in:
@@ -34,14 +34,15 @@ export const handler = safeHandler(async (
|
||||
throw new ApiError(404, 'Host not found');
|
||||
}
|
||||
|
||||
let body: { activityXid: number; venueXid: number; scheduleHeaderXid: number; slotXid: number; cancellationReason?: string };
|
||||
let body: { activityXid: number; venueXid: number; cancellations: { scheduleHeaderXid: number; slotXid: number; cancellationReason: string }[] };
|
||||
|
||||
try {
|
||||
body = event.body ? JSON.parse(event.body) : {};
|
||||
} catch {
|
||||
throw new ApiError(400, 'Invalid JSON payload');
|
||||
}
|
||||
if(!body.activityXid || !body.venueXid || !body.scheduleHeaderXid || !body.slotXid){
|
||||
|
||||
if (!body.activityXid || !body.venueXid || !Array.isArray(body.cancellations) || body.cancellations.length === 0) {
|
||||
throw new ApiError(400, 'Missing required fields');
|
||||
}
|
||||
|
||||
@@ -63,12 +64,15 @@ export const handler = safeHandler(async (
|
||||
}
|
||||
|
||||
|
||||
await schedulingService.cancelSlotForActivity(
|
||||
Number(body.scheduleHeaderXid),
|
||||
Number(body.slotXid),
|
||||
body.cancellationReason || 'No reason provided'
|
||||
await schedulingService.cancelMultipleSlotsForActivity(
|
||||
body.cancellations.map((item: any) => ({
|
||||
scheduleHeaderXid: Number(item.scheduleHeaderXid),
|
||||
slotXid: Number(item.slotXid),
|
||||
cancellationReason: item.cancellationReason
|
||||
}))
|
||||
);
|
||||
|
||||
|
||||
const result = await schedulingService.getVenueDurationByAct(Number(body.activityXid), Number(hostId));
|
||||
|
||||
return {
|
||||
|
||||
@@ -694,24 +694,23 @@ export class SchedulingService {
|
||||
return result;
|
||||
}
|
||||
|
||||
async cancelSlotForActivity(
|
||||
scheduleHeaderXid: number,
|
||||
slotXid?: number,
|
||||
cancellationReason?: string
|
||||
) {
|
||||
return await this.prisma.cancellations.create({
|
||||
data: {
|
||||
scheduleHeader: {
|
||||
connect: { id: scheduleHeaderXid },
|
||||
},
|
||||
slot: {
|
||||
connect: { id: slotXid },
|
||||
},
|
||||
cancellationReason
|
||||
}
|
||||
})
|
||||
async cancelMultipleSlotsForActivity(cancellations: {
|
||||
scheduleHeaderXid: number;
|
||||
slotXid: number;
|
||||
cancellationReason?: string;
|
||||
}[]) {
|
||||
return await this.prisma.cancellations.createMany({
|
||||
data: cancellations.map(item => ({
|
||||
scheduleHeaderXid: item.scheduleHeaderXid,
|
||||
slotXid: item.slotXid,
|
||||
cancellationReason: item.cancellationReason || 'No reason provided'
|
||||
})),
|
||||
skipDuplicates: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
async openCanceledSlot(
|
||||
cancellationXid: number,
|
||||
slotXid?: number,
|
||||
|
||||
@@ -2,10 +2,12 @@ export class AddSchoolCompanyDetailDTO {
|
||||
schoolCompanyName: string;
|
||||
isSchool: boolean;
|
||||
cityXid: number;
|
||||
userId: number;
|
||||
|
||||
constructor(schoolCompanyName: string, isSchool: boolean, cityXid: number) {
|
||||
constructor(schoolCompanyName: string, isSchool: boolean, cityXid: number, userId: number) {
|
||||
this.schoolCompanyName = schoolCompanyName;
|
||||
this.isSchool = isSchool;
|
||||
this.cityXid = cityXid;
|
||||
this.userId = userId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ export const handler = safeHandler(
|
||||
schoolCompanyName.trim().toLowerCase(),
|
||||
isSchool,
|
||||
cityXid,
|
||||
userId
|
||||
);
|
||||
|
||||
// Call service to add or find school/company
|
||||
@@ -99,11 +100,8 @@ export const handler = safeHandler(
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: result.isNew
|
||||
? `${isSchool ? 'School' : 'Company'} created successfully`
|
||||
: `${isSchool ? 'School' : 'Company'} already exists, returning existing record`,
|
||||
data: result.data,
|
||||
isNew: result.isNew,
|
||||
message: 'Connection added successfully',
|
||||
data: null,
|
||||
}),
|
||||
};
|
||||
},
|
||||
|
||||
@@ -1943,7 +1943,7 @@ export class UserService {
|
||||
|
||||
|
||||
async addOrFindSchoolCompanyDetail(dto: AddSchoolCompanyDetailDTO) {
|
||||
const { schoolCompanyName, isSchool, cityXid } = dto;
|
||||
const { schoolCompanyName, isSchool, cityXid, userId } = dto;
|
||||
|
||||
const normalizedName = normalizeName(schoolCompanyName);
|
||||
|
||||
@@ -1961,7 +1961,7 @@ export class UserService {
|
||||
}
|
||||
|
||||
// ✅ 2. Check existing (lowercase match)
|
||||
const existing = await this.prisma.schoolCompany.findFirst({
|
||||
let schoolCompany = await this.prisma.schoolCompany.findFirst({
|
||||
where: {
|
||||
schoolCompanyName: normalizedName,
|
||||
cityXid,
|
||||
@@ -1971,28 +1971,47 @@ export class UserService {
|
||||
},
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
return {
|
||||
isNew: false,
|
||||
data: existing,
|
||||
message: "Already exists",
|
||||
};
|
||||
let isNewSchoolCompany = false;
|
||||
|
||||
if (!schoolCompany) {
|
||||
schoolCompany = await this.prisma.schoolCompany.create({
|
||||
data: {
|
||||
schoolCompanyName: normalizedName,
|
||||
isSchool,
|
||||
cityXid,
|
||||
},
|
||||
});
|
||||
|
||||
isNewSchoolCompany = true;
|
||||
}
|
||||
|
||||
// ✅ 3. Create new (store lowercase)
|
||||
const created = await this.prisma.schoolCompany.create({
|
||||
data: {
|
||||
schoolCompanyName: normalizedName,
|
||||
isSchool,
|
||||
cityXid,
|
||||
// 4️⃣ Check if user already connected
|
||||
const existingConnection = await this.prisma.connectDetails.findFirst({
|
||||
where: {
|
||||
userXid: userId,
|
||||
schoolCompanyXid: schoolCompany.id,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
isNew: true,
|
||||
data: created,
|
||||
message: "Created successfully",
|
||||
};
|
||||
if (existingConnection) {
|
||||
return {
|
||||
isNew: false,
|
||||
data: schoolCompany,
|
||||
message: "Already connected",
|
||||
};
|
||||
}
|
||||
|
||||
// 5️⃣ Create connectDetails safely
|
||||
await this.prisma.connectDetails.create({
|
||||
data: {
|
||||
userXid: userId,
|
||||
schoolCompanyXid: schoolCompany.id,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async getAllActivitiesFromConnectionsUserInterests(
|
||||
|
||||
Reference in New Issue
Block a user