Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 2x 2x 1x 1x 6x 6x 6x 6x 5x 4x 1x 3x 5x 3x 1x 1x 1x 7x 7x 7x 1x 1x | 'use strict';
const moment = require('moment-timezone');
const Config = use('Config');
const Event = use('Event');
const CE = use('C2C/Exceptions');
const namespace = Config.get('modules.salon.general.namespace');
const Logger = make('Adonis/Src/Logger');
const defaultDateObject = Config.get('core.shared.general.defaultDateObject');
const { SALON_SCHEDULE_UPDATED } = Config.get('modules.salon.constants');
class SystemSalonScheduleController {
static get inject() {
return [
`${namespace}/Services/SalonService`,
`${namespace}/Services/SystemService`,
`C2C/Services/SalonService`,
];
}
constructor(salonService, systemService, sharedSalonService) {
this.logger = Logger;
this.salonService = salonService;
this.systemService = systemService;
this.sharedSalonService = sharedSalonService;
}
/**
* @swagger
*
* /api/v1/apps/{appId}/salons/{salonId}/schedules:
* get:
* tags:
* - salons
* operationId: 'getSalonSchedule'
* summary: 'getSalonSchedule'
* description: 'Get the salon schedules'
* security:
* - BasicAuth: []
* parameters:
* - name: appId
* in: path
* required: true
* schema:
* type: string
* - name: salonId
* in: path
* required: true
* schema:
* type: string
* responses:
* 200:
* description: 'The salon schedule'
* content:
* application/json; charset=utf-8:
* schema:
* $ref: '#/components/schemas/SalonScheduleResponse'
* 403:
* $ref: '#/components/responses/Forbidden'
* 404:
* $ref: '#/components/responses/NotFound'
* 500:
* description: system error
*/
async index({ request, params, response, transform }) {
const salonId = params.salonId;
const salon = await this.salonService.findSalonIncludeScheduleOrFail(salonId);
const transformed = await transform.collection(
salon.scheduleObjetcs,
'SalonScheduleTransformer',
);
response.success(transformed);
}
/**
* @swagger
*
* /api/v1/apps/{appId}/salons/{salonId}/schedules:
* put:
* tags:
* - salons
* description: update salon schedule by target system
* security:
* - BasicAuth: []
* parameters:
* - $ref: '#/components/parameters/AppIdParam'
* - $ref: '#/components/parameters/SalonIdParam'
* requestBody:
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ScheduleBody'
* responses:
* 200:
* description: 'An object containing the salon information'
* content:
* application/json; charset=utf-8:
* schema:
* $ref: '#/components/schemas/ApiResponse'
* 404:
* description: The salon you requested does not exist
* content:
* application/json:
* schema:
* type: object
* properties:
* statusCode:
* type: number
* example: 404
* error:
* type: string
* example: NotFoundException
* message:
* type: string
* example: The salon you requested does not exist
* data:
* type: array
* example: []
* items:
* type: object
* 500:
* description: system error
*/
async update({ request, params, response, transform }) {
const { schedules } = request.all();
const salonId = params.salonId;
const systemId = params.appId;
const system = await this.systemService.findOrFail(systemId);
const salon = await this.salonService.findByOrFail({
id: salonId,
systemId: system.id,
});
if (salon.lockSchedule) {
throw CE.ForbiddenException.raise('errors.scheduleLocked');
}
const timezone = salon.timezone;
const schedulesData = schedules.map((schedule) => ({
salonId,
dayOfWeek: schedule.dayOfWeek,
startAt: moment(schedule.startAt).tz(timezone).set(defaultDateObject),
endAt: moment(schedule.endAt).tz(timezone).set(defaultDateObject),
}));
const newSchedules = await this.salonService.updateSchedules({ salonId }, schedulesData);
response.success({}); // response
const data = [];
for (let i = 0; i < newSchedules.length; i++) {
const item = newSchedules[i];
await item.reload();
data.push(item.toJSON());
}
Event.fire(SALON_SCHEDULE_UPDATED, {
salonId,
timezone,
schedules: data,
});
}
}
module.exports = SystemSalonScheduleController;
|