Merge branch 'paritosh-main1' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into mayankSprint2
This commit is contained in:
@@ -198,6 +198,51 @@ searchActivities:
|
||||
path: /user/activities/specific-search
|
||||
method: get
|
||||
|
||||
searchSchoolsAndCompanies:
|
||||
handler: src/modules/user/handlers/connections/getSchoolCompanyName.handler
|
||||
memorySize: 384
|
||||
package:
|
||||
patterns:
|
||||
- 'src/modules/user/handlers/connections/**'
|
||||
- ${file(./serverless/patterns/base.yml):pattern1}
|
||||
- ${file(./serverless/patterns/base.yml):pattern2}
|
||||
- ${file(./serverless/patterns/base.yml):pattern3}
|
||||
- ${file(./serverless/patterns/base.yml):pattern4}
|
||||
events:
|
||||
- httpApi:
|
||||
path: /user/connections/search-schools-companies
|
||||
method: get
|
||||
|
||||
searchCities:
|
||||
handler: src/modules/user/handlers/connections/searchCities.handler
|
||||
memorySize: 384
|
||||
package:
|
||||
patterns:
|
||||
- 'src/modules/user/handlers/connections/**'
|
||||
- ${file(./serverless/patterns/base.yml):pattern1}
|
||||
- ${file(./serverless/patterns/base.yml):pattern2}
|
||||
- ${file(./serverless/patterns/base.yml):pattern3}
|
||||
- ${file(./serverless/patterns/base.yml):pattern4}
|
||||
events:
|
||||
- httpApi:
|
||||
path: /user/connections/search-cities
|
||||
method: get
|
||||
|
||||
addSchoolCompanyDetail:
|
||||
handler: src/modules/user/handlers/connections/addSchoolCompanyDetail.handler
|
||||
memorySize: 384
|
||||
package:
|
||||
patterns:
|
||||
- 'src/modules/user/handlers/connections/**'
|
||||
- ${file(./serverless/patterns/base.yml):pattern1}
|
||||
- ${file(./serverless/patterns/base.yml):pattern2}
|
||||
- ${file(./serverless/patterns/base.yml):pattern3}
|
||||
- ${file(./serverless/patterns/base.yml):pattern4}
|
||||
events:
|
||||
- httpApi:
|
||||
path: /user/connections/add-school-company
|
||||
method: post
|
||||
|
||||
getAllConnectionOfUser:
|
||||
handler: src/modules/user/handlers/connections/getAllConnectionDetailsOfUser.handler
|
||||
memorySize: 384
|
||||
|
||||
11
src/modules/user/dto/addSchoolCompanyDetail.dto.ts
Normal file
11
src/modules/user/dto/addSchoolCompanyDetail.dto.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export class AddSchoolCompanyDetailDTO {
|
||||
schoolCompanyName: string;
|
||||
isSchool: boolean;
|
||||
cityXid: number;
|
||||
|
||||
constructor(schoolCompanyName: string, isSchool: boolean, cityXid: number) {
|
||||
this.schoolCompanyName = schoolCompanyName;
|
||||
this.isSchool = isSchool;
|
||||
this.cityXid = cityXid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
APIGatewayProxyEvent,
|
||||
APIGatewayProxyResult,
|
||||
Context,
|
||||
} from 'aws-lambda';
|
||||
import { prismaClient } from '../../../../common/database/prisma.lambda.service';
|
||||
import { safeHandler } from '../../../../common/utils/handlers/safeHandler';
|
||||
import ApiError from '../../../../common/utils/helper/ApiError';
|
||||
import { AddSchoolCompanyDetailDTO } from '../../dto/addSchoolCompanyDetail.dto';
|
||||
import { UserService } from '../../services/user.service';
|
||||
|
||||
const userService = new UserService(prismaClient);
|
||||
|
||||
export const handler = safeHandler(
|
||||
async (
|
||||
event: APIGatewayProxyEvent,
|
||||
context?: Context,
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Extract body parameters
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(event.body || '{}');
|
||||
} catch (error) {
|
||||
throw new ApiError(400, 'Invalid JSON in request body');
|
||||
}
|
||||
|
||||
const { schoolCompanyName, isSchool, cityXid } = body;
|
||||
|
||||
// Validate required inputs
|
||||
if (!schoolCompanyName || schoolCompanyName.trim().length === 0) {
|
||||
throw new ApiError(400, 'schoolCompanyName is required');
|
||||
}
|
||||
|
||||
if (schoolCompanyName.trim().length < 2) {
|
||||
throw new ApiError(
|
||||
400,
|
||||
'schoolCompanyName must be at least 2 characters long',
|
||||
);
|
||||
}
|
||||
|
||||
if (isSchool === undefined || isSchool === null) {
|
||||
throw new ApiError(
|
||||
400,
|
||||
'isSchool is required and must be a boolean value',
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof isSchool !== 'boolean') {
|
||||
throw new ApiError(
|
||||
400,
|
||||
'isSchool must be a boolean value (true or false)',
|
||||
);
|
||||
}
|
||||
|
||||
if (!cityXid || typeof cityXid !== 'number') {
|
||||
throw new ApiError(400, 'cityXid is required and must be a number');
|
||||
}
|
||||
|
||||
// Create DTO
|
||||
const dto = new AddSchoolCompanyDetailDTO(
|
||||
schoolCompanyName.trim(),
|
||||
isSchool,
|
||||
cityXid,
|
||||
);
|
||||
|
||||
// Call service to add or find school/company
|
||||
const result = await userService.addOrFindSchoolCompanyDetail(dto);
|
||||
|
||||
return {
|
||||
statusCode: 201,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
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,
|
||||
}),
|
||||
};
|
||||
},
|
||||
);
|
||||
@@ -1 +1,83 @@
|
||||
//#do your code here
|
||||
import {
|
||||
APIGatewayProxyEvent,
|
||||
APIGatewayProxyResult,
|
||||
Context,
|
||||
} from 'aws-lambda';
|
||||
import { prismaClient } from '../../../../common/database/prisma.lambda.service';
|
||||
import { safeHandler } from '../../../../common/utils/handlers/safeHandler';
|
||||
import ApiError from '../../../../common/utils/helper/ApiError';
|
||||
import { UserService } from '../../services/user.service';
|
||||
|
||||
const userService = new UserService(prismaClient);
|
||||
|
||||
export const handler = safeHandler(
|
||||
async (
|
||||
event: APIGatewayProxyEvent,
|
||||
context?: Context,
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Extract query parameters
|
||||
const searchQuery = event.queryStringParameters?.searchQuery?.trim();
|
||||
const isSchool = event.queryStringParameters?.isSchool?.toLowerCase();
|
||||
|
||||
// Validate inputs
|
||||
if (!searchQuery || searchQuery.length === 0) {
|
||||
throw new ApiError(400, 'Search query is required');
|
||||
}
|
||||
|
||||
if (searchQuery.length < 2) {
|
||||
throw new ApiError(
|
||||
400,
|
||||
'Search query must be at least 2 characters long',
|
||||
);
|
||||
}
|
||||
|
||||
// Validate isSchool parameter
|
||||
if (!isSchool || !['true', 'false'].includes(isSchool)) {
|
||||
throw new ApiError(
|
||||
400,
|
||||
'isSchool parameter must be either "true" (for schools) or "false" (for companies)',
|
||||
);
|
||||
}
|
||||
|
||||
// Convert isSchool to boolean
|
||||
const filterBySchool = isSchool === 'true';
|
||||
|
||||
// Call service to search
|
||||
const results = await userService.searchSchoolsAndCompanies(
|
||||
searchQuery,
|
||||
filterBySchool,
|
||||
);
|
||||
|
||||
// Check if any results found
|
||||
if (results.length === 0) {
|
||||
const type = filterBySchool ? 'school' : 'company';
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: `No ${type}s found matching your search`,
|
||||
data: [],
|
||||
count: 0,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: `${filterBySchool ? 'Schools' : 'Companies'} found successfully`,
|
||||
data: results,
|
||||
count: results.length,
|
||||
}),
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
64
src/modules/user/handlers/connections/searchCities.ts
Normal file
64
src/modules/user/handlers/connections/searchCities.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import {
|
||||
APIGatewayProxyEvent,
|
||||
APIGatewayProxyResult,
|
||||
Context,
|
||||
} from 'aws-lambda';
|
||||
import { prismaClient } from '../../../../common/database/prisma.lambda.service';
|
||||
import { safeHandler } from '../../../../common/utils/handlers/safeHandler';
|
||||
import ApiError from '../../../../common/utils/helper/ApiError';
|
||||
import { UserService } from '../../services/user.service';
|
||||
|
||||
const userService = new UserService(prismaClient);
|
||||
|
||||
export const handler = safeHandler(
|
||||
async (
|
||||
event: APIGatewayProxyEvent,
|
||||
context?: Context,
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Extract query parameters
|
||||
const searchQuery = event.queryStringParameters?.searchQuery?.trim();
|
||||
|
||||
// Validate inputs
|
||||
if (!searchQuery || searchQuery.length === 0) {
|
||||
throw new ApiError(400, 'Search query is required');
|
||||
}
|
||||
|
||||
if (searchQuery.length < 2) {
|
||||
throw new ApiError(400, 'Search query must be at least 2 characters long');
|
||||
}
|
||||
|
||||
// Call service to search cities
|
||||
const results = await userService.searchCities(searchQuery);
|
||||
|
||||
// Check if any results found
|
||||
if (results.length === 0) {
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'No cities found matching your search',
|
||||
data: [],
|
||||
count: 0,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Cities found successfully',
|
||||
data: results,
|
||||
count: results.length,
|
||||
}),
|
||||
};
|
||||
},
|
||||
);
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user