feat: refactor user ID handling and implement getHostIdByUserId method in SchedulingService
This commit is contained in:
@@ -27,18 +27,20 @@ export const handler = safeHandler(async (
|
||||
}
|
||||
|
||||
const userInfo = await verifyMinglarAdminHostToken(token);
|
||||
const hostId = Number(userInfo.id);
|
||||
const userId = Number(userInfo.id);
|
||||
|
||||
if (!hostId) {
|
||||
throw new ApiError(400, 'Host ID is required');
|
||||
if (!userId) {
|
||||
throw new ApiError(400, 'User ID is required');
|
||||
}
|
||||
|
||||
if (isNaN(hostId)) {
|
||||
throw new ApiError(400, 'Invalid host ID format');
|
||||
if (isNaN(userId)) {
|
||||
throw new ApiError(400, 'Invalid user ID format');
|
||||
}
|
||||
|
||||
// Get status filter from query parameters
|
||||
const status = event.queryStringParameters?.status as string | undefined;
|
||||
|
||||
const hostId = await schedulingService.getHostIdByUserId(userId);
|
||||
|
||||
// Validate status if provided
|
||||
const validStatuses = [ACTIVITY_INTERNAL_STATUS.ACTIVITY_APPROVED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_UNLISTED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED];
|
||||
@@ -63,7 +65,6 @@ export const handler = safeHandler(async (
|
||||
activities: activities,
|
||||
filter: {
|
||||
status: status || 'All',
|
||||
hostId: hostId,
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -13,6 +13,24 @@ const bucket = config.aws.bucketName;
|
||||
export class SchedulingService {
|
||||
constructor(private prisma: PrismaClient) { }
|
||||
|
||||
async getHostIdByUserId(userId: number) {
|
||||
const host = await this.prisma.hostHeader.findFirst({
|
||||
where: {
|
||||
userXid: userId,
|
||||
isActive: true
|
||||
},
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
})
|
||||
|
||||
if (!host) {
|
||||
throw new ApiError(404, 'Host not found for the given user.');
|
||||
}
|
||||
|
||||
return host.id;
|
||||
}
|
||||
|
||||
async addSchedulingForActivity(data: ScheduleActivityDTO) {
|
||||
const {
|
||||
activityXid,
|
||||
|
||||
Reference in New Issue
Block a user