Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function(req, res, next) {
- const ACTIVATION = 1;
- const EXPIRATION = 2;
- const OFFER = 3;
- const CHARGE = 4;
- const EXTERNAL = 5;
- const getAutoGroup = ({ groupId, name }) => {
- if (groupId) return groupId;
- const groupMap = new Map([
- [/activation/i, ACTIVATION],
- [/expiration/i, EXPIRATION],
- [/offer/i, OFFER],
- [/charg/i, CHARGE],
- [/external/i, EXTERNAL],
- ]);
- const foundMapEntry = Array.from(
- groupMap.entries()
- ).find(([regex]) => (
- typeof name === 'string' && regex.test(name)
- ));
- if (foundMapEntry) {
- return foundMapEntry[1];
- }
- };
- try {
- const rows = await ProductOfferingVersionAttributeType.find();
- res.json(map(rows, row => ({
- ...row,
- groupId: getAutoGroup(row)
- })));
- } catch (e) {
- next(e);
- }
- }
Add Comment
Please, Sign In to add comment