Skip to content

Commit

Permalink
handle fax multilang (ko)
Browse files Browse the repository at this point in the history
  • Loading branch information
kckern committed Sep 16, 2024
1 parent ab0a21d commit cce0a8b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/database/models/bom_xtras_fax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export default class _bom_xtras_fax extends ModelBase {
type: DataTypes.STRING(10),
allowNull: true
},
lang: {
type: DataTypes.STRING(10),
allowNull: true
},
}, {
sequelize,
tableName: 'bom_xtras_fax',
Expand Down
26 changes: 19 additions & 7 deletions src/resolvers/BomNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,27 @@ export default {
});
},
fax: async (root: any, args: any, context: any, info: any) => {
const lang = context.lang ? context.lang : null;
const fetchResults = async (model: any, where: any, lang: string) => {
return await model.findAll({
where: where,
order: ['weight'],
include: [includeTranslation({ [Op.or]: ['title', 'info'] }, lang)].filter(x => !!x)
});
};

let lang = context.lang ? context.lang : null;
let filter = args.filter;
let where = filter === 'pdf' ? { com: 0, hide: 0 } : { fax: 1 };
let where = filter === 'pdf' ? { com: 0, hide: 0, lang: lang } : { fax: 1, lang: lang};
const model = Models.BomXtrasFax;
const results = await model.findAll({
where: where,
order: ['weight'],
include: [includeTranslation({ [Op.or]: ['title', 'info'] }, lang)].filter(x => !!x)
});

let results = await fetchResults(model, where, lang);

if (results.length === 0 && lang !== 'en') {
lang = 'en';
where = filter === 'pdf' ? { com: 0, hide: 0, lang: lang } : { fax: 1, lang: lang };
results = await fetchResults(model, where, lang);
}

return results;
},
faxIndex: async (root: any, args: any, context: any, info: any) => {
Expand Down

0 comments on commit cce0a8b

Please sign in to comment.