Add promo model

pull/4032/head
Berkeley Martinez 2015-10-25 14:26:37 -07:00
parent 03db485112
commit 568d1ef1d2
3 changed files with 112 additions and 0 deletions

49
common/models/promo.js Normal file
View File

@ -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'
}
]
}
);
}

59
common/models/promo.json Normal file
View File

@ -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": []
}

View File

@ -51,6 +51,10 @@
"dataSource": "db",
"public": true
},
"promo": {
"dataSource": "db",
"public": true
},
"user": {
"dataSource": "db",
"public": true