Skip to content

Commit

Permalink
Merge pull request #344 from NIAEFEUP/fix/image-upload-company-edit
Browse files Browse the repository at this point in the history
Removed url and string constraint from file image argument
  • Loading branch information
tomaspalma committed Mar 13, 2024
2 parents 81bce7c + f8194c1 commit 82886d0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/api/middleware/validators/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,4 @@ export const edit = useExpressValidators([
.withMessage(ValidationReasons.ARRAY_SIZE(CompanyConstants.contacts.min_length, CompanyConstants.contacts.max_length)),
body("logo", ValidationReasons.DEFAULT)
.optional()
.isString().withMessage(ValidationReasons.STRING).bail()
.isURL().withMessage(ValidationReasons.URL),
]);
5 changes: 3 additions & 2 deletions src/api/routes/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { concurrentOffersNotExceeded } from "../middleware/validators/validatorU

import { or } from "../middleware/utils.js";

import * as fileMiddleware from "../middleware/files.js";
import * as fileMiddleware from "../middleware/files.js";
import OfferService from "../../services/offer.js";
import AccountService from "../../services/account.js";
import Offer from "../../models/Offer.js";
Expand Down Expand Up @@ -245,7 +245,8 @@ export default (app) => {
try {
const companyService = new CompanyService();
const offerService = new OfferService();
const company = await companyService.changeAttributes(req.params.companyId, req.body);
const logo = req.file && (req?.file?.url || `${config.webserver_host}/static/${req.file.filename}`);
const company = await companyService.changeAttributes(req.params.companyId, { ...req.body, logo });
await offerService.updateAllOffersByCompanyId(company);
return res.json(company);
} catch (err) {
Expand Down

0 comments on commit 82886d0

Please sign in to comment.