service entry
This commit is contained in:
parent
9f807a783d
commit
a5e519f634
1 changed files with 22 additions and 0 deletions
|
|
@ -2,6 +2,9 @@ const uuid = require('uuid');
|
|||
|
||||
const OfferCreated = require('../models/OfferCreated');
|
||||
const OfferDetailsSet = require('../models/OfferDetailsSet');
|
||||
const OfferDeleted = require('../models/OfferDeleted');
|
||||
|
||||
const errors = require('../errors');
|
||||
|
||||
async function createOffer(publicKey, offerDetails) {
|
||||
const offerCreated = await OfferCreated.create({
|
||||
|
|
@ -28,6 +31,25 @@ async function createOffer(publicKey, offerDetails) {
|
|||
});
|
||||
}
|
||||
|
||||
async function deleteOffer(offerUuid) {
|
||||
const offerExists = Boolean(
|
||||
await OfferCreated.findOne({ where: { uuid: offerUuid } })
|
||||
);
|
||||
const offerHasBeenDeleted = Boolean(
|
||||
await OfferDeleted.findOne({ where: { offer_uuid: offerUuid } })
|
||||
);
|
||||
|
||||
if (!offerExists || offerHasBeenDeleted) {
|
||||
throw new errors.NotFoundError(`Could not find the offer.`);
|
||||
}
|
||||
|
||||
return OfferDeleted.create({
|
||||
uuid: uuid.v7(),
|
||||
offer_uuid: offerUuid,
|
||||
created_at: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
async function getOffersByPublicKey(publicKey) {
|
||||
const offers = await OfferCreated.findAll({
|
||||
where: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue