Commit 0223f390 by jaymehta

update req

1 parent 4bc23d2c
...@@ -105,85 +105,47 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -105,85 +105,47 @@ module.exports = createCoreController("api::experience.experience", () => ({
}); });
}, },
async update(ctx) { // async update(ctx) {
// if (!ctx.request.body.data.vendor) { // // if (!ctx.request.body.data.vendor) {
// throw new ValidationError("Vendor is a mandatory field."); // // throw new ValidationError("Vendor is a mandatory field.");
// // }
// console.log("ctx>", ctx.request.body);
// if (!ctx.request.body.data.pincode) {
// throw new ValidationError("Pincode is a mandatory field.");
// } // }
console.log("ctx>", ctx.request.body); // if (!ctx.request.body.data.subCategory) {
if (!ctx.request.body.data.pincode) { // throw new ValidationError("Subcategory is a mandatory field");
throw new ValidationError("Pincode is a mandatory field."); // }
} // if (!ctx.request.body.data.category) {
if (!ctx.request.body.data.subCategory) { // throw new ValidationError("Category is a mandatory field");
throw new ValidationError("Subcategory is a mandatory field"); // }
} // console.log("subcategoyr", ctx.params);
if (!ctx.request.body.data.category) { // const { id } = ctx.params;
throw new ValidationError("Category is a mandatory field");
}
console.log("subcategoyr", ctx.params);
const { id } = ctx.params;
const subCategory = await strapi
.query("api::sub-categorie.sub-categorie")
.findOne({
where: {
name: {
$eq: ctx.request.body.data.subCategory,
},
},
});
const category = await strapi.query("api::categorie.categorie").findOne({
where: {
name: {
$eq: ctx.request.body.data.category,
},
},
});
console.log(
"ctx.request.body.data.activityId",
ctx.request.body.data.activityId
);
const updatedExperience = await strapi
.query("api::experience.experience")
.update(
{ id },
{
name: ctx.request.body.data.name,
description: ctx.request.body.data.description,
pricePerPerson: ctx.request.body.data.pricePerPerson,
address: ctx.request.body.data.address,
masterPincode: ctx.request.body.data.pincode.id,
minimumDuration: ctx.request.body.data.minimumDuration,
maximumDuration: ctx.request.body.data.maximumDuration,
duration: ctx.request.body.data.duration,
ageLowerLimit: ctx.request.body.data.ageLowerLimit,
ageNotes: ctx.request.body.data.ageNotes,
phoneNumber: ctx.request.body.data.phoneNumber,
minGroupSize: ctx.request.body.data.minGroupSize,
maxGroupSize: ctx.request.body.data.maxGroupSize,
activityType: ctx.request.body.data.activityType,
link: ctx.request.body.data.link,
cancellationPolicy: ctx.request.body.data.cancellationPolicy,
// vendor: ctx.request.body.data.vendor.id,
subCategory: subCategory.id,
category: category.id,
giftSomeone: ctx.request.body.data.giftSomeone,
fromDate: ctx.request.body.data.fromDate,
toDate: ctx.request.body.data.toDate,
fromTime: ctx.request.body.data.fromTime,
toTime: ctx.request.body.data.toTime,
offers: ctx.request.body.data.offers,
rating: ctx.request.body.data.rating,
contactPersonForActivity:
ctx.request.body.data.contactPersonForActivity,
contactPersonForBooking:
ctx.request.body.data.contactPersonForBooking,
...ctx.request.body.data.daysBoolean,
}
);
// const activity = await strapi.entityService.update( // const subCategory = await strapi
// "api::experience.experience", // .query("api::sub-categorie.sub-categorie")
// { id: ctx.request.body.data.activityId }, // .findOne({
// where: {
// name: {
// $eq: ctx.request.body.data.subCategory,
// },
// },
// });
// const category = await strapi.query("api::categorie.categorie").findOne({
// where: {
// name: {
// $eq: ctx.request.body.data.category,
// },
// },
// });
// console.log(
// "ctx.request.body.data.activityId",
// ctx.request.body.data.activityId
// );
// const updatedExperience = await strapi
// .query("api::experience.experience")
// .update(
// { id },
// { // {
// name: ctx.request.body.data.name, // name: ctx.request.body.data.name,
// description: ctx.request.body.data.description, // description: ctx.request.body.data.description,
...@@ -213,17 +175,55 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -213,17 +175,55 @@ module.exports = createCoreController("api::experience.experience", () => ({
// rating: ctx.request.body.data.rating, // rating: ctx.request.body.data.rating,
// contactPersonForActivity: // contactPersonForActivity:
// ctx.request.body.data.contactPersonForActivity, // ctx.request.body.data.contactPersonForActivity,
// contactPersonForBooking: ctx.request.body.data.contactPersonForBooking, // contactPersonForBooking:
// ctx.request.body.data.contactPersonForBooking,
// ...ctx.request.body.data.daysBoolean, // ...ctx.request.body.data.daysBoolean,
// } // }
// ); // );
console.log("updatedExperience", updatedExperience);
ctx.send({ // // const activity = await strapi.entityService.update(
success: true, // // "api::experience.experience",
message: "Activity updated", // // { id: ctx.request.body.data.activityId },
data: { // // {
...updatedExperience, // // name: ctx.request.body.data.name,
}, // // description: ctx.request.body.data.description,
}); // // pricePerPerson: ctx.request.body.data.pricePerPerson,
}, // // address: ctx.request.body.data.address,
// // masterPincode: ctx.request.body.data.pincode.id,
// // minimumDuration: ctx.request.body.data.minimumDuration,
// // maximumDuration: ctx.request.body.data.maximumDuration,
// // duration: ctx.request.body.data.duration,
// // ageLowerLimit: ctx.request.body.data.ageLowerLimit,
// // ageNotes: ctx.request.body.data.ageNotes,
// // phoneNumber: ctx.request.body.data.phoneNumber,
// // minGroupSize: ctx.request.body.data.minGroupSize,
// // maxGroupSize: ctx.request.body.data.maxGroupSize,
// // activityType: ctx.request.body.data.activityType,
// // link: ctx.request.body.data.link,
// // cancellationPolicy: ctx.request.body.data.cancellationPolicy,
// // // vendor: ctx.request.body.data.vendor.id,
// // subCategory: subCategory.id,
// // category: category.id,
// // giftSomeone: ctx.request.body.data.giftSomeone,
// // fromDate: ctx.request.body.data.fromDate,
// // toDate: ctx.request.body.data.toDate,
// // fromTime: ctx.request.body.data.fromTime,
// // toTime: ctx.request.body.data.toTime,
// // offers: ctx.request.body.data.offers,
// // rating: ctx.request.body.data.rating,
// // contactPersonForActivity:
// // ctx.request.body.data.contactPersonForActivity,
// // contactPersonForBooking: ctx.request.body.data.contactPersonForBooking,
// // ...ctx.request.body.data.daysBoolean,
// // }
// // );
// console.log("updatedExperience", updatedExperience);
// ctx.send({
// success: true,
// message: "Activity updated",
// data: {
// ...updatedExperience,
// },
// });
// },
})); }));
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!