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 | 1x 1x 1x 1x 6x 6x 2x 2x 1x 1x 4x 4x 4x 4x 4x 1x 3x 3x 1x 2x 2x 2x 2x 1x | 'use strict';
const _ = require('lodash');
const Config = use('Config');
const namespace = Config.get('modules.thirdParty.general.namespace');
const CE = use('C2C/Exceptions');
class SystemStaffThirdPartyController {
static get inject() {
return [`${namespace}/Services/ThirdPartyService`];
}
constructor(thirdPartyService) {
this.thirdPartyService = thirdPartyService;
}
/**
* @swagger
*
* /api/v1/apps/third-parties/{thirdPartyCode}/staff/{staffId}:
* get:
* tags:
* - third-parties
* operationId: 'getStaffByThirdPartySourceId'
* summary: 'getStaffByThirdPartySourceId'
* parameters:
* - $ref: '#/components/parameters/ThirdPartyCodeParam'
* - $ref: '#/components/parameters/StaffIdParam'
* responses:
* 200:
* description: |-
* OK
* content:
* application/json; charset=utf-8:
* schema:
* $ref: '#/components/schemas/StaffResponse'
* 401:
* $ref: '#/components/responses/Unauthorized'
* 404:
* $ref: '#/components/responses/NotFound'
* deprecated: false
* security:
* - BasicAuth: []
*/
async show({ request, params, response, thirdParty, transform }) {
const id = decodeURIComponent(params.id);
const staff = await this.thirdPartyService.findStaffByThirdPartyId(thirdParty, id);
const transformed = await transform
.include('services,services.category,connections')
.item(staff, 'StaffTransformer');
return response.success(transformed, 200);
}
/**
* @swagger
*
* /api/v1/apps/third-parties/{thirdPartyCode}/salons/{salonId}/staff:
* put:
* tags:
* - third-parties
* operationId: 'putThirdPartySourceStaff'
* summary: 'putThirdPartySourceStaff'
* parameters:
* - $ref: '#/components/parameters/ThirdPartyCodeParam'
* - $ref: '#/components/parameters/SalonIdParam'
* requestBody:
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/ThirdPartyStaffBody'
* responses:
* 200:
* description: |-
* OK
* content:
* application/json; charset=utf-8:
* schema:
* $ref: '#/components/schemas/ApiResponse'
* 401:
* $ref: '#/components/responses/Unauthorized'
* 404:
* $ref: '#/components/responses/NotFound'
* deprecated: false
* security:
* - BasicAuth: []
*/
async update({ request, response, thirdParty, salon }) {
let thirdPartyStaffs = request.input('thirdPartyStaffs', []);
thirdPartyStaffs = thirdPartyStaffs.map(({ sourceId, name, kana, email }) => ({
thirdPartyId: thirdParty.id,
salonId: salon.id,
sourceId,
name,
kana,
email,
}));
// check unique by sourceId in input
const sourceIds = thirdPartyStaffs.map(({ sourceId }) => sourceId);
const uniqSourceIds = _.uniq(sourceIds);
if (sourceIds.length !== uniqSourceIds.length) {
throw CE.BadRequestException.raise('errors.duplicateSourceIdValues');
}
// check unique by sourceId in database
const existsBySourceIds = await this.thirdPartyService.getListSourceStaff({
salonId: ['<>', salon.id],
sourceId: ['IN', sourceIds],
});
if (existsBySourceIds.size() > 0) {
throw CE.BadRequestException.raise('errors.duplicateSourceIdValues');
}
// delete old source staff
await this.thirdPartyService.deleteAllSourceStaff({
thirdPartyId: thirdParty.id,
salonId: salon.id,
});
// add new source staff
await this.thirdPartyService.createManySourceStaff(thirdPartyStaffs);
// delete connection by source ids
await this.thirdPartyService.deleteStaffThirdPartyConnectionBy({
salonId: salon.id,
thirdPartyId: thirdParty.id,
sourceId: ['NOT_IN', sourceIds],
});
return response.success();
}
}
module.exports = SystemStaffThirdPartyController;
|