-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/evershop/src/modules/checkout/api/deleteShippingZone/deleteShippingZone.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable camelcase */ | ||
const { | ||
rollback, | ||
commit, | ||
startTransaction, | ||
del, | ||
select | ||
} = require('@evershop/postgres-query-builder'); | ||
const { | ||
getConnection | ||
} = require('@evershop/evershop/src/lib/postgres/connection'); | ||
const { | ||
OK, | ||
INTERNAL_SERVER_ERROR, | ||
INVALID_PAYLOAD | ||
} = require('@evershop/evershop/src/lib/util/httpStatus'); | ||
const { error } = require('@evershop/evershop/src/lib/log/logger'); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
module.exports = async (request, response, deledate, next) => { | ||
const { id } = request.params; | ||
const connection = await getConnection(); | ||
await startTransaction(connection); | ||
try { | ||
// Load the shipping zone | ||
const shippingZone = await select() | ||
.from('shipping_zone') | ||
.where('uuid', '=', id) | ||
.load(connection); | ||
|
||
if (!shippingZone) { | ||
response.status(INVALID_PAYLOAD); | ||
response.json({ | ||
error: { | ||
status: INVALID_PAYLOAD, | ||
message: 'Invalid zone id' | ||
} | ||
}); | ||
return; | ||
} | ||
const zone = await del('shipping_zone') | ||
.where('uuid', '=', id) | ||
.execute(connection); | ||
|
||
await commit(connection); | ||
response.status(OK); | ||
response.json({ | ||
data: zone | ||
}); | ||
} catch (e) { | ||
error(e); | ||
await rollback(connection); | ||
response.status(INTERNAL_SERVER_ERROR); | ||
response.json({ | ||
error: { | ||
status: INTERNAL_SERVER_ERROR, | ||
message: e.message | ||
} | ||
}); | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/evershop/src/modules/checkout/api/deleteShippingZone/route.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"methods": ["DELETE"], | ||
"path": "/shippingZones/:id", | ||
"access": "private" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ const ZonesQuery = ` | |
updateApi | ||
} | ||
updateApi | ||
deleteApi | ||
addMethodApi | ||
} | ||
} | ||
|