service entry

This commit is contained in:
counterweight 2025-03-05 00:48:33 +01:00
parent 9f807a783d
commit a5e519f634
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -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: {