Commit d211e8ac by jaymehta

activity update

1 parent f28c1a3b
...@@ -22,24 +22,6 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -22,24 +22,6 @@ module.exports = createCoreController("api::experience.experience", () => ({
if (!ctx.request.body.data.category) { if (!ctx.request.body.data.category) {
throw new ValidationError("Category is a mandatory field"); throw new ValidationError("Category is a mandatory field");
} }
// const months = ctx.request.body.data.months;
// if (!months || !months.length > 0) {
// throw new ValidationError("Months is a required field.");
// }
// let monthsIds = [];
// for (let index = 0; index < months.length; index++) {
// const element = months[index];
// const singleMonth = await strapi
// .query("api::master-month.master-month")
// .findOne({
// where: {
// name: element.value,
// },
// });
// // console.log("singleMonth", singleMonth);
// monthsIds = [...monthsIds, singleMonth.id];
// }
const subCategory = await strapi const subCategory = await strapi
.query("api::sub-categorie.sub-categorie") .query("api::sub-categorie.sub-categorie")
.findOne({ .findOne({
...@@ -50,9 +32,7 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -50,9 +32,7 @@ module.exports = createCoreController("api::experience.experience", () => ({
}, },
}); });
const category = await strapi const category = await strapi.query("api::categorie.categorie").findOne({
.query("api::categorie.categorie")
.findOne({
where: { where: {
name: { name: {
$eq: ctx.request.body.data.category, $eq: ctx.request.body.data.category,
...@@ -100,7 +80,6 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -100,7 +80,6 @@ module.exports = createCoreController("api::experience.experience", () => ({
vendor: ctx.request.body.data.vendor.id, vendor: ctx.request.body.data.vendor.id,
subCategory: subCategory.id, subCategory: subCategory.id,
category: category.id, category: category.id,
// masterMonths: monthsIds,
giftSomeone: ctx.request.body.data.giftSomeone, giftSomeone: ctx.request.body.data.giftSomeone,
fromDate: ctx.request.body.data.fromDate, fromDate: ctx.request.body.data.fromDate,
toDate: ctx.request.body.data.toDate, toDate: ctx.request.body.data.toDate,
...@@ -108,43 +87,100 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -108,43 +87,100 @@ module.exports = createCoreController("api::experience.experience", () => ({
toTime: ctx.request.body.data.toTime, toTime: ctx.request.body.data.toTime,
offers: ctx.request.body.data.offers, offers: ctx.request.body.data.offers,
rating: ctx.request.body.data.rating, rating: ctx.request.body.data.rating,
contactPersonForActivity: ctx.request.body.data.contactPersonForActivity, contactPersonForActivity:
contactPersonForBooking: ctx.request.body.data.contactPersonForBooking, ctx.request.body.data.contactPersonForActivity,
contactPersonForBooking:
ctx.request.body.data.contactPersonForBooking,
...ctx.request.body.data.daysBoolean, ...ctx.request.body.data.daysBoolean,
}, },
} }
); );
// [{day: "monday", fromTime: "10:20:00", toTime: "18:30:00"}, {day: "tuesday", fromTime: "09:30:00", toTime: "20:00:00"}] ctx.send({
success: true,
message: "Activity Created",
data: {
...activity,
},
});
},
async update(ctx) {
if (!ctx.request.body.data.vendor) {
throw new ValidationError("Vendor is a mandatory field.");
}
if (!ctx.request.body.data.pincode) {
throw new ValidationError("Pincode is a mandatory field.");
}
if (!ctx.request.body.data.subCategory) {
throw new ValidationError("Subcategory is a mandatory field");
}
if (!ctx.request.body.data.category) {
throw new ValidationError("Category is a mandatory field");
}
const subCategory = await strapi
.query("api::sub-categorie.sub-categorie")
.findOne({
where: {
name: {
$eq: ctx.request.body.data.subCategory,
},
},
});
// const timeSlotsArray = ctx.request.body.data.timeSlots; const category = await strapi.query("api::categorie.categorie").findOne({
// if (!timeSlotsArray || !timeSlotsArray.length > 0) { where: {
// throw new ValidationError("No time slots given."); name: {
// } $eq: ctx.request.body.data.category,
// let timeSlotIds = []; },
// for (let index = 0; index < timeSlotsArray.length; index++) { },
// const element = timeSlotsArray[index]; });
// const timeSlotEntry = await strapi.entityService.create( const activity = await strapi.entityService.update(
// "api::time-slot.time-slot", "api::experience.experience",
// { { id: ctx.request.body.data.activityId },
// data: { {
// masterDay: element.day.id, data: {
// start: element.fromTime, name: ctx.request.body.data.name,
// end: element.toTime, description: ctx.request.body.data.description,
// experience: activity.id, 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,
// timeSlotIds = [...timeSlotIds, timeSlotEntry]; 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,
},
}
);
ctx.send({ ctx.send({
success: true, success: true,
message: "Activity Created", message: "Activity updated",
data: { data: {
...activity, ...activity,
// timeSlots: { ...timeSlotIds }
}, },
}); });
}, },
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!