Skip to content

Commit

Permalink
Created new isPending attribute in Offer model and implemented creati…
Browse files Browse the repository at this point in the history
…ng of pending offers depending on application status

Co-authored-by: Francisco Cardoso <[email protected]>
  • Loading branch information
dsantosferreira and FranciscoCardoso913 committed Apr 14, 2023
1 parent ce93f75 commit ab43bd3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/api/routes/offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/models/Offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ const OfferSchema = new Schema({
type: Boolean,
default: false
},
isPending: {
type: Boolean,
default: false,
},
isArchived: {
type: Boolean,
default: false
Expand Down
2 changes: 2 additions & 0 deletions src/services/offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class OfferService {
fields,
technologies,
isHidden,
isPending,
owner,
location,
coordinates,
Expand All @@ -57,6 +58,7 @@ class OfferService {
fields,
technologies,
isHidden,
isPending,
owner,
ownerName,
ownerLogo,
Expand Down

0 comments on commit ab43bd3

Please sign in to comment.