Add company specific promocodes
parent
d6a7fa5562
commit
36067f37cb
|
@ -100,6 +100,7 @@ export default contain(
|
|||
|
||||
renderPromo() {
|
||||
const {
|
||||
id,
|
||||
promoApplied,
|
||||
promoCode,
|
||||
promoName,
|
||||
|
@ -145,6 +146,7 @@ export default contain(
|
|||
block={ true }
|
||||
onClick={ () => {
|
||||
jobActions.applyCode({
|
||||
id,
|
||||
code: promoCode,
|
||||
type: isHighlighted ? 'isHighlighted' : null
|
||||
});
|
||||
|
|
|
@ -170,8 +170,11 @@ export default Actions({
|
|||
);
|
||||
});
|
||||
|
||||
jobActions.applyCode.subscribe(({ code = '', type = null}) => {
|
||||
const body = { code: code.replace(/[^\d\w\s]/, '') };
|
||||
jobActions.applyCode.subscribe(({ id, code = '', type = null}) => {
|
||||
const body = {
|
||||
id,
|
||||
code: code.replace(/[^\d\w\s]/, '')
|
||||
};
|
||||
if (type) {
|
||||
body.type = type;
|
||||
}
|
||||
|
|
|
@ -88,6 +88,10 @@
|
|||
"type": "string",
|
||||
"required": true,
|
||||
"description": "How do campers apply to job"
|
||||
},
|
||||
"promoCodeUsed": {
|
||||
"type": "string",
|
||||
"description": "the promocode, if any, that the job uses"
|
||||
}
|
||||
},
|
||||
"validations": [],
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
import { isAlphanumeric } from 'validator';
|
||||
import { isAlphanumeric, isHexadecimal } from 'validator';
|
||||
import debug from 'debug';
|
||||
|
||||
const log = debug('freecc:models:promo');
|
||||
|
||||
export default function promo(Promo) {
|
||||
Promo.getButton = function getButton(code, type = 'isNot') {
|
||||
Promo.getButton = function getButton(id, code, type = 'isNot') {
|
||||
const Job = Promo.app.models.Job;
|
||||
if (!id || !isHexadecimal(id)) {
|
||||
return Promise.reject(new Error(
|
||||
'Must include job id'
|
||||
));
|
||||
}
|
||||
|
||||
if (
|
||||
!isAlphanumeric(code) &&
|
||||
type &&
|
||||
|
@ -14,11 +24,28 @@ export default function promo(Promo) {
|
|||
|
||||
const query = {
|
||||
where: {
|
||||
and: [{ code }, { type }]
|
||||
and: [{
|
||||
code: type === 'isNot' ? type : 'isHighlighted'
|
||||
},
|
||||
{
|
||||
type: type.replace(/^\$/g, '')
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
return Promo.findOne(query);
|
||||
return Promo.findOne(query)
|
||||
.then(function(promo) {
|
||||
return Job.updateAll({ id: id }, { promoCodeUsed: code })
|
||||
.then(function({ count = 0 } = {}) {
|
||||
log('job', count);
|
||||
if (count) {
|
||||
return promo;
|
||||
}
|
||||
return Promise.reject(new Error(
|
||||
`Job ${id} not found`
|
||||
));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Promo.remoteMethod(
|
||||
|
@ -26,6 +53,11 @@ export default function promo(Promo) {
|
|||
{
|
||||
description: 'Get button id for promocode',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'code',
|
||||
type: 'string',
|
||||
|
|
Loading…
Reference in New Issue