Skip to content

Commit

Permalink
feat(tutorservice/filter): filter by city name
Browse files Browse the repository at this point in the history
  • Loading branch information
Veirt committed Nov 21, 2024
1 parent b1f39af commit 8c68a16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/controllers/tutorService.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const tutorServiceService = new TutorServiceService({ firestore });

type GetServicesSchema = z.infer<typeof getServicesSchema>;
export const getServices: Controller<GetServicesSchema> = async (req, res) => {
const { q, subjectId, minHourlyRate, maxHourlyRate, typeLesson } = req.query;
const { q, subjectId, minHourlyRate, maxHourlyRate, typeLesson, city } =
req.query;

const filters = {
q: q || null,
Expand All @@ -25,6 +26,7 @@ export const getServices: Controller<GetServicesSchema> = async (req, res) => {
maxHourlyRate: maxHourlyRate ? parseInt(maxHourlyRate as string) : null,
typeLesson: typeLesson || null,
// minRating: minRating ? parseFloat(minRating as string) : null,
city: city || null,
};

try {
Expand Down
1 change: 1 addition & 0 deletions src/schemas/tutorService.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const getServicesSchema = z.object({
message: "Teaching type must be either 'online', 'offline', or 'both'",
})
.optional(),
city: z.string().optional(),
}),
});

Expand Down
8 changes: 8 additions & 0 deletions src/services/tutorService.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type GetTutorServicesFilters = {
maxHourlyRate?: number | null;
typeLesson?: string | null;
tutorId?: string | null;
city?: string | null;
};

export class TutorServiceService {
Expand All @@ -43,6 +44,7 @@ export class TutorServiceService {
maxHourlyRate = null,
typeLesson = null,
tutorId = null,
city = null,
}: GetTutorServicesFilters = {}) {
try {
let query: FirebaseFirestore.Query<FirebaseFirestore.DocumentData> =
Expand Down Expand Up @@ -174,6 +176,12 @@ export class TutorServiceService {
}
}

if (city) {
if (!tutorData.city?.toLowerCase().includes(city.toLowerCase())) {
return null;
}
}

return {
id: doc.id,
tutorName,
Expand Down

0 comments on commit 8c68a16

Please sign in to comment.