From ab43bd3bc8769daf7590a9df8c7bd0d4af3a1cd7 Mon Sep 17 00:00:00 2001 From: dsantosferreira Date: Sat, 15 Apr 2023 00:54:16 +0100 Subject: [PATCH] Created new isPending attribute in Offer model and implemented creating of pending offers depending on application status Co-authored-by: Francisco Cardoso --- src/api/routes/offer.js | 11 ++++++++--- src/models/Offer.js | 4 ++++ src/services/offer.js | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/api/routes/offer.js b/src/api/routes/offer.js index c4116257..3b3364c7 100644 --- a/src/api/routes/offer.js +++ b/src/api/routes/offer.js @@ -11,6 +11,9 @@ import ValidationReasons from "../middleware/validators/validationReasons.js"; import { or, when } from "../middleware/utils.js"; import OfferConstants from "../../models/constants/Offer.js"; import * as companyValidators from "../middleware/validators/company.js"; +import CompanyApplication from "../../models/CompanyApplication.js"; +import Account from "../../models/Account.js" +import ApplicationStatus from "../../models/constants/ApplicationStatus.js"; const router = Router(); @@ -96,11 +99,13 @@ export default (app) => { (req, res, next) => companyMiddleware.isNotDisabled(req.targetOwner)(req, res, next)), validators.offersDateSanitizers, async (req, res, next) => { - try { - + try { + const account = await Account.findOne({ company: req.targetOwner }); + const application = await CompanyApplication.findOne({ email: account.email }); const params = { ...req.body, - owner: req.targetOwner + owner: req.targetOwner, + isPending: application.state === ApplicationStatus.APPROVED ? false : true, }; const offer = await (new OfferService()).create(params); diff --git a/src/models/Offer.js b/src/models/Offer.js index b6275af3..4270b9e3 100644 --- a/src/models/Offer.js +++ b/src/models/Offer.js @@ -85,6 +85,10 @@ const OfferSchema = new Schema({ type: Boolean, default: false }, + isPending: { + type: Boolean, + default: false, + }, isArchived: { type: Boolean, default: false diff --git a/src/services/offer.js b/src/services/offer.js index 61f2541e..badaf627 100644 --- a/src/services/offer.js +++ b/src/services/offer.js @@ -34,6 +34,7 @@ class OfferService { fields, technologies, isHidden, + isPending, owner, location, coordinates, @@ -57,6 +58,7 @@ class OfferService { fields, technologies, isHidden, + isPending, owner, ownerName, ownerLogo,