Merge branch 'mayankSprint2' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into Split-lambda
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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.getAllBucketActivities(
|
||||
userId
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Data retrieved successfully',
|
||||
data: result,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -400,7 +400,7 @@ export class FilteredLandingPageService {
|
||||
id: true,
|
||||
schoolCompanyXid: true,
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const otherConnectionUsers = await tx.connectDetails.findMany({
|
||||
where: { userXid: { notIn: [userId] }, isActive: true, schoolCompanyXid: { in: userConnectionDetails.map((u) => u.schoolCompanyXid) } },
|
||||
@@ -408,7 +408,7 @@ export class FilteredLandingPageService {
|
||||
id: true,
|
||||
userXid: true,
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const connectionUserIds =
|
||||
otherConnectionUsers.length > 0
|
||||
@@ -450,7 +450,7 @@ export class FilteredLandingPageService {
|
||||
return acc;
|
||||
}, {} as any);
|
||||
|
||||
// Fetch activities for each activity type
|
||||
// Fetch activities for each activity type with excluded activities filter
|
||||
const activitiesByActivityType = await Promise.all(
|
||||
activityTypesWithInterests.map(async (activityType) => {
|
||||
const activities = await tx.activities.findMany({
|
||||
@@ -565,7 +565,6 @@ export class FilteredLandingPageService {
|
||||
// Group by interests for the final structure
|
||||
const interestsWithActivities = await Promise.all(
|
||||
Object.values(activityTypesByInterest).map(async (interestGroup: any) => {
|
||||
|
||||
// collect all activities belonging to this interest
|
||||
const activitiesForInterest = activitiesByActivityType
|
||||
.filter(a => a.interestXid === interestGroup.interest.id)
|
||||
@@ -580,11 +579,9 @@ export class FilteredLandingPageService {
|
||||
interestGroup.interest.interestImage
|
||||
),
|
||||
displayOrder: interestGroup.interest.displayOrder,
|
||||
|
||||
page,
|
||||
limit,
|
||||
hasMore: activitiesForInterest.length === limit,
|
||||
|
||||
activities: activitiesForInterest
|
||||
};
|
||||
})
|
||||
@@ -596,6 +593,9 @@ export class FilteredLandingPageService {
|
||||
where: {
|
||||
isActive: true,
|
||||
isBucket: false,
|
||||
activityXid: {
|
||||
notIn: allUserExcludedActivityIds.length ? allUserExcludedActivityIds : [-1],
|
||||
},
|
||||
},
|
||||
_count: {
|
||||
activityXid: true,
|
||||
|
||||
@@ -4256,4 +4256,70 @@ export class UserService {
|
||||
interestedCount,
|
||||
};
|
||||
}
|
||||
|
||||
async getAllBucketActivities(userXid: number) {
|
||||
const bucketActivities = await this.prisma.userBucketInterested.findMany({
|
||||
where: {
|
||||
userXid,
|
||||
isBucket: true,
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
bucketTypeName: true,
|
||||
activityXid: true,
|
||||
Activities: {
|
||||
select: {
|
||||
activityTitle: true,
|
||||
ActivitiesMedia: {
|
||||
where: {
|
||||
isCoverImage: true,
|
||||
isActive: true,
|
||||
},
|
||||
select: {
|
||||
mediaFileName: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const ready: any[] = [];
|
||||
const planning: any[] = [];
|
||||
const oneDay: any[] = [];
|
||||
|
||||
for (const item of bucketActivities) {
|
||||
const media = item.Activities?.ActivitiesMedia?.[0]?.mediaFileName;
|
||||
|
||||
let presignedUrl = null;
|
||||
|
||||
if (media) {
|
||||
presignedUrl = await attachPresignedUrl(media);
|
||||
// your presigned url function
|
||||
}
|
||||
|
||||
const activityData = {
|
||||
id: item.id,
|
||||
activityXid: item.activityXid,
|
||||
bucketTypeName: item.bucketTypeName,
|
||||
activityTitle: item.Activities?.activityTitle,
|
||||
coverImage: presignedUrl,
|
||||
};
|
||||
|
||||
if (item.bucketTypeName === 'Ready') {
|
||||
ready.push(activityData);
|
||||
} else if (item.bucketTypeName === 'Planning') {
|
||||
planning.push(activityData);
|
||||
} else if (item.bucketTypeName === 'One-day') {
|
||||
oneDay.push(activityData);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ready,
|
||||
planning,
|
||||
oneDay,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user