/var/www/greso.tech/server/nsm/controllers/company/client
Edit: /var/www/greso.tech/server/nsm/controllers/company/client/edit.js (1122B)
module.exports = function ({ db, logger }) {
const { NotFound, BadRequest } = require('../../../responseModels/errors')
const { isSet, isEmail, isPhone, isEmpty, minLength, isNumber } = require('../../../utils/validator.util')
return async (req, res, next) => {
logger.child({ path: req.path, request: req.query }).info()
let t1 = performance.now()
try {
const { companyId, userId, discount } = req.body
if (!isSet(companyId) || !isSet(userId) ||
isEmpty(companyId) || isEmpty(userId) ||
!isSet(discount) || !isSet(discount) ) {
throw new BadRequest({ lang: req.user?.languageCode })
}
const companyClient = await db.companyClients.findOne({ where: { companyId: companyId, userId: userId } })
// const user = await db.user.findOne({ where: { id: userId } })
if (!companyClient) {
throw new NotFound({ lang: req.user?.languageCode })
}
// company.removeClient(user)
companyClient.discount = discount
companyClient.save()
const time = performance.now() - t1
return res.status(200).json({ status: 'success', time })
} catch (err) {
next(err)
}
}
}