@giftwizard/db-models
Advanced tools
Comparing version 5.0.4 to 5.0.5-optim-2
@@ -41,13 +41,14 @@ module.exports = (sequelizeConnection, DataTypes, Sequelize) => { | ||
const offset = parseInt(page) * limitInt - limitInt; | ||
try { | ||
const { rows, count } = await Customer.findAndCountAll({ | ||
const result = await Customer.findAll({ | ||
limit: limitInt, | ||
offset, | ||
attributes: ['email', 'first_name', 'last_name', 'state'], | ||
include: [ | ||
{ | ||
model: sequelizeConnection.models.LoyaltyCard, | ||
required: true, | ||
required: false, | ||
include: [ | ||
{ | ||
attributes: ['balance', 'code'], | ||
model: sequelizeConnection.models.GiftCard, | ||
@@ -66,6 +67,6 @@ required: true | ||
}, | ||
order: [['id', 'DESC'], ['updated_at', 'DESC']] | ||
order: [['updated_at', 'DESC']] | ||
}); | ||
return { rows, count }; | ||
return result; | ||
} catch (error) { | ||
@@ -122,6 +123,6 @@ throw new Error(`Unable to get all customers page - ${page} for shop - ${shop_url}, ${error}`); | ||
Customer.getCustomersByName = (shop_url, email) => { | ||
Customer.getCustomersSearch = (shop_url, search) => { | ||
const sanitizedSearchQuery = search.trim().toLowerCase(); | ||
const searchQueryTokens = sanitizedSearchQuery.split(/\s+/); | ||
const fields = ['first_name', 'last_name']; | ||
const fields = ['email', 'first_name', 'last_name', 'tags', 'platform_customer_id']; | ||
@@ -137,3 +138,3 @@ const operatorsFields = fields.map(field => { | ||
return Customer.findAll({ | ||
limit: 5, | ||
limit: 20, | ||
where: { | ||
@@ -143,2 +144,12 @@ shop_url, | ||
}, | ||
include: [ | ||
{ | ||
model: sequelizeConnection.models.LoyaltyCard, | ||
include: [ | ||
{ | ||
model: sequelizeConnection.models.GiftCard | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -152,3 +163,2 @@ .then(customers => { | ||
}; | ||
Customer.updateLoyaltyCard = (shop_url, customerId, giftCardId) => { | ||
@@ -155,0 +165,0 @@ return sequelizeConnection.models.LoyaltyCard.create({ gift_card_id: giftCardId }) |
{ | ||
"name": "@giftwizard/db-models", | ||
"version": "5.0.4", | ||
"version": "5.0.5-optim-2", | ||
"description": "Rise.ai package for 'sequelize' models used by several projects.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
81906
3079
3