Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
31 changes: 31 additions & 0 deletions scrappers/Wuzzuf/utils/filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const CountriesFilter = {
Egypt: 'Egypt',
UnitedArabEmirates: 'United Arab Emirates',
SaudiArabia: 'Saudi Arabia',
}
export const CitiesFilter = {
Cairo: 'Cairo',
Alexandria: 'Alexandria',
Giza: 'Giza',
}
export const AreasFilter = {
NasrCity: 'Nasr City',
Maadi: 'Maadi',
Heliopolis: 'Heliopolis',
NewCairo: 'New Cairo',
October: '6th of October',
Dokki: 'Dokki',
Mohandseen: 'Mohandessin',
Downtown: 'Downtown',
}
export const CareerLevelsFilter = {
Student: 'Student',
EntryLevel: 'Entry Level',
Experienced: 'Experienced',
}
export const JobTypesFilter = {
FullTime: 'Full time',
PartTime: 'Part time',
Internship: 'Internship',
FreelanceProject: 'Freelance project',
}
99 changes: 99 additions & 0 deletions scrappers/Wuzzuf/utils/validate-query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { AreasFilter, CareerLevelsFilter, CitiesFilter, CountriesFilter, JobTypesFilter } from "./filters"

export interface IFilters {
// country be enum of countryFilter and can be array
country?: string[] | string
city?: string[] | string
area?: string[] | string
career_level?: string
job_types?: string
}

export interface IQuery {
query: string
options?: IFilters
}

export interface IQueryValidationError {
param: string
reason: string
}

export const validateQuery = (filters: IQuery): IQueryValidationError[] => {
const errors: IQueryValidationError[] = [];

// query must be string
if (filters.query && typeof (filters.query) !== "string") {
errors.push({
param: "query",
reason: `Must be a string`
});
}
if (filters.options) {
let {
country,
city,
area,
career_level,
job_types,
} = filters.options;
// country must be string or array of strings
if (country) {
const allowed = Object.values(CountriesFilter)
if (!Array.isArray(country))
country = [country];
if (!country.every(e => allowed.includes(e))) {
errors.push({
param: "options.country",
reason: `Must be option of ${allowed.join(', ')}`
});
}
}
// city must be string or array of strings
if (city) {
const allowed = Object.values(CitiesFilter)
if (!Array.isArray(city))
city = [city];
if (!city.every(e => allowed.includes(e))) {
errors.push({
param: "options.city",
reason: `Must be option of ${allowed.join(', ')}`
});
}
}
// area must be string or array of strings
if (area) {
const allowed = Object.values(AreasFilter)
if (!Array.isArray(area))
area = [area];
if (!area.every(e => allowed.includes(e))) {
errors.push({
param: "options.area",
reason: `Must be option of ${allowed.join(', ')}`
});
}
}
// career_level must be string
if (career_level) {
const allowed = Object.values(CareerLevelsFilter)
if (!allowed.includes(career_level)) {
errors.push({
param: "options.career_level",
reason: `Must be option of ${allowed.join(', ')}`
});
}
}
// job_types must be string
if (job_types) {
const allowed = Object.values(JobTypesFilter)
if (!allowed.includes(job_types)) {
errors.push({
param: "options.job_types",
reason: `Must be option of ${allowed.join(', ')}`
});
}
}
}
console.log(errors)
return errors;
}
14 changes: 14 additions & 0 deletions scrappers/Wuzzuf/wuzzufScrapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AreasFilter, CareerLevelsFilter, CitiesFilter, CountriesFilter, JobTypesFilter } from "./utils/filters"
import { validateQuery } from "./utils/validate-query"


validateQuery({
query: 'software engineer',
options: {
country: [CountriesFilter.Egypt],
city: [CitiesFilter.Cairo],
area: [AreasFilter.Maadi],
career_level: CareerLevelsFilter.EntryLevel,
job_types: JobTypesFilter.FullTime,
}
})