first service

This commit is contained in:
counterweight 2025-03-06 01:26:36 +01:00
parent cdc344c528
commit 56aa416751
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 89 additions and 80 deletions

View file

@ -2,6 +2,14 @@ class ServicesProvider {
constructor() {} constructor() {}
provide() { provide() {
const invitesService = require('../services/invitesService');
const nostrService = require('../services/nostrService');
const loginService = require('../services/loginService');
const sessionService = require('../services/sessionService');
const profileService = require('../services/profileService');
const OfferServiceProvider = require('../services/offerService');
const offerService = new OfferServiceProvider().provide();
return { return {
invitesService, invitesService,
nostrService, nostrService,
@ -13,11 +21,4 @@ class ServicesProvider {
} }
} }
const invitesService = require('../services/invitesService');
const nostrService = require('../services/nostrService');
const loginService = require('../services/loginService');
const sessionService = require('../services/sessionService');
const profileService = require('../services/profileService');
const offerService = require('../services/offerService');
module.exports = ServicesProvider; module.exports = ServicesProvider;

View file

@ -4,7 +4,9 @@ const models = require('../models');
const errors = require('../errors'); const errors = require('../errors');
async function createOffer(publicKey, offerDetails) { class OfferServiceProvider {
provide() {
async function createOffer(publicKey, offerDetails) {
const offerCreated = await models.OfferCreated.create({ const offerCreated = await models.OfferCreated.create({
uuid: uuid.v7(), uuid: uuid.v7(),
public_key: publicKey, public_key: publicKey,
@ -20,16 +22,17 @@ async function createOffer(publicKey, offerDetails) {
location_details: offerDetails.location_details, location_details: offerDetails.location_details,
time_availability_details: offerDetails.time_availability_details, time_availability_details: offerDetails.time_availability_details,
show_offer_to_trusted: offerDetails.show_offer_to_trusted, show_offer_to_trusted: offerDetails.show_offer_to_trusted,
show_offer_to_trusted_trusted: offerDetails.show_offer_to_trusted_trusted, show_offer_to_trusted_trusted:
offerDetails.show_offer_to_trusted_trusted,
show_offer_to_all_members: offerDetails.show_offer_to_all_members, show_offer_to_all_members: offerDetails.show_offer_to_all_members,
is_onchain_accepted: offerDetails.is_onchain_accepted, is_onchain_accepted: offerDetails.is_onchain_accepted,
is_lightning_accepted: offerDetails.is_lightning_accepted, is_lightning_accepted: offerDetails.is_lightning_accepted,
are_big_notes_accepted: offerDetails.are_big_notes_accepted, are_big_notes_accepted: offerDetails.are_big_notes_accepted,
created_at: new Date().toISOString(), created_at: new Date().toISOString(),
}); });
} }
async function deleteOffer(offerUuid) { async function deleteOffer(offerUuid) {
const offerExists = Boolean( const offerExists = Boolean(
await models.OfferCreated.findOne({ where: { uuid: offerUuid } }) await models.OfferCreated.findOne({ where: { uuid: offerUuid } })
); );
@ -46,9 +49,9 @@ async function deleteOffer(offerUuid) {
offer_uuid: offerUuid, offer_uuid: offerUuid,
created_at: new Date().toISOString(), created_at: new Date().toISOString(),
}); });
} }
async function getOffersByPublicKey(publicKey) { async function getOffersByPublicKey(publicKey) {
const offers = await models.OfferCreated.findAll({ const offers = await models.OfferCreated.findAll({
where: { where: {
public_key: publicKey, public_key: publicKey,
@ -93,5 +96,10 @@ async function getOffersByPublicKey(publicKey) {
} }
return offersToReturn; return offersToReturn;
}
return { createOffer, getOffersByPublicKey, deleteOffer };
}
} }
module.exports = { createOffer, getOffersByPublicKey, deleteOffer };
module.exports = OfferServiceProvider;