Made get all connection details of user and fixed the issues in the schoolCompany table
This commit is contained in:
@@ -201,8 +201,6 @@ model ConnectDetails {
|
||||
user User @relation(fields: [userXid], references: [id], onDelete: Cascade)
|
||||
schoolCompanyXid Int @map("school_company_xid")
|
||||
schoolCompany SchoolCompany @relation(fields: [schoolCompanyXid], references: [id], onDelete: Restrict)
|
||||
connectionXid Int @map("connection_xid")
|
||||
connect Connections @relation(fields: [connectionXid], references: [id], onDelete: Cascade)
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
@@ -264,6 +262,8 @@ model SchoolCompany {
|
||||
id Int @id @default(autoincrement())
|
||||
schoolCompanyName String @map("school_company_name") @db.VarChar(255)
|
||||
isSchool Boolean @map("is_school")
|
||||
cityXid Int @map("city_xid")
|
||||
cities Cities @relation(fields: [cityXid], references: [id], onDelete: Restrict)
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
@@ -354,6 +354,7 @@ model Cities {
|
||||
// 🔹 Activity relations
|
||||
checkInActivities Activities[] @relation("CheckInCity")
|
||||
checkOutActivities Activities[] @relation("CheckOutCity")
|
||||
schoolCompanies SchoolCompany[]
|
||||
|
||||
@@map("cities")
|
||||
@@schema("mst")
|
||||
@@ -696,7 +697,6 @@ model Connections {
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
User User[]
|
||||
connectDetails ConnectDetails[]
|
||||
|
||||
@@map("connections")
|
||||
@@schema("mst")
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
||||
import { safeHandler } from '../../../../common/utils/handlers/safeHandler';
|
||||
import { prismaClient } from '../../../../common/database/prisma.lambda.service';
|
||||
import ApiError from '../../../../common/utils/helper/ApiError';
|
||||
import { UserService } from '../../services/user.service';
|
||||
import { verifyUserToken } from '../../../../common/middlewares/jwt/authForUser';
|
||||
|
||||
const userService = new UserService(prismaClient);
|
||||
|
||||
export const handler = safeHandler(async (
|
||||
event: APIGatewayProxyEvent,
|
||||
context?: Context
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Extract token from headers
|
||||
const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token'];
|
||||
if (!token) {
|
||||
throw new ApiError(400, 'This is a protected route. Please provide a valid token.');
|
||||
}
|
||||
|
||||
// Verify token and get user info
|
||||
const userInfo = await verifyUserToken(token);
|
||||
const userId = Number(userInfo.id);
|
||||
|
||||
if (!userId || isNaN(userId)) {
|
||||
throw new ApiError(400, 'Invalid user ID');
|
||||
}
|
||||
|
||||
// Fetch user with their HostHeader stepper info
|
||||
const result = await userService.getAllConnectionDetailsOfUser(userId);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Data retrieved successfully',
|
||||
data: result,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1809,4 +1809,23 @@ export class UserService {
|
||||
|
||||
return activitiesWithCounts;
|
||||
}
|
||||
|
||||
|
||||
// CONNECTIONS
|
||||
|
||||
async getAllConnectionDetailsOfUser(userXid: number) {
|
||||
return await this.prisma.connectDetails.findMany({
|
||||
where: { userXid, isActive: true },
|
||||
select: {
|
||||
id: true,
|
||||
schoolCompany: {
|
||||
select: {
|
||||
id: true,
|
||||
schoolCompanyName: true,
|
||||
isSchool: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user