Merged in feature-homepage-contacts-languages (pull request #43)

Feature homepage contacts languages

Approved-by: Tiago Ribeiro
This commit is contained in:
João Ramos
2024-02-29 23:54:04 +00:00
committed by Tiago Ribeiro
2 changed files with 10 additions and 5 deletions

View File

@@ -23,7 +23,7 @@ interface Contact {
number: string;
}
async function get(req: NextApiRequest, res: NextApiResponse) {
const { code } = req.query as { code: string };
const { code, language = 'en' } = req.query as { code: string, language: string};
const usersQuery = query(
collection(db, "users"),
@@ -43,9 +43,11 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
return newUser;
}) as Contact[];
const country = countryCodes.findOne("countryCode" as any, code);
const country = countryCodes.findOne("countryCode" as any, code.toUpperCase());
const key = language === 'ar' ? 'countryNameLocal' : 'countryNameEn';
res.json({
label: country.countryNameEn,
label: country[key],
entries,
});
}

View File

@@ -23,6 +23,8 @@ interface Contact {
number: string;
}
async function get(req: NextApiRequest, res: NextApiResponse) {
const { language = 'en' } = req.query as { language: string };
const usersQuery = query(
collection(db, "users"),
where("type", "==", "agent")
@@ -49,9 +51,10 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
) as Record<string, Contact[]>;
const result = Object.keys(data).map((code) => {
const country = countryCodes.findOne("countryCode" as any, code);
const country = countryCodes.findOne("countryCode" as any, code.toUpperCase());
const key = language === 'ar' ? 'countryNameLocal' : 'countryNameEn';
return {
label: country.countryNameEn,
label: country[key],
key: code,
entries: data[code],
};