Skip to content

Commit

Permalink
improves promo codes (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreromao authored Apr 10, 2024
1 parent 7653900 commit 0c1b6a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion server/db/promo-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const mongoose = require('mongoose')
const schema = new mongoose.Schema({
company: String,
edition: String,
expire: Date,
validity: {
from: Date,
to: Date
},
description: String,
code: String
})
Expand Down
7 changes: 6 additions & 1 deletion server/resources/promo-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ server.method('promoCode.get', get, {})
async function get () {
let now = new Date()

filter = {
'validity.from': { $lte: now },
'validity.to': { $gte: now }
}

try {
let codes = await PromoCode.find({ expire: { '$gt': now.toISOString() } }, {}, {})
let codes = await PromoCode.find(filter)
if (!codes) {
log.warn({ err: err }, 'could not find promo code')
return cb(Boom.notFound())
Expand Down
2 changes: 1 addition & 1 deletion server/views/promo-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function renderObject (model) {
return {
company: model.company,
edition: model.edition,
expire: model.expire,
expire: model.validity.to,
description: model.description,
code: model.code
}
Expand Down

0 comments on commit 0c1b6a0

Please sign in to comment.