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

@@ -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));
}