-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
32 changed files
with
783 additions
and
468 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
8 changes: 0 additions & 8 deletions
8
...rshop/src/modules/catalog/api/createCollection/[getConnection]createCollection[finish].js
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
packages/evershop/src/modules/catalog/api/createCollection/createCollection[finish].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,9 @@ | ||
const createCollection = require('../../services/collection/createCollection'); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
module.exports = async (request, response, delegate) => { | ||
const collection = await createCollection(request.body, { | ||
routeId: request.currentRoute.id | ||
}); | ||
return collection; | ||
}; |
77 changes: 20 additions & 57 deletions
77
packages/evershop/src/modules/catalog/api/createCollection/finish[apiResponse].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 |
---|---|---|
@@ -1,64 +1,27 @@ | ||
const { | ||
commit, | ||
rollback, | ||
select | ||
} = require('@evershop/postgres-query-builder'); | ||
const { pool } = require('@evershop/evershop/src/lib/postgres/connection'); | ||
const { buildUrl } = require('@evershop/evershop/src/lib/router/buildUrl'); | ||
const { | ||
OK, | ||
INTERNAL_SERVER_ERROR | ||
} = require('@evershop/evershop/src/lib/util/httpStatus'); | ||
const { OK } = require('@evershop/evershop/src/lib/util/httpStatus'); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
module.exports = async (request, response, delegate, next) => { | ||
const promises = []; | ||
Object.keys(delegate).forEach((id) => { | ||
// Check if middleware is async | ||
if (delegate[id] instanceof Promise) { | ||
promises.push(delegate[id]); | ||
const collection = await delegate.createCollection; | ||
response.status(OK); | ||
response.json({ | ||
data: { | ||
...collection, | ||
links: [ | ||
{ | ||
rel: 'collectionGrid', | ||
href: buildUrl('collectionGrid'), | ||
action: 'GET', | ||
types: ['text/xml'] | ||
}, | ||
{ | ||
rel: 'edit', | ||
href: buildUrl('collectionEdit', { id: collection.uuid }), | ||
action: 'GET', | ||
types: ['text/xml'] | ||
} | ||
] | ||
} | ||
}); | ||
const result = await delegate.createCollection; | ||
const connection = await delegate.getConnection; | ||
const results = await Promise.allSettled(promises); | ||
const rejected = results.find((r) => r.status === 'rejected'); | ||
if (!rejected) { | ||
await commit(connection); | ||
// Load the created collection | ||
const query = select().from('collection'); | ||
const collection = await query | ||
.where('collection_id', '=', result.insertId) | ||
.load(pool); | ||
response.status(OK); | ||
response.json({ | ||
data: { | ||
...collection, | ||
links: [ | ||
{ | ||
rel: 'collectionGrid', | ||
href: buildUrl('collectionGrid'), | ||
action: 'GET', | ||
types: ['text/xml'] | ||
}, | ||
{ | ||
rel: 'edit', | ||
href: buildUrl('collectionEdit', { id: collection.uuid }), | ||
action: 'GET', | ||
types: ['text/xml'] | ||
} | ||
] | ||
} | ||
}); | ||
} else { | ||
await rollback(connection); | ||
response.status(INTERNAL_SERVER_ERROR); | ||
response.json({ | ||
data: null, | ||
error: { | ||
status: INTERNAL_SERVER_ERROR, | ||
message: rejected.reason.message | ||
} | ||
}); | ||
} | ||
}; |
12 changes: 0 additions & 12 deletions
12
packages/evershop/src/modules/catalog/api/createCollection/getConnection[finish].js
This file was deleted.
Oops, something went wrong.
14 changes: 2 additions & 12 deletions
14
packages/evershop/src/modules/catalog/api/createCollection/payloadSchema.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 |
---|---|---|
@@ -1,20 +1,10 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
"type": "string" | ||
}, | ||
"code": { | ||
"type": "string" | ||
"type": "string", | ||
"skipEscape": true | ||
} | ||
}, | ||
"required": [ | ||
"name", | ||
"description", | ||
"code" | ||
], | ||
"additionalProperties": true | ||
} |
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
28 changes: 6 additions & 22 deletions
28
packages/evershop/src/modules/catalog/api/deleteAttribute/deleteAttribute.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
34 changes: 6 additions & 28 deletions
34
packages/evershop/src/modules/catalog/api/deleteCategory/deleteCategory.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
26 changes: 6 additions & 20 deletions
26
packages/evershop/src/modules/catalog/api/deleteCollection/deleteCollection.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
32 changes: 5 additions & 27 deletions
32
packages/evershop/src/modules/catalog/api/deleteProduct/deleteProduct.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
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
31 changes: 0 additions & 31 deletions
31
...rshop/src/modules/catalog/api/updateCollection/[getConnection]updateCollection[finish].js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.