prevent modification of billing type
This commit is contained in:
parent
0d5ef11b1e
commit
11e6a98bc7
@ -114,7 +114,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX this is because we did the wrong thing and used the subName as a primary key
|
// XXX this is because we did the wrong thing and used the subName as a primary key
|
||||||
const existing = await models.sub.findUnique({
|
const old = await models.sub.findUnique({
|
||||||
where: {
|
where: {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
userId: me.id
|
userId: me.id
|
||||||
@ -123,8 +123,8 @@ export default {
|
|||||||
|
|
||||||
await ssValidate(territorySchema, data, { models, me })
|
await ssValidate(territorySchema, data, { models, me })
|
||||||
|
|
||||||
if (existing) {
|
if (old) {
|
||||||
return await updateSub(parent, data, { me, models, lnd, hash, hmac })
|
return await updateSub(parent, data, { me, models, lnd, hash, hmac, old })
|
||||||
} else {
|
} else {
|
||||||
return await createSub(parent, data, { me, models, lnd, hash, hmac })
|
return await createSub(parent, data, { me, models, lnd, hash, hmac })
|
||||||
}
|
}
|
||||||
@ -236,24 +236,14 @@ async function createSub (parent, data, { me, models, lnd, hash, hmac }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function updateSub (parent, { name, ...data }, { me, models, lnd, hash, hmac }) {
|
async function updateSub (parent, { name, ...data }, { me, models, lnd, hash, hmac }) {
|
||||||
const { billingType } = data
|
// prevent modification of billingType
|
||||||
|
delete data.billingType
|
||||||
let billingCost = TERRITORY_COST_MONTHLY
|
|
||||||
if (billingType === 'ONCE') {
|
|
||||||
billingCost = TERRITORY_COST_ONCE
|
|
||||||
} else if (billingType === 'YEARLY') {
|
|
||||||
billingCost = TERRITORY_COST_YEARLY
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const results = await serialize(models,
|
const results = await serialize(models,
|
||||||
// update 'em
|
// update 'em
|
||||||
models.sub.update({
|
models.sub.update({
|
||||||
data: {
|
data,
|
||||||
...data,
|
|
||||||
billingCost,
|
|
||||||
billingType
|
|
||||||
},
|
|
||||||
where: {
|
where: {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user