Merge branch 'mayankSprint2' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into paritosh-main1
This commit is contained in:
@@ -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