Merge branch 'mayankSprint2' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into paritosh-main1

This commit is contained in:
paritosh18
2026-02-23 17:52:03 +05:30
11 changed files with 335 additions and 136 deletions

View File

@@ -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;
}
}

View File

@@ -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,
}),
};
},

View File

@@ -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(