Add promo model
parent
03db485112
commit
568d1ef1d2
|
@ -0,0 +1,49 @@
|
||||||
|
import { isAlphanumeric } from 'validator';
|
||||||
|
|
||||||
|
export default function promo(Promo) {
|
||||||
|
Promo.getButton = function getButton(code, type = null) {
|
||||||
|
|
||||||
|
if (
|
||||||
|
!isAlphanumeric(code) &&
|
||||||
|
type &&
|
||||||
|
!isAlphanumeric(type)
|
||||||
|
) {
|
||||||
|
return Promise.reject(new Error(
|
||||||
|
'Code or Type should be an alphanumeric'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = {
|
||||||
|
where: {
|
||||||
|
code,
|
||||||
|
type
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return Promo.findOne(query);
|
||||||
|
};
|
||||||
|
|
||||||
|
Promo.remoteMethod(
|
||||||
|
'getButton',
|
||||||
|
{
|
||||||
|
description: 'Get button id for promocode',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'code',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'type',
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'promo',
|
||||||
|
type: 'object'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
{
|
||||||
|
"name": "promo",
|
||||||
|
"base": "PersistedModel",
|
||||||
|
"strict": true,
|
||||||
|
"idInjection": true,
|
||||||
|
"trackChanges": false,
|
||||||
|
"properties": {
|
||||||
|
"code": {
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"description": "The code to unlock the promotional discount"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"description": "The name of the discount"
|
||||||
|
},
|
||||||
|
"buttonId": {
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"description": "The id of paypal button"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A selector of different types of buttons for the same discount"
|
||||||
|
},
|
||||||
|
"fullPrice": {
|
||||||
|
"type": "number",
|
||||||
|
"required": true,
|
||||||
|
"description": "The original amount"
|
||||||
|
},
|
||||||
|
"discountAmount": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "The amount of the discount if applicable"
|
||||||
|
},
|
||||||
|
"discountPercent": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "The amount of discount as a percentage if applicable"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"validations": [],
|
||||||
|
"relations": {},
|
||||||
|
"acls": [
|
||||||
|
{
|
||||||
|
"accessType": "*",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "$everyone",
|
||||||
|
"permission": "DENY"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"accessType": "EXECUTE",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "$everyone",
|
||||||
|
"permission": "ALLOW",
|
||||||
|
"property": "getButton"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"methods": []
|
||||||
|
}
|
|
@ -51,6 +51,10 @@
|
||||||
"dataSource": "db",
|
"dataSource": "db",
|
||||||
"public": true
|
"public": true
|
||||||
},
|
},
|
||||||
|
"promo": {
|
||||||
|
"dataSource": "db",
|
||||||
|
"public": true
|
||||||
|
},
|
||||||
"user": {
|
"user": {
|
||||||
"dataSource": "db",
|
"dataSource": "db",
|
||||||
"public": true
|
"public": true
|
||||||
|
|
Loading…
Reference in New Issue