Feat/nested return reasons (#418)
* api endpoints for nested return_reasons * add nested return reasons to database * add parent reason to update * integration tests * add children relation * integration tests for nested returns and failing doubly nesting returns * add delete-route and nested relations * delete return reason route * doubly nested return reason creation check and deletion * nested return reasons migration * list only parent reasons * removed null filter * remove empty migration * add return reason filter to get list of categories with children * removed console log * corrected delete route * return reason testing * return reasons query * listREasonsFromIDs * create return testing * listReasonsFromIds * return reason tests * failing if returnreason has child on return * integration tests * cascading deletes on return reasons * more elegant checking for children of return reasons when creating a return * remove console.log * pr adjust Co-authored-by: Philip Korsholm <phko@MacBook-Pro.localdomain>
This commit is contained in:
co-authored by
Philip Korsholm
parent
4db860f9ab
commit
42cdfde6d9
@@ -39,6 +39,7 @@ export default async (req, res) => {
|
||||
const schema = Validator.object().keys({
|
||||
value: Validator.string().required(),
|
||||
label: Validator.string().required(),
|
||||
parent_return_reason_id: Validator.string().optional(),
|
||||
description: Validator.string()
|
||||
.optional()
|
||||
.allow(""),
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @oas [delete] /return-reason/{id}
|
||||
* operationId: "DeleteReturnReason"
|
||||
* summary: "Delete a return reason"
|
||||
* description: "Deletes a return reason."
|
||||
* parameters:
|
||||
* - (path) id=* {string} The id of the return reason
|
||||
* tags:
|
||||
* - Return Reason
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* properties:
|
||||
* id:
|
||||
* type: string
|
||||
* description: The id of the deleted return reason
|
||||
* object:
|
||||
* type: string
|
||||
* description: The type of the object that was deleted.
|
||||
* deleted:
|
||||
* type: boolean
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
try {
|
||||
const returnReasonService = req.scope.resolve("returnReasonService")
|
||||
await returnReasonService.delete(id)
|
||||
|
||||
res.json({
|
||||
id: id,
|
||||
object: "return_reason",
|
||||
deleted: true,
|
||||
})
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,11 @@ export default app => {
|
||||
*/
|
||||
route.post("/:id", middlewares.wrap(require("./update-reason").default))
|
||||
|
||||
/**
|
||||
* Delete a reason
|
||||
*/
|
||||
route.delete("/:id", middlewares.wrap(require("./delete-reason").default))
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
@@ -33,10 +38,14 @@ export const defaultFields = [
|
||||
"id",
|
||||
"value",
|
||||
"label",
|
||||
"parent_return_reason_id",
|
||||
"description",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
]
|
||||
|
||||
export const defaultRelations = []
|
||||
export const defaultRelations = [
|
||||
"parent_return_reason",
|
||||
"return_reason_children",
|
||||
]
|
||||
|
||||
@@ -24,7 +24,7 @@ export default async (req, res) => {
|
||||
try {
|
||||
const returnReasonService = req.scope.resolve("returnReasonService")
|
||||
|
||||
const query = {}
|
||||
const query = { parent_return_reason_id: null }
|
||||
const data = await returnReasonService.list(query, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
|
||||
@@ -42,6 +42,7 @@ export default async (req, res) => {
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
label: Validator.string().optional(),
|
||||
parent_return_reason_id: Validator.string().optional(),
|
||||
description: Validator.string()
|
||||
.optional()
|
||||
.allow(""),
|
||||
|
||||
@@ -23,10 +23,14 @@ export const defaultFields = [
|
||||
"id",
|
||||
"value",
|
||||
"label",
|
||||
"parent_return_reason_id",
|
||||
"description",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
]
|
||||
|
||||
export const defaultRelations = []
|
||||
export const defaultRelations = [
|
||||
"parent_return_reason",
|
||||
"return_reason_children",
|
||||
]
|
||||
|
||||
@@ -24,7 +24,7 @@ export default async (req, res) => {
|
||||
try {
|
||||
const returnReasonService = req.scope.resolve("returnReasonService")
|
||||
|
||||
const query = {}
|
||||
const query = { parent_return_reason_id: null}
|
||||
const data = await returnReasonService.list(query, {
|
||||
select: defaultFields,
|
||||
relations: defaultRelations,
|
||||
|
||||
Reference in New Issue
Block a user