Skip to content

Commit

Permalink
Merge pull request #97 from Tatino12/Luciano
Browse files Browse the repository at this point in the history
updateProduct !stock, email on newsletter changed!
  • Loading branch information
DemIGoD45 authored Mar 21, 2022
2 parents 25cbf6d + d85f466 commit 9773a2e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
getShopId,
banShop,
getShopDiscounts,
autorizheShop
autorizheShop,
} from "./shop.controller";
import {
addNewComment,
Expand Down Expand Up @@ -63,8 +63,8 @@ export const getAllShops = async (req: Request, res: Response) => {
if (!Number.isNaN(pageAsNumber) && pageAsNumber > 0) {
pageBase = pageAsNumber;
}
const shops = await getShops(pageBase, true as boolean, name as string );

const shops = await getShops(pageBase, true as boolean, name as string);
res.status(200).send(shops);
} catch (error) {
console.error(error);
Expand All @@ -80,27 +80,30 @@ export const getShopsinAwait = async (req: Request, res: Response) => {
if (!Number.isNaN(pageAsNumber) && pageAsNumber > 0) {
pageBase = pageAsNumber;
}
const shops = await getShops(pageBase, false as boolean, undefined )

const shops = await getShops(pageBase, false as boolean, undefined);
res.status(200).send(shops);
} catch (error) {
console.error(error);
res.status(401).json({ msg: "error", error: error });
}
}
};
export const putShopsinAwait = async (req: Request, res: Response) => {
try {
const {shopId} = req.params;
const { shopId } = req.params;
const authorize = req.query.authorize as string;
//console.log(Boolean(parseInt(authorize)));

const shop = await autorizheShop(shopId as string, Boolean(parseInt(authorize)));
if(shop) res.status(200).json({ msg: "Tienda autorizada", shop: shop })
else res.status(400).json({ msg: "Tienda no encontrada", shop: shop })

const shop = await autorizheShop(
shopId as string,
Boolean(parseInt(authorize))
);
if (shop) res.status(200).json({ msg: "Tienda autorizada", shop: shop });
else res.status(400).json({ msg: "Tienda no encontrada", shop: shop });
} catch (error) {
res.status(401).json({ msg: "error", error: error });
}
}
};

export const getShop = async (req: Request, res: Response) => {
try {
Expand All @@ -121,8 +124,8 @@ export const addShop = async (req: Request, res: Response) => {
try {
const data = {
...req.body,
authorization: false
}
authorization: false,
};

const shop = await saveNewShop(data);
if (shop) {
Expand Down Expand Up @@ -331,7 +334,6 @@ export const updateProduct = async (req: Request, res: Response) => {
!description ||
!price ||
!discount ||
!stock ||
!categoriesId
)
throw (new Error().message = "datos");
Expand Down
14 changes: 14 additions & 0 deletions src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,21 @@ export const updateUserMailingState = async (userId: string, boolean: any) => {
data: {
mailingList: bool,
},
select: {
email: true,
},
});
if (bool) {
sendEmail(
updatedUser.email,
"Te has suscripto al newsletter de HumbleFoods!"
);
} else {
sendEmail(
updatedUser.email,
"Has cancelado tu suscripción al newsletter de HumbleFoods!"
);
}
return updatedUser;
} catch (error) {
return null;
Expand Down

0 comments on commit 9773a2e

Please sign in to comment.