Skip to content

Commit

Permalink
feat: 🎸 Added endpoint for modifiers removal
Browse files Browse the repository at this point in the history
DELETE: /facility/:facilityId/modifier/:modifierKey; DELETE:
/facility/:facilityId/:itemKey/:itemId/modifier/:modifierKey

✅ Closes: #18
  • Loading branch information
kostysh committed Jun 6, 2022
1 parent 7651648 commit 8a9c602
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 2 deletions.
51 changes: 51 additions & 0 deletions src/controllers/FacilityController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,57 @@ export class FacilityController {
next(e);
}
};

// Removes a modifier from the facility
removeModifierOfFacility = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { facilityId, modifierKey } = req.params;

const repository = new FacilityModifierRepository(facilityId);
await repository.delModifier(
modifierKey as ModifiersKey
);

res.json({ success: true });
} catch (e) {
next(e);
}
};

// Removes modifier of the item: `spaces` or `otherItems`
removeModifierOfItem = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { facilityId, itemKey, itemId, modifierKey } = req.params;
let repository: SpaceModifierRepository | OtherItemsModifierRepository;

switch (itemKey) {
case 'spaces':
repository = new SpaceModifierRepository(facilityId, itemId);
break;
case 'otherItems':
repository = new OtherItemsModifierRepository(facilityId, itemId);
break;
default:
throw ApiError.BadRequest('Invalid item key');
}

await repository.delModifier(
modifierKey as ModifiersKey
);

res.json({ success: true });
} catch (e) {
next(e);
}
};
}

export default new FacilityController();
115 changes: 113 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ router.get(
* security:
* - bearerAuth: []
* summary: add modifier to the facility
* tags: [Facility service, availability]
* tags: [Facility service, modifiers]
* requestBody:
* required: true
* content:
Expand Down Expand Up @@ -632,6 +632,8 @@ router.get(
* description: User is not Auth
* 403:
* description: Access denied
* 404:
* description: Not Found
* 500:
* description: Some server error
*/
Expand All @@ -648,7 +650,7 @@ router.post(
* security:
* - bearerAuth: []
* summary: add modifier to the facility
* tags: [Facility service, availability]
* tags: [Facility service, modifiers]
* requestBody:
* required: true
* content:
Expand Down Expand Up @@ -697,6 +699,8 @@ router.post(
* description: User is not Auth
* 403:
* description: Access denied
* 404:
* description: Not Found
* 500:
* description: Some server error
*/
Expand All @@ -705,3 +709,110 @@ router.post(
authMiddleware,
facilityController.createItemModifier
);

/**
* @swagger
* /facility/{facilityId}/modifier/{modifierKey}:
* delete:
* security:
* - bearerAuth: []
* summary: remove modifier from the facility
* tags: [Facility service, modifiers]
* parameters:
* - in: path
* name: facilityId
* description: The facility Id
* required: true
* schema:
* type: string
* - in: path
* name: modifierKey
* description: The facility modifier key
* required: true
* schema:
* type: string
* enum: ["day_of_week", "occupancy", "length_of_stay"]
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* 401:
* description: User is not Auth
* 403:
* description: Access denied
* 404:
* description: Not Found
* 500:
* description: Some server error
*/
router.delete(
'/facility/:facilityId/modifier/:modifierKey',
authMiddleware,
facilityController.removeModifierOfFacility
);

/**
* @swagger
* /facility/{facilityId}/{itemKey}/{itemId}/modifier/{modifierKey}:
* delete:
* security:
* - bearerAuth: []
* summary: remove modifier of the item kind of space or otherItems
* tags: [Facility service, modifiers]
* parameters:
* - in: path
* name: facilityId
* description: The facility Id
* required: true
* schema:
* type: string
* - in: path
* name: itemKey
* description: Type of item
* required: true
* schema:
* type: string
* enum: ["spaces", "otherItems"]
* - in: path
* name: itemId
* description: The item Id
* required: true
* schema:
* type: string
* - in: path
* name: modifierKey
* description: The facility modifier key
* required: true
* schema:
* type: string
* enum: ["day_of_week", "occupancy", "length_of_stay"]
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* 401:
* description: User is not Auth
* 403:
* description: Access denied
* 404:
* description: Not Found
* 500:
* description: Some server error
*/
router.delete(
'/facility/:facilityId/:itemKey/:itemId/modifier/:modifierKey',
authMiddleware,
facilityController.removeModifierOfItem
);

0 comments on commit 8a9c602

Please sign in to comment.