UNPKG

tuain-ecosystem-lib

Version:

Servicio de gestión mensajería instantanea de la plataforma Tuain

99 lines (86 loc) 2.25 kB
const { ObjectId } = require('mongodb'); const commonQueries = require('./common'); function findSetupProdPrice(productPriceTypeId, productId, subproductId, setupId) { const query = { productPriceTypeId: ObjectId(productPriceTypeId), productId: ObjectId(productId), setupId: ObjectId(setupId), }; if (subproductId) { query.subproductId = ObjectId(subproductId); } return query; } function findCurrentGroupSetup(setupId, groupId) { return { setupId: ObjectId(setupId), groupId: ObjectId(groupId), active: true, }; } function findCurrentThirdSetup(setupId, thirdPartyId) { return { setupId: ObjectId(setupId), thirdPartyId: ObjectId(thirdPartyId), }; } function findGroupSetup(groupId) { return { groupId: ObjectId(groupId), active: true, }; } function findThirdSetup(thirdPartyId, groupId = null) { const setupQuery = { thirdPartyId: ObjectId(thirdPartyId), active: true }; if (groupId) { setupQuery.groupId = ObjectId(groupId); } return setupQuery; } function findOldThirdSetup(thirdPartyId, groupId = null) { const setupQuery = { thirdPartyId: ObjectId(thirdPartyId), active: false }; if (groupId) { setupQuery.groupId = groupId; } return setupQuery; } function addScale(scale) { return { $addToSet: { scales: scale, }, }; } function deleteScale(minValue) { return { $pull: { scales: { minValue }, }, }; } function findAuditSetupProdPrice(productPriceTypeId, productId, subproductId, setupId) { return { productPriceTypeId, productId, subproductId, setupId, priceEndDate: null }; } function findBySetup(setupId) { return { setupId: ObjectId(setupId) }; } function findSetupConfig(setupId, productId, subproductId = null) { const basicProductPriceFind = { setupId: ObjectId(setupId), productId: ObjectId(productId) }; if (subproductId) { basicProductPriceFind.subproductId = ObjectId(subproductId); } return basicProductPriceFind; } module.exports = { ...commonQueries, // Stores findSetupProdPrice, findGroupSetup, findAuditSetupProdPrice, findCurrentGroupSetup, findThirdSetup, findOldThirdSetup, findCurrentThirdSetup, addScale, deleteScale, findBySetup, findSetupConfig, };