Skip to content

Commit

Permalink
Merge pull request #64 from iam-abin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
iam-abin authored Oct 31, 2024
2 parents 43e3a6b + 4e0c241 commit a4027e2
Show file tree
Hide file tree
Showing 66 changed files with 1,085 additions and 505 deletions.
2 changes: 2 additions & 0 deletions admin/src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import recruiterControllers from './recruiter';
import dashboardControllers from './admin';
import membershipControllers from './membership';
import paymentControllers from './payment';
import searchControllers from './search';

export {
candidateControllers,
Expand All @@ -12,4 +13,5 @@ export {
dashboardControllers,
membershipControllers,
paymentControllers,
searchControllers
};
2 changes: 2 additions & 0 deletions admin/src/controllers/recruiter/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import getAllRecruitersController from './getRecruiters.controller';
import getRecruiterByIdController from './viewProfile.controller';
import recruiterBlockUnblockController from './blockUnblock.controller';
import searchRecruitersController from './search.controller';

import { IDependency } from '../../frameworks/types/dependency';

Expand All @@ -9,5 +10,6 @@ export = (dependencies: IDependency) => {
getAllRecruitersController: getAllRecruitersController(dependencies),
getRecruiterByIdController: getRecruiterByIdController(dependencies),
recruiterBlockUnblockController: recruiterBlockUnblockController(dependencies),
searchRecruitersController: searchRecruitersController(dependencies),
};
};
19 changes: 19 additions & 0 deletions admin/src/controllers/recruiter/search.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Request, Response } from 'express';
import { IDependency } from '../../frameworks/types/dependency';

export = (dependencies: IDependency) => {
const {
useCases: { searchRecruitersUseCase },
} = dependencies;

return async (req: Request, res: Response) => {
const { searchKey } = req.query;
const { recruiters, numberOfPages } = await searchRecruitersUseCase(dependencies).execute(
searchKey,
Number(req.params.page) || 1,
Number(req.params.limit) || 4,
);

res.status(200).json({ message: 'all recruiters', data: { recruiters, numberOfPages } });
};
};
8 changes: 8 additions & 0 deletions admin/src/controllers/search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import searchController from "./search.controller"
import { IDependency } from '../../frameworks/types/dependency';

export = (dependencies: IDependency) => {
return {
searchController: searchController(dependencies),
};
};
24 changes: 24 additions & 0 deletions admin/src/controllers/search/search.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Request, Response } from 'express';
import { IDependency } from '../../frameworks/types/dependency';

export = (dependencies: IDependency) => {
const {
useCases: { searchUseCase },
} = dependencies;

return async (req: Request, res: Response) => {
const { type: resourceType } = req.params;
const { searchKey } = req.query;
const { result, numberOfPages } = await searchUseCase(dependencies).execute(
resourceType,
searchKey as string,
Number(req.params.page) || 1,
Number(req.params.limit) || 4,
);

res.status(200).json({
message: 'search results fetched successfully',
data: { result, numberOfPages },
});
};
};
8 changes: 4 additions & 4 deletions admin/src/frameworks/database/models/job.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from 'mongoose';
import { IJob } from '../../types/job';

export type JobDocument = mongoose.Document & Omit<IJob, 'jobId'>;
export type IJobDocument = mongoose.Document & Omit<IJob, 'jobId'>;

const jobSchema = new mongoose.Schema(
{
Expand Down Expand Up @@ -39,13 +39,13 @@ const jobSchema = new mongoose.Schema(
},
);

interface JobModel extends mongoose.Model<JobDocument> {
buildJob(attributes: IJob): JobDocument;
interface JobModel extends mongoose.Model<IJobDocument> {
buildJob(attributes: IJob): IJobDocument;
}

jobSchema.statics.buildJob = (attributes: IJob) => {
const { jobId, ...rest } = attributes;
return new JobModel({ ...rest, _id: jobId });
};

export const JobModel = mongoose.model<JobDocument, JobModel>('Job', jobSchema);
export const JobModel = mongoose.model<IJobDocument, JobModel>('Job', jobSchema);
3 changes: 3 additions & 0 deletions admin/src/frameworks/express/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { membershipPlanRouter } from './membershipplan';
import { jobRouter } from './job';
import { paymentRouter } from './payment';
import { IDependency } from '../../types/dependency';
import { searchRouter } from './search';

export const routes = (dependencies: IDependency) => {
const router = express.Router();
Expand All @@ -18,6 +19,7 @@ export const routes = (dependencies: IDependency) => {
const membershipPlan = membershipPlanRouter(dependencies);
const job = jobRouter(dependencies);
const payment = paymentRouter(dependencies);
const search = searchRouter(dependencies);

// checkCurrentUser extract current user from jwt, if user is present add it to req.currentUser
// In admin service every routes are protected for admin.
Expand All @@ -31,6 +33,7 @@ export const routes = (dependencies: IDependency) => {
router.use('/membership', membershipPlan);
router.use('/job', job);
router.use('/payment', payment);
router.use('/search', search);

return router;
};
13 changes: 13 additions & 0 deletions admin/src/frameworks/express/routes/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import express, { Router } from 'express';
import { IDependency } from '../../types/dependency';
import { searchControllers } from '../../../controllers';

export const searchRouter = (dependencies: IDependency) => {
const router: Router = express.Router();

const searchController = searchControllers(dependencies);

router.get('/:type/:page/:limit/', searchController.searchController);

return router;
};
27 changes: 23 additions & 4 deletions admin/src/frameworks/repositories/mongo/candidate.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CandidateModel, ICandidateDocument } from '../../database/models';
import { ICandidate, IUser } from '../../types/user';

const CANDIDATES_SELECT_FIELDS: string[] = ['name', 'email', 'phone', 'isActive'];

export = {
createCandidate: async (userData: IUser): Promise<Partial<ICandidateDocument>> => {
const candidate = CandidateModel.buildCandidate(userData);
Expand Down Expand Up @@ -31,13 +33,30 @@ export = {
},

getAllCandidates: async (skip: number, limit: number): Promise<ICandidateDocument[] | null> => {
return await CandidateModel.find({})
.skip(skip)
.limit(limit)
.select(['name', 'email', 'phone', 'isActive']);
return await CandidateModel.find({}).skip(skip).limit(limit).select(CANDIDATES_SELECT_FIELDS);
},

getCountOfCandidates: async (): Promise<number> => {
return await CandidateModel.countDocuments();
},

searchCandidates: async (
searchKey: string,
skip: number,
limit: number,
): Promise<ICandidateDocument[] | []> => {

return await CandidateModel.find({
name: {
$regex: new RegExp(searchKey, 'i'),
},
})
.skip(skip)
.limit(limit)
.select(CANDIDATES_SELECT_FIELDS);
},

getCountOfSearchedCandidates: async (searchKey: string): Promise<number> => {
return await CandidateModel.countDocuments({ name: { $regex: new RegExp(searchKey, 'i') } });
},
};
32 changes: 24 additions & 8 deletions admin/src/frameworks/repositories/mongo/job.repository.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { JobDocument, JobModel } from '../../database/models';
import { IJobDocument, JobModel } from '../../database/models';
import { IJob } from '../../types/job';

const JOB_SELECT_FIELDS = ['title', 'companyLocation', 'isActive'];
export = {
createJob: async (jobData: IJob): Promise<JobDocument> => {
createJob: async (jobData: IJob): Promise<IJobDocument> => {
const jobObject = JobModel.buildJob(jobData);
return await jobObject.save();
},

blockUnblock: async (jobId: string): Promise<JobDocument> => {
blockUnblock: async (jobId: string): Promise<IJobDocument> => {
const job = await JobModel.findById(jobId);
if (!job) throw new Error('job not found');

Expand All @@ -16,17 +17,17 @@ export = {
return await job.save();
},

updateJob: async (jobId: string, data: Partial<IJob>): Promise<JobDocument | null> => {
updateJob: async (jobId: string, data: Partial<IJob>): Promise<IJobDocument | null> => {
const updatedJob = await JobModel.findOneAndUpdate({ jobId: jobId }, { $set: data }, { new: true });

return updatedJob;
},

getById: async (jobId: string): Promise<JobDocument | null> => {
getById: async (jobId: string): Promise<IJobDocument | null> => {
return await JobModel.findById(jobId);
},

deleteJob: async (jobId: string): Promise<JobDocument | null> => {
deleteJob: async (jobId: string): Promise<IJobDocument | null> => {
const deletedJob = await JobModel.findByIdAndUpdate(
jobId,
{ $set: { isDeleted: true } },
Expand All @@ -37,11 +38,26 @@ export = {
return deletedJob;
},

getAllJobs: async (skip: number, limit: number): Promise<JobDocument[] | []> => {
return await JobModel.find({}).skip(skip).limit(limit);
getAllJobs: async (skip: number, limit: number): Promise<IJobDocument[] | []> => {
return await JobModel.find({}).select(JOB_SELECT_FIELDS).skip(skip).limit(limit);
},

getCountOfJobs: async (): Promise<number> => {
return await JobModel.countDocuments();
},

searchJobs: async (searchKey: string, skip: number, limit: number): Promise<IJobDocument[] | []> => {
return await JobModel.find({
title: {
$regex: new RegExp(searchKey, 'i'),
},
})
.select(JOB_SELECT_FIELDS)
.skip(skip)
.limit(limit);
},

getCountOfSearchedJobs: async (searchKey: string): Promise<number> => {
return await JobModel.countDocuments({ title: { $regex: new RegExp(searchKey, 'i') } });
},
};
18 changes: 17 additions & 1 deletion admin/src/frameworks/repositories/mongo/membership.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IMembershipPlanData } from '../../../entities/membership-plan';
import { IMembershipPlansDocument, MembershipPlansModel } from '../../database/models';

const MEMBERSHIP_SELECT_FIELDS = ["name", "price","isActive"]

export = {
createMembershipPlan: async (
membershipPlanData: IMembershipPlanData,
Expand Down Expand Up @@ -58,11 +60,25 @@ export = {
const membershipPlans = await MembershipPlansModel.find({})
.skip(skip)
.limit(limit)
.select(['name', 'price']);
.select(MEMBERSHIP_SELECT_FIELDS);
return membershipPlans;
},

getCountOfMembershipPlans: async (): Promise<number> => {
return await MembershipPlansModel.countDocuments();
},

searchMembershipPlans: async (searchKey: string, skip: number, limit: number): Promise<IMembershipPlansDocument[] | []> => {
return await MembershipPlansModel.find({
name: {
$regex: new RegExp(searchKey, 'i'),
},
}).select(MEMBERSHIP_SELECT_FIELDS)
.skip(skip)
.limit(limit);
},

getCountOfSearchedMembershipPlans: async (searchKey: string): Promise<number> => {
return await MembershipPlansModel.countDocuments({ name: { $regex: new RegExp(searchKey, 'i') } });
},
};
Loading

0 comments on commit a4027e2

Please sign in to comment.