diff --git a/src/api/routes/offer.js b/src/api/routes/offer.js index 3b3364c7..30ba4a35 100644 --- a/src/api/routes/offer.js +++ b/src/api/routes/offer.js @@ -105,7 +105,7 @@ export default (app) => { const params = { ...req.body, owner: req.targetOwner, - isPending: application.state === ApplicationStatus.APPROVED ? false : true, + isPending: !(application.state === ApplicationStatus.APPROVED), }; const offer = await (new OfferService()).create(params); diff --git a/src/api/routes/review.js b/src/api/routes/review.js index 46422fd6..122fbc89 100644 --- a/src/api/routes/review.js +++ b/src/api/routes/review.js @@ -10,6 +10,8 @@ import ApplicationService, { } from "../../services/application.js"; import { buildErrorResponse, ErrorTypes } from "../middleware/errorHandler.js"; +import Company from "../../models/Company.js"; +import CompanyService from "../../services/company.js"; const router = Router(); @@ -82,9 +84,10 @@ export default (app) => { async (req, res, next) => { try { - /* TODO: check return account logic*/ - const { account } = await (new ApplicationService()).approve(req.params.id); - return res.json(account); + const account = await (new ApplicationService()).approve(req.params.id); + const company = await Company.findOne({ company: account.company }); + await (new CompanyService()).releaseOffers(company); + return res.json({account}); } catch (err) { console.error(err); if (err instanceof CompanyApplicationNotFound) { diff --git a/src/services/application.js b/src/services/application.js index 9657c0f2..04e1a37f 100644 --- a/src/services/application.js +++ b/src/services/application.js @@ -12,7 +12,7 @@ import { REJECTION_NOTIFICATION, } from "../email-templates/companyApplicationApproval.js"; import config from "../config/env.js"; -import Account from "../models/constants/Account.js"; +import Account from "../models/Account.js"; export class CompanyApplicationNotFound extends Error { @@ -183,9 +183,7 @@ class CompanyApplicationService { console.error(e); throw new CompanyApplicationAlreadyReviewed(CompanyApplicationRules.CANNOT_REVIEW_TWICE.msg); } - return Account.findOne({ email: application.email }); - - /* TODO: Make offers unpending */ + return Account.findOne({ email: application.email }); } async reject(id, reason, options) { diff --git a/src/services/company.js b/src/services/company.js index 4fbed913..394741b9 100644 --- a/src/services/company.js +++ b/src/services/company.js @@ -7,6 +7,8 @@ import { COMPANY_BLOCKED_NOTIFICATION, import EmailService from "../lib/emailService.js"; import Account from "../models/Account.js"; import Company from "../models/Company.js"; +import Offer from "../models/Offer.js" + class CompanyService { getOffersInTimePeriod(owner, publishDate, publishEndDate, OfferModel) { return OfferModel.find({ @@ -189,6 +191,14 @@ class CompanyService { } } + async releaseOffers(companyId) { + try { + await Offer.updateMany({ company : companyId }, { $set: { "isPending" : false } }); + } catch (err) { + console.error(err); + throw err; + } + } } export default CompanyService;