Added country and birthday filters to actors page.

This commit is contained in:
2024-01-03 02:52:41 +01:00
parent b59a6dc066
commit 3c3be10c4e
21 changed files with 1061 additions and 138 deletions

View File

@@ -106,13 +106,17 @@ function buildQuery(filters) {
});
}
if (filters.gender) {
query.bool.must.push({
equals: {
gender: filters.gender,
},
});
}
['gender', 'country'].forEach((attribute) => {
if (filters[attribute]) {
console.log(attribute, filters[attribute]);
query.bool.must.push({
equals: {
[attribute]: filters[attribute],
},
});
}
});
['age', 'height', 'weight'].forEach((attribute) => {
if (filters[attribute]) {
@@ -127,6 +131,39 @@ function buildQuery(filters) {
}
});
if (filters.dateOfBirth && filters.dobType === 'dateOfBirth') {
query.bool.must.push({
equals: {
date_of_birth: Math.floor(filters.dateOfBirth.getTime() / 1000),
},
});
}
if (filters.dateOfBirth && filters.dobType === 'birthday') {
expressions.month_of_birth = 'month(date_of_birth)';
expressions.day_of_birth = 'day(date_of_birth)';
const month = filters.dateOfBirth.getMonth() + 1;
const day = filters.dateOfBirth.getDate();
query.bool.must.push({
bool: {
must: [
{
equals: {
month_of_birth: month,
},
},
{
equals: {
day_of_birth: day,
},
},
],
},
});
}
if (filters.cup) {
expressions.cup_in_range = `regex(cup, '^[${filters.cup[0]}-${filters.cup[1]}]')`;

View File

@@ -3,13 +3,28 @@ import knex from './knex.js';
function curateCountry(countryEntry) {
return {
name: countryEntry.name,
alias: countryEntry.alias,
alpha2: countryEntry.alpha2,
code: countryEntry.code,
};
}
export async function fetchCountriesByAlpha2(alpha2s) {
const entries = await knex('countries').whereIn('alpha2', alpha2s);
export async function fetchCountriesByAlpha2(alpha2s, options = {}) {
const entries = await knex('countries')
.whereIn('alpha2', alpha2s)
.orderBy(knex.raw('coalesce(alias, name)'));
return entries.map((entry) => curateCountry(entry));
if (options.preserveOrder) {
return alpha2s.map((alpha2) => {
const countryEntry = entries.find((entry) => entry.alpha2 === alpha2);
if (!countryEntry) {
return null;
}
return curateCountry(countryEntry);
}).filter(Boolean);
}
return entries.map((countryEntry) => curateCountry(countryEntry));
}

3
src/events.js Normal file
View File

@@ -0,0 +1,3 @@
import mitt from 'mitt';
export default mitt();

View File

@@ -7,7 +7,10 @@ export function curateActorsQuery(query) {
query: query.q,
gender: query.gender,
age: query.age?.split(',').map((age) => Number(age)),
dateOfBirth: query.dob && new Date(query.dob),
dobType: ({ dob: 'dateOfBirth', bd: 'birthday' })[query.dobt] || 'birthday',
cup: query.cup?.split(','),
country: query.c,
naturalBoobs: query.nb,
height: query.height?.split(',').map((height) => Number(height)),
weight: query.weight?.split(',').map((weight) => Number(weight)),