Commit 156b9d2c by jaymehta

changes

1 parent 02cf9431
...@@ -84,7 +84,11 @@ ...@@ -84,7 +84,11 @@
}, },
"activityType": { "activityType": {
"type": "enumeration", "type": "enumeration",
"enum": ["indoor", "outdoor", "both"] "enum": [
"indoor",
"outdoor",
"both"
]
}, },
"giftSomeone": { "giftSomeone": {
"type": "boolean" "type": "boolean"
...@@ -117,22 +121,30 @@ ...@@ -117,22 +121,30 @@
"type": "time" "type": "time"
}, },
"fromDate": { "fromDate": {
"type": "time" "type": "date"
}, },
"toDate": { "toDate": {
"type": "time" "type": "date"
}, },
"image": { "image": {
"type": "media", "type": "media",
"multiple": false, "multiple": false,
"required": false, "required": false,
"allowedTypes": ["images"] "allowedTypes": [
"images"
]
}, },
"rating": { "rating": {
"type": "decimal" "type": "decimal"
}, },
"off": { "offers": {
"type": "integer" "type": "integer"
},
"contactPersonForActivity": {
"type": "string"
},
"contactPersonForBooking": {
"type": "string"
} }
} }
} }
...@@ -19,31 +19,33 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -19,31 +19,33 @@ module.exports = createCoreController("api::experience.experience", () => ({
if (!ctx.request.body.data.subCategory) { if (!ctx.request.body.data.subCategory) {
throw new ValidationError("Subcategory is a mandatory field"); throw new ValidationError("Subcategory is a mandatory field");
} }
const months = ctx.request.body.data.months; // const months = ctx.request.body.data.months;
if (!months || !months.length > 0) { // if (!months || !months.length > 0) {
throw new ValidationError("Months is a required field."); // throw new ValidationError("Months is a required field.");
} // }
let monthsIds = []; // let monthsIds = [];
for (let index = 0; index < months.length; index++) { // for (let index = 0; index < months.length; index++) {
const element = months[index]; // const element = months[index];
const singleMonth = await strapi // const singleMonth = await strapi
.query("api::master-month.master-month") // .query("api::master-month.master-month")
.findOne({ // .findOne({
where: { // where: {
name: element.value, // name: element.value,
}, // },
}); // });
// console.log("singleMonth", singleMonth); // // console.log("singleMonth", singleMonth);
monthsIds = [...monthsIds, singleMonth.id] // monthsIds = [...monthsIds, singleMonth.id];
} // }
const subCategory = await strapi.query("api::sub-categorie.sub-categorie").findOne({ const subCategory = await strapi
where: { .query("api::sub-categorie.sub-categorie")
name: { .findOne({
$eq: ctx.request.body.data.subCategory where: {
} name: {
} $eq: ctx.request.body.data.subCategory,
}) },
},
});
const repeatedActivities = await strapi const repeatedActivities = await strapi
.query("api::experience.experience") .query("api::experience.experience")
...@@ -83,40 +85,52 @@ module.exports = createCoreController("api::experience.experience", () => ({ ...@@ -83,40 +85,52 @@ module.exports = createCoreController("api::experience.experience", () => ({
cancellationPolicy: ctx.request.body.data.cancellationPolicy, cancellationPolicy: ctx.request.body.data.cancellationPolicy,
vendor: ctx.request.body.data.vendor.id, vendor: ctx.request.body.data.vendor.id,
subCategory: subCategory.id, subCategory: subCategory.id,
masterMonths: monthsIds, // masterMonths: monthsIds,
giftSomeone: ctx.request.body.data.giftSomeone 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,
}, },
} }
); );
// [{day: "monday", fromTime: "10:20:00", toTime: "18:30:00"}, {day: "tuesday", fromTime: "09:30:00", toTime: "20:00:00"}] // [{day: "monday", fromTime: "10:20:00", toTime: "18:30:00"}, {day: "tuesday", fromTime: "09:30:00", toTime: "20:00:00"}]
const timeSlotsArray = ctx.request.body.data.timeSlots; // const timeSlotsArray = ctx.request.body.data.timeSlots;
if (!timeSlotsArray || !timeSlotsArray.length > 0) { // if (!timeSlotsArray || !timeSlotsArray.length > 0) {
throw new ValidationError("No time slots given."); // throw new ValidationError("No time slots given.");
} // }
let timeSlotIds = []; // let timeSlotIds = [];
for (let index = 0; index < timeSlotsArray.length; index++) { // for (let index = 0; index < timeSlotsArray.length; index++) {
const element = timeSlotsArray[index]; // const element = timeSlotsArray[index];
const timeSlotEntry = await strapi.entityService.create( // const timeSlotEntry = await strapi.entityService.create(
"api::time-slot.time-slot", // "api::time-slot.time-slot",
{ // {
data: { // data: {
masterDay: element.day.id, // masterDay: element.day.id,
start: element.fromTime, // start: element.fromTime,
end: element.toTime, // end: element.toTime,
experience: activity.id, // experience: activity.id,
}, // },
} // }
); // );
timeSlotIds = [...timeSlotIds, timeSlotEntry]; // timeSlotIds = [...timeSlotIds, timeSlotEntry];
} // }
ctx.send({ ctx.send({
success: true, success: true,
message: "Activity Created", message: "Activity Created",
data: { ...activity, timeSlots: { ...timeSlotIds } }, data: {
...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!