chore: server code formatting

This commit is contained in:
Rafael Taranto 2025-05-12 15:35:00 +01:00
parent aedabcbdee
commit 68517170e2
234 changed files with 9824 additions and 6195 deletions

View file

@ -1,62 +1,66 @@
const db = require('./db')
const uuid = require('uuid')
const _ = require('lodash/fp')
const pgp = require('pg-promise')()
function getAvailablePromoCodes () {
function getAvailablePromoCodes() {
const sql = `SELECT * FROM coupons WHERE soft_deleted=false`
return db.any(sql)
}
function getPromoCode (code) {
function getPromoCode(code) {
const sql = `SELECT * FROM coupons WHERE code=$1 AND soft_deleted=false`
return db.oneOrNone(sql, [code])
}
function createPromoCode (code, discount) {
function createPromoCode(code, discount) {
const sql = `INSERT INTO coupons (id, code, discount) VALUES ($1, $2, $3) RETURNING *`
return db.one(sql, [uuid.v4(), code, discount])
}
function deletePromoCode (id) {
function deletePromoCode(id) {
const sql = `UPDATE coupons SET soft_deleted=true WHERE id=$1`
return db.none(sql, [id])
}
function getNumberOfAvailablePromoCodes () {
function getNumberOfAvailablePromoCodes() {
const sql = `SELECT COUNT(id) FROM coupons WHERE soft_deleted=false`
return db.one(sql).then(res => res.count)
}
function getAvailableIndividualDiscounts () {
function getAvailableIndividualDiscounts() {
const sql = `SELECT * FROM individual_discounts WHERE soft_deleted=false`
return db.any(sql).then(res => _.map(it => ({
id: it.id,
customerId: it.customer_id,
discount: it.discount
}), res))
return db.any(sql).then(res =>
_.map(
it => ({
id: it.id,
customerId: it.customer_id,
discount: it.discount,
}),
res,
),
)
}
function getCustomerActiveIndividualDiscount (customerId) {
function getCustomerActiveIndividualDiscount(customerId) {
const sql = `SELECT * FROM individual_discounts WHERE customer_id=$1 AND soft_deleted=false LIMIT 1`
return db.oneOrNone(sql, [customerId]).then(res => {
if (!_.isNil(res)) {
return {
id: res.id,
customerId: res.customer_id,
discount: res.discount
discount: res.discount,
}
}
return res
})
}
function createIndividualDiscount (customerId, discount) {
function createIndividualDiscount(customerId, discount) {
const sql = `INSERT INTO individual_discounts (id, customer_id, discount) VALUES ($1, $2, $3)`
return db.none(sql, [uuid.v4(), customerId, discount])
}
function deleteIndividualDiscount (id) {
function deleteIndividualDiscount(id) {
const sql = `UPDATE individual_discounts SET soft_deleted=true WHERE id=$1`
return db.none(sql, [id])
}
@ -70,5 +74,5 @@ module.exports = {
getAvailableIndividualDiscounts,
getCustomerActiveIndividualDiscount,
createIndividualDiscount,
deleteIndividualDiscount
deleteIndividualDiscount,
}