@webiny/api-aco 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c59b9cc5b9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/createAcoFields.js +2 -2
- package/createAcoFields.js.map +1 -1
- package/createAcoGraphQL.js +10 -9
- package/createAcoGraphQL.js.map +1 -1
- package/createAcoModels.js +1 -11
- package/createAcoModels.js.map +1 -1
- package/folder/folder.gql.js +20 -5
- package/folder/folder.gql.js.map +1 -1
- package/folder/folder.model.d.ts +3 -3
- package/folder/folder.model.js +3 -7
- package/folder/folder.model.js.map +1 -1
- package/folder/folder.so.d.ts +1 -6
- package/folder/folder.so.js +103 -108
- package/folder/folder.so.js.map +1 -1
- package/folder/folder.types.d.ts +2 -2
- package/folder/folder.types.js.map +1 -1
- package/folder/onFolderBeforeDelete.hook.js +11 -11
- package/folder/onFolderBeforeDelete.hook.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js +17 -3
- package/index.js.map +1 -1
- package/package.json +32 -31
- package/record/record.crud.js +3 -0
- package/record/record.crud.js.map +1 -1
- package/record/record.gql.js +77 -8
- package/record/record.gql.js.map +1 -1
- package/record/record.model.d.ts +3 -3
- package/record/record.model.js +12 -25
- package/record/record.model.js.map +1 -1
- package/record/record.so.d.ts +1 -6
- package/record/record.so.js +101 -62
- package/record/record.so.js.map +1 -1
- package/record/record.types.d.ts +24 -7
- package/record/record.types.js.map +1 -1
- package/types.d.ts +11 -0
- package/types.js +35 -1
- package/types.js.map +1 -1
- package/utils/acoRecordId.d.ts +6 -0
- package/utils/acoRecordId.js +33 -0
- package/utils/acoRecordId.js.map +1 -0
- package/utils/checkPermissions.d.ts +2 -0
- package/utils/checkPermissions.js +14 -0
- package/utils/checkPermissions.js.map +1 -0
- package/utils/createListSort.d.ts +2 -0
- package/utils/createListSort.js +13 -0
- package/utils/createListSort.js.map +1 -0
- package/utils/createModelField.d.ts +0 -1
- package/utils/createModelField.js +2 -4
- package/utils/createModelField.js.map +1 -1
- package/utils/createOperationsWrapper.d.ts +9 -0
- package/utils/createOperationsWrapper.js +29 -0
- package/utils/createOperationsWrapper.js.map +1 -0
- package/utils/getFieldValues.d.ts +4 -1
- package/utils/getFieldValues.js +6 -2
- package/utils/getFieldValues.js.map +1 -1
- package/utils/modelFactory.d.ts +3 -3
- package/utils/modelFactory.js +4 -2
- package/utils/modelFactory.js.map +1 -1
- package/context/folders.d.ts +0 -2
- package/context/folders.js +0 -261
- package/context/folders.js.map +0 -1
- package/context/index.d.ts +0 -2
- package/context/index.js +0 -22
- package/context/index.js.map +0 -1
- package/context/links.d.ts +0 -2
- package/context/links.js +0 -270
- package/context/links.js.map +0 -1
- package/graphql/base.gql.d.ts +0 -3
- package/graphql/base.gql.js +0 -63
- package/graphql/base.gql.js.map +0 -1
- package/graphql/folders.gql.d.ts +0 -3
- package/graphql/folders.gql.js +0 -126
- package/graphql/folders.gql.js.map +0 -1
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +0 -15
- package/graphql/index.js.map +0 -1
- package/graphql/links.gql.d.ts +0 -3
- package/graphql/links.gql.js +0 -123
- package/graphql/links.gql.js.map +0 -1
- package/subscriptions/afterFolderDelete.d.ts +0 -3
- package/subscriptions/afterFolderDelete.js +0 -62
- package/subscriptions/afterFolderDelete.js.map +0 -1
- package/subscriptions/index.d.ts +0 -3
- package/subscriptions/index.js +0 -14
- package/subscriptions/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -18,16 +18,16 @@ yarn add @webiny/api-aco
|
|
|
18
18
|
```
|
|
19
19
|
## Testing
|
|
20
20
|
|
|
21
|
-
To run tests api-
|
|
21
|
+
To run tests api-aco tests with targeted storage operations loaded use:
|
|
22
22
|
|
|
23
23
|
### DynamoDB
|
|
24
24
|
|
|
25
25
|
```
|
|
26
|
-
yarn test packages/api-aco --keyword=cms:ddb --keyword=aco:base
|
|
26
|
+
yarn test packages/api-aco/* --keyword=cms:ddb --keyword=aco:base
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
### DynamoDB + ElasticSearch
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
```
|
|
32
|
+
yarn test packages/api-aco/* --keyword=cms:ddb-es --keyword=aco:base
|
|
33
|
+
```
|
package/createAcoFields.js
CHANGED
|
@@ -9,8 +9,8 @@ const jsonField = {
|
|
|
9
9
|
name: "cms-model-field-to-graphql-json",
|
|
10
10
|
type: "cms-model-field-to-graphql",
|
|
11
11
|
fieldType: "wby-aco-json",
|
|
12
|
-
isSortable:
|
|
13
|
-
isSearchable:
|
|
12
|
+
isSortable: true,
|
|
13
|
+
isSearchable: true,
|
|
14
14
|
read: {
|
|
15
15
|
createTypeField({
|
|
16
16
|
field
|
package/createAcoFields.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["jsonField","name","type","fieldType","isSortable","isSearchable","read","createTypeField","field","fieldId","createGetFilters","manage","createInputField","createAcoFields"],"sources":["createAcoFields.ts"],"sourcesContent":["import { CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\n\n// Creating an internal JSON field, we are using it inside the `record` type\nconst jsonField: CmsModelFieldToGraphQLPlugin = {\n name: \"cms-model-field-to-graphql-json\",\n type: \"cms-model-field-to-graphql\",\n fieldType: \"wby-aco-json\",\n isSortable:
|
|
1
|
+
{"version":3,"names":["jsonField","name","type","fieldType","isSortable","isSearchable","read","createTypeField","field","fieldId","createGetFilters","manage","createInputField","createAcoFields"],"sources":["createAcoFields.ts"],"sourcesContent":["import { CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\n\n// Creating an internal JSON field, we are using it inside the `record` type\nconst jsonField: CmsModelFieldToGraphQLPlugin = {\n name: \"cms-model-field-to-graphql-json\",\n type: \"cms-model-field-to-graphql\",\n fieldType: \"wby-aco-json\",\n isSortable: true,\n isSearchable: true,\n read: {\n createTypeField({ field }) {\n return `${field.fieldId}: JSON`;\n },\n createGetFilters({ field }) {\n return `${field.fieldId}: JSON`;\n }\n },\n manage: {\n createTypeField({ field }) {\n return `${field.fieldId}: JSON`;\n },\n createInputField({ field }) {\n return field.fieldId + \": JSON\";\n }\n }\n};\n\nexport const createAcoFields = (): CmsModelFieldToGraphQLPlugin[] => [jsonField];\n"],"mappings":";;;;;;AAEA;AACA,MAAMA,SAAuC,GAAG;EAC5CC,IAAI,EAAE,iCAAiC;EACvCC,IAAI,EAAE,4BAA4B;EAClCC,SAAS,EAAE,cAAc;EACzBC,UAAU,EAAE,IAAI;EAChBC,YAAY,EAAE,IAAI;EAClBC,IAAI,EAAE;IACFC,eAAe,CAAC;MAAEC;IAAM,CAAC,EAAE;MACvB,OAAQ,GAAEA,KAAK,CAACC,OAAQ,QAAO;IACnC,CAAC;IACDC,gBAAgB,CAAC;MAAEF;IAAM,CAAC,EAAE;MACxB,OAAQ,GAAEA,KAAK,CAACC,OAAQ,QAAO;IACnC;EACJ,CAAC;EACDE,MAAM,EAAE;IACJJ,eAAe,CAAC;MAAEC;IAAM,CAAC,EAAE;MACvB,OAAQ,GAAEA,KAAK,CAACC,OAAQ,QAAO;IACnC,CAAC;IACDG,gBAAgB,CAAC;MAAEJ;IAAM,CAAC,EAAE;MACxB,OAAOA,KAAK,CAACC,OAAO,GAAG,QAAQ;IACnC;EACJ;AACJ,CAAC;AAEM,MAAMI,eAAe,GAAG,MAAsC,CAACb,SAAS,CAAC;AAAC"}
|
package/createAcoGraphQL.js
CHANGED
|
@@ -51,15 +51,16 @@ const baseSchema = new _handlerGraphql.GraphQLSchemaPlugin({
|
|
|
51
51
|
error: AcoError
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
enum
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
enum AcoSortDirection {
|
|
55
|
+
ASC
|
|
56
|
+
DESC
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
input AcoSort {
|
|
60
|
+
id: AcoSortDirection
|
|
61
|
+
createdOn: AcoSortDirection
|
|
62
|
+
savedOn: AcoSortDirection
|
|
63
|
+
title: AcoSortDirection
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
extend type Query {
|
package/createAcoGraphQL.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["emptyResolver","baseSchema","GraphQLSchemaPlugin","typeDefs","resolvers","Query","aco","search","Mutation","createAcoGraphQL","ContextPlugin","context","plugins","register","folderSchema","searchRecordSchema"],"sources":["createAcoGraphQL.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\n\nimport { folderSchema } from \"~/folder/folder.gql\";\nimport { searchRecordSchema } from \"~/record/record.gql\";\n\nimport { AcoContext } from \"~/types\";\n\nconst emptyResolver = () => ({});\n\nconst baseSchema = new GraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type AcoQuery {\n _empty: String\n }\n\n type AcoMutation {\n _empty: String\n }\n\n type SearchQuery {\n _empty: String\n }\n\n type SearchMutation {\n _empty: String\n }\n\n type AcoMeta {\n hasMoreItems: Boolean\n totalCount: Int\n cursor: String\n }\n\n type AcoUser {\n id: ID\n displayName: String\n type: String\n }\n\n type AcoError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type AcoBooleanResponse {\n data: Boolean\n error: AcoError\n }\n\n enum
|
|
1
|
+
{"version":3,"names":["emptyResolver","baseSchema","GraphQLSchemaPlugin","typeDefs","resolvers","Query","aco","search","Mutation","createAcoGraphQL","ContextPlugin","context","plugins","register","folderSchema","searchRecordSchema"],"sources":["createAcoGraphQL.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\n\nimport { folderSchema } from \"~/folder/folder.gql\";\nimport { searchRecordSchema } from \"~/record/record.gql\";\n\nimport { AcoContext } from \"~/types\";\n\nconst emptyResolver = () => ({});\n\nconst baseSchema = new GraphQLSchemaPlugin({\n typeDefs: /* GraphQL */ `\n type AcoQuery {\n _empty: String\n }\n\n type AcoMutation {\n _empty: String\n }\n\n type SearchQuery {\n _empty: String\n }\n\n type SearchMutation {\n _empty: String\n }\n\n type AcoMeta {\n hasMoreItems: Boolean\n totalCount: Int\n cursor: String\n }\n\n type AcoUser {\n id: ID\n displayName: String\n type: String\n }\n\n type AcoError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type AcoBooleanResponse {\n data: Boolean\n error: AcoError\n }\n\n enum AcoSortDirection {\n ASC\n DESC\n }\n\n input AcoSort {\n id: AcoSortDirection\n createdOn: AcoSortDirection\n savedOn: AcoSortDirection\n title: AcoSortDirection\n }\n\n extend type Query {\n aco: AcoQuery\n search: SearchQuery\n }\n\n extend type Mutation {\n aco: AcoMutation\n search: SearchMutation\n }\n `,\n resolvers: {\n Query: {\n aco: emptyResolver,\n search: emptyResolver\n },\n Mutation: {\n aco: emptyResolver,\n search: emptyResolver\n }\n }\n});\n\nexport const createAcoGraphQL = () => {\n return new ContextPlugin<AcoContext>(context => {\n context.plugins.register([baseSchema, folderSchema, searchRecordSchema]);\n });\n};\n"],"mappings":";;;;;;AAAA;AACA;AAEA;AACA;AAIA,MAAMA,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;AAEhC,MAAMC,UAAU,GAAG,IAAIC,mCAAmB,CAAC;EACvCC,QAAQ,EAAE,aAAe;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EACDC,SAAS,EAAE;IACPC,KAAK,EAAE;MACHC,GAAG,EAAEN,aAAa;MAClBO,MAAM,EAAEP;IACZ,CAAC;IACDQ,QAAQ,EAAE;MACNF,GAAG,EAAEN,aAAa;MAClBO,MAAM,EAAEP;IACZ;EACJ;AACJ,CAAC,CAAC;AAEK,MAAMS,gBAAgB,GAAG,MAAM;EAClC,OAAO,IAAIC,kBAAa,CAAaC,OAAO,IAAI;IAC5CA,OAAO,CAACC,OAAO,CAACC,QAAQ,CAAC,CAACZ,UAAU,EAAEa,oBAAY,EAAEC,0BAAkB,CAAC,CAAC;EAC5E,CAAC,CAAC;AACN,CAAC;AAAC"}
|
package/createAcoModels.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.createAcoModels = void 0;
|
|
8
7
|
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
8
|
var _folder = require("./folder/folder.model");
|
|
11
9
|
var _record = require("./record/record.model");
|
|
12
|
-
var _modelFactory = require("./utils/modelFactory");
|
|
13
10
|
var _isInstallationPending = require("./utils/isInstallationPending");
|
|
11
|
+
var _modelFactory = require("./utils/modelFactory");
|
|
14
12
|
const createAcoModels = context => {
|
|
15
13
|
/**
|
|
16
14
|
* This should never happen in the actual project.
|
|
@@ -26,11 +24,6 @@ const createAcoModels = context => {
|
|
|
26
24
|
})) {
|
|
27
25
|
return;
|
|
28
26
|
}
|
|
29
|
-
context.security.disableAuthorization();
|
|
30
|
-
const locale = context.i18n.getContentLocale();
|
|
31
|
-
if (!locale) {
|
|
32
|
-
throw new _error.default("Missing content locale in api-aco/storageOperations/index.ts", "LOCALE_ERROR");
|
|
33
|
-
}
|
|
34
27
|
const groupId = "contentModelGroup_aco";
|
|
35
28
|
|
|
36
29
|
/**
|
|
@@ -52,8 +45,6 @@ const createAcoModels = context => {
|
|
|
52
45
|
const cmsModelPlugins = modelDefinitions.map(modelDefinition => {
|
|
53
46
|
return (0, _modelFactory.modelFactory)({
|
|
54
47
|
group: cmsGroupPlugin.contentModelGroup,
|
|
55
|
-
tenant: context.tenancy.getCurrentTenant().id,
|
|
56
|
-
locale: locale.code,
|
|
57
48
|
modelDefinition
|
|
58
49
|
});
|
|
59
50
|
});
|
|
@@ -62,6 +53,5 @@ const createAcoModels = context => {
|
|
|
62
53
|
* Register them so that they are accessible in cms context
|
|
63
54
|
*/
|
|
64
55
|
context.plugins.register([cmsGroupPlugin, cmsModelPlugins]);
|
|
65
|
-
context.security.enableAuthorization();
|
|
66
56
|
};
|
|
67
57
|
exports.createAcoModels = createAcoModels;
|
package/createAcoModels.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createAcoModels","context","cms","console","warn","isInstallationPending","tenancy","i18n","
|
|
1
|
+
{"version":3,"names":["createAcoModels","context","cms","console","warn","isInstallationPending","tenancy","i18n","groupId","cmsGroupPlugin","CmsGroupPlugin","id","slug","name","description","icon","isPrivate","modelDefinitions","createFolderModelDefinition","createSearchModelDefinition","cmsModelPlugins","map","modelDefinition","modelFactory","group","contentModelGroup","plugins","register"],"sources":["createAcoModels.ts"],"sourcesContent":["import { CmsGroupPlugin } from \"@webiny/api-headless-cms\";\nimport { CmsContext } from \"@webiny/api-headless-cms/types\";\nimport { createFolderModelDefinition } from \"~/folder/folder.model\";\nimport { createSearchModelDefinition } from \"~/record/record.model\";\nimport { isInstallationPending } from \"~/utils/isInstallationPending\";\nimport { modelFactory } from \"~/utils/modelFactory\";\n\nexport const createAcoModels = (context: CmsContext) => {\n /**\n * This should never happen in the actual project.\n * It is to make sure that we load setup context before the CRUD init in our internal code.\n */\n if (!context.cms) {\n console.warn(\"Creating model before cms init.\");\n return;\n }\n\n if (isInstallationPending({ tenancy: context.tenancy, i18n: context.i18n })) {\n return;\n }\n\n const groupId = \"contentModelGroup_aco\";\n\n /**\n * Create a CmsGroup.\n */\n const cmsGroupPlugin = new CmsGroupPlugin({\n id: groupId,\n slug: \"aco\",\n name: \"ACO\",\n description: \"Group for Advanced Content Organisation and Search\",\n icon: \"fas/folder\",\n isPrivate: true\n });\n\n /**\n * Create CmsModel plugins.\n */\n const modelDefinitions = [createFolderModelDefinition(), createSearchModelDefinition()];\n const cmsModelPlugins = modelDefinitions.map(modelDefinition => {\n return modelFactory({\n group: cmsGroupPlugin.contentModelGroup,\n modelDefinition\n });\n });\n\n /**\n * Register them so that they are accessible in cms context\n */\n context.plugins.register([cmsGroupPlugin, cmsModelPlugins]);\n};\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AACA;AAEO,MAAMA,eAAe,GAAIC,OAAmB,IAAK;EACpD;AACJ;AACA;AACA;EACI,IAAI,CAACA,OAAO,CAACC,GAAG,EAAE;IACdC,OAAO,CAACC,IAAI,CAAC,iCAAiC,CAAC;IAC/C;EACJ;EAEA,IAAI,IAAAC,4CAAqB,EAAC;IAAEC,OAAO,EAAEL,OAAO,CAACK,OAAO;IAAEC,IAAI,EAAEN,OAAO,CAACM;EAAK,CAAC,CAAC,EAAE;IACzE;EACJ;EAEA,MAAMC,OAAO,GAAG,uBAAuB;;EAEvC;AACJ;AACA;EACI,MAAMC,cAAc,GAAG,IAAIC,8BAAc,CAAC;IACtCC,EAAE,EAAEH,OAAO;IACXI,IAAI,EAAE,KAAK;IACXC,IAAI,EAAE,KAAK;IACXC,WAAW,EAAE,oDAAoD;IACjEC,IAAI,EAAE,YAAY;IAClBC,SAAS,EAAE;EACf,CAAC,CAAC;;EAEF;AACJ;AACA;EACI,MAAMC,gBAAgB,GAAG,CAAC,IAAAC,mCAA2B,GAAE,EAAE,IAAAC,mCAA2B,GAAE,CAAC;EACvF,MAAMC,eAAe,GAAGH,gBAAgB,CAACI,GAAG,CAACC,eAAe,IAAI;IAC5D,OAAO,IAAAC,0BAAY,EAAC;MAChBC,KAAK,EAAEf,cAAc,CAACgB,iBAAiB;MACvCH;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;;EAEF;AACJ;AACA;EACIrB,OAAO,CAACyB,OAAO,CAACC,QAAQ,CAAC,CAAClB,cAAc,EAAEW,eAAe,CAAC,CAAC;AAC/D,CAAC;AAAC"}
|
package/folder/folder.gql.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.folderSchema = void 0;
|
|
7
7
|
var _responses = require("@webiny/handler-graphql/responses");
|
|
8
8
|
var _GraphQLSchemaPlugin = require("@webiny/handler-graphql/plugins/GraphQLSchemaPlugin");
|
|
9
|
+
var _checkPermissions = require("../utils/checkPermissions");
|
|
9
10
|
var _resolve = require("../utils/resolve");
|
|
10
11
|
const folderSchema = new _GraphQLSchemaPlugin.GraphQLSchemaPlugin({
|
|
11
12
|
typeDefs: /* GraphQL */`
|
|
@@ -36,6 +37,7 @@ const folderSchema = new _GraphQLSchemaPlugin.GraphQLSchemaPlugin({
|
|
|
36
37
|
input FoldersListWhereInput {
|
|
37
38
|
type: String!
|
|
38
39
|
parentId: String
|
|
40
|
+
createdBy: ID
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
type FolderResponse {
|
|
@@ -54,7 +56,7 @@ const folderSchema = new _GraphQLSchemaPlugin.GraphQLSchemaPlugin({
|
|
|
54
56
|
where: FoldersListWhereInput!
|
|
55
57
|
limit: Int
|
|
56
58
|
after: String
|
|
57
|
-
sort:
|
|
59
|
+
sort: AcoSort
|
|
58
60
|
): FoldersListResponse
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -69,10 +71,14 @@ const folderSchema = new _GraphQLSchemaPlugin.GraphQLSchemaPlugin({
|
|
|
69
71
|
getFolder: async (_, {
|
|
70
72
|
id
|
|
71
73
|
}, context) => {
|
|
72
|
-
return (0, _resolve.resolve)(() =>
|
|
74
|
+
return (0, _resolve.resolve)(() => {
|
|
75
|
+
(0, _checkPermissions.checkPermissions)(context);
|
|
76
|
+
return context.aco.folder.get(id);
|
|
77
|
+
});
|
|
73
78
|
},
|
|
74
79
|
listFolders: async (_, args, context) => {
|
|
75
80
|
try {
|
|
81
|
+
await (0, _checkPermissions.checkPermissions)(context);
|
|
76
82
|
const [entries, meta] = await context.aco.folder.list(args);
|
|
77
83
|
return new _responses.ListResponse(entries, meta);
|
|
78
84
|
} catch (e) {
|
|
@@ -84,18 +90,27 @@ const folderSchema = new _GraphQLSchemaPlugin.GraphQLSchemaPlugin({
|
|
|
84
90
|
createFolder: async (_, {
|
|
85
91
|
data
|
|
86
92
|
}, context) => {
|
|
87
|
-
return (0, _resolve.resolve)(() =>
|
|
93
|
+
return (0, _resolve.resolve)(() => {
|
|
94
|
+
(0, _checkPermissions.checkPermissions)(context);
|
|
95
|
+
return context.aco.folder.create(data);
|
|
96
|
+
});
|
|
88
97
|
},
|
|
89
98
|
updateFolder: async (_, {
|
|
90
99
|
id,
|
|
91
100
|
data
|
|
92
101
|
}, context) => {
|
|
93
|
-
return (0, _resolve.resolve)(() =>
|
|
102
|
+
return (0, _resolve.resolve)(() => {
|
|
103
|
+
(0, _checkPermissions.checkPermissions)(context);
|
|
104
|
+
return context.aco.folder.update(id, data);
|
|
105
|
+
});
|
|
94
106
|
},
|
|
95
107
|
deleteFolder: async (_, {
|
|
96
108
|
id
|
|
97
109
|
}, context) => {
|
|
98
|
-
return (0, _resolve.resolve)(() =>
|
|
110
|
+
return (0, _resolve.resolve)(() => {
|
|
111
|
+
(0, _checkPermissions.checkPermissions)(context);
|
|
112
|
+
return context.aco.folder.delete(id);
|
|
113
|
+
});
|
|
99
114
|
}
|
|
100
115
|
}
|
|
101
116
|
}
|
package/folder/folder.gql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["folderSchema","GraphQLSchemaPlugin","typeDefs","resolvers","AcoQuery","getFolder","_","id","context","resolve","aco","folder","get","listFolders","args","entries","meta","list","ListResponse","e","ErrorResponse","AcoMutation","createFolder","data","create","updateFolder","update","deleteFolder","delete"],"sources":["folder.gql.ts"],"sourcesContent":["import { ErrorResponse, ListResponse } from \"@webiny/handler-graphql/responses\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/plugins/GraphQLSchemaPlugin\";\n\nimport { resolve } from \"~/utils/resolve\";\n\nimport { AcoContext } from \"~/types\";\n\nexport const folderSchema = new GraphQLSchemaPlugin<AcoContext>({\n typeDefs: /* GraphQL */ `\n type Folder {\n id: ID!\n title: String!\n slug: String!\n type: String!\n parentId: ID\n savedOn: DateTime\n createdOn: DateTime\n createdBy: AcoUser\n }\n\n input FolderCreateInput {\n title: String!\n slug: String!\n type: String!\n parentId: ID\n }\n\n input FolderUpdateInput {\n title: String\n slug: String\n parentId: ID\n }\n\n input FoldersListWhereInput {\n type: String!\n parentId: String\n }\n\n type FolderResponse {\n data: Folder\n error: AcoError\n }\n\n type FoldersListResponse {\n data: [Folder]\n error: AcoError\n }\n\n extend type AcoQuery {\n getFolder(id: ID!): FolderResponse\n listFolders(\n where: FoldersListWhereInput!\n limit: Int\n after: String\n sort:
|
|
1
|
+
{"version":3,"names":["folderSchema","GraphQLSchemaPlugin","typeDefs","resolvers","AcoQuery","getFolder","_","id","context","resolve","checkPermissions","aco","folder","get","listFolders","args","entries","meta","list","ListResponse","e","ErrorResponse","AcoMutation","createFolder","data","create","updateFolder","update","deleteFolder","delete"],"sources":["folder.gql.ts"],"sourcesContent":["import { ErrorResponse, ListResponse } from \"@webiny/handler-graphql/responses\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/plugins/GraphQLSchemaPlugin\";\n\nimport { checkPermissions } from \"~/utils/checkPermissions\";\nimport { resolve } from \"~/utils/resolve\";\n\nimport { AcoContext } from \"~/types\";\n\nexport const folderSchema = new GraphQLSchemaPlugin<AcoContext>({\n typeDefs: /* GraphQL */ `\n type Folder {\n id: ID!\n title: String!\n slug: String!\n type: String!\n parentId: ID\n savedOn: DateTime\n createdOn: DateTime\n createdBy: AcoUser\n }\n\n input FolderCreateInput {\n title: String!\n slug: String!\n type: String!\n parentId: ID\n }\n\n input FolderUpdateInput {\n title: String\n slug: String\n parentId: ID\n }\n\n input FoldersListWhereInput {\n type: String!\n parentId: String\n createdBy: ID\n }\n\n type FolderResponse {\n data: Folder\n error: AcoError\n }\n\n type FoldersListResponse {\n data: [Folder]\n error: AcoError\n }\n\n extend type AcoQuery {\n getFolder(id: ID!): FolderResponse\n listFolders(\n where: FoldersListWhereInput!\n limit: Int\n after: String\n sort: AcoSort\n ): FoldersListResponse\n }\n\n extend type AcoMutation {\n createFolder(data: FolderCreateInput!): FolderResponse\n updateFolder(id: ID!, data: FolderUpdateInput!): FolderResponse\n deleteFolder(id: ID!): AcoBooleanResponse\n }\n `,\n resolvers: {\n AcoQuery: {\n getFolder: async (_, { id }, context) => {\n return resolve(() => {\n checkPermissions(context);\n return context.aco.folder.get(id);\n });\n },\n listFolders: async (_, args: any, context) => {\n try {\n await checkPermissions(context);\n const [entries, meta] = await context.aco.folder.list(args);\n return new ListResponse(entries, meta);\n } catch (e) {\n return new ErrorResponse(e);\n }\n }\n },\n AcoMutation: {\n createFolder: async (_, { data }, context) => {\n return resolve(() => {\n checkPermissions(context);\n return context.aco.folder.create(data);\n });\n },\n updateFolder: async (_, { id, data }, context) => {\n return resolve(() => {\n checkPermissions(context);\n return context.aco.folder.update(id, data);\n });\n },\n deleteFolder: async (_, { id }, context) => {\n return resolve(() => {\n checkPermissions(context);\n return context.aco.folder.delete(id);\n });\n }\n }\n }\n});\n"],"mappings":";;;;;;AAAA;AACA;AAEA;AACA;AAIO,MAAMA,YAAY,GAAG,IAAIC,wCAAmB,CAAa;EAC5DC,QAAQ,EAAE,aAAe;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;EACDC,SAAS,EAAE;IACPC,QAAQ,EAAE;MACNC,SAAS,EAAE,OAAOC,CAAC,EAAE;QAAEC;MAAG,CAAC,EAAEC,OAAO,KAAK;QACrC,OAAO,IAAAC,gBAAO,EAAC,MAAM;UACjB,IAAAC,kCAAgB,EAACF,OAAO,CAAC;UACzB,OAAOA,OAAO,CAACG,GAAG,CAACC,MAAM,CAACC,GAAG,CAACN,EAAE,CAAC;QACrC,CAAC,CAAC;MACN,CAAC;MACDO,WAAW,EAAE,OAAOR,CAAC,EAAES,IAAS,EAAEP,OAAO,KAAK;QAC1C,IAAI;UACA,MAAM,IAAAE,kCAAgB,EAACF,OAAO,CAAC;UAC/B,MAAM,CAACQ,OAAO,EAAEC,IAAI,CAAC,GAAG,MAAMT,OAAO,CAACG,GAAG,CAACC,MAAM,CAACM,IAAI,CAACH,IAAI,CAAC;UAC3D,OAAO,IAAII,uBAAY,CAACH,OAAO,EAAEC,IAAI,CAAC;QAC1C,CAAC,CAAC,OAAOG,CAAC,EAAE;UACR,OAAO,IAAIC,wBAAa,CAACD,CAAC,CAAC;QAC/B;MACJ;IACJ,CAAC;IACDE,WAAW,EAAE;MACTC,YAAY,EAAE,OAAOjB,CAAC,EAAE;QAAEkB;MAAK,CAAC,EAAEhB,OAAO,KAAK;QAC1C,OAAO,IAAAC,gBAAO,EAAC,MAAM;UACjB,IAAAC,kCAAgB,EAACF,OAAO,CAAC;UACzB,OAAOA,OAAO,CAACG,GAAG,CAACC,MAAM,CAACa,MAAM,CAACD,IAAI,CAAC;QAC1C,CAAC,CAAC;MACN,CAAC;MACDE,YAAY,EAAE,OAAOpB,CAAC,EAAE;QAAEC,EAAE;QAAEiB;MAAK,CAAC,EAAEhB,OAAO,KAAK;QAC9C,OAAO,IAAAC,gBAAO,EAAC,MAAM;UACjB,IAAAC,kCAAgB,EAACF,OAAO,CAAC;UACzB,OAAOA,OAAO,CAACG,GAAG,CAACC,MAAM,CAACe,MAAM,CAACpB,EAAE,EAAEiB,IAAI,CAAC;QAC9C,CAAC,CAAC;MACN,CAAC;MACDI,YAAY,EAAE,OAAOtB,CAAC,EAAE;QAAEC;MAAG,CAAC,EAAEC,OAAO,KAAK;QACxC,OAAO,IAAAC,gBAAO,EAAC,MAAM;UACjB,IAAAC,kCAAgB,EAACF,OAAO,CAAC;UACzB,OAAOA,OAAO,CAACG,GAAG,CAACC,MAAM,CAACiB,MAAM,CAACtB,EAAE,CAAC;QACxC,CAAC,CAAC;MACN;IACJ;EACJ;AACJ,CAAC,CAAC;AAAC"}
|
package/folder/folder.model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare type FolderModelDefinition =
|
|
3
|
-
export declare const FOLDER_MODEL_ID = "
|
|
1
|
+
import { CmsPrivateModelFull } from "@webiny/api-headless-cms";
|
|
2
|
+
export declare type FolderModelDefinition = Omit<CmsPrivateModelFull, "noValidate" | "group">;
|
|
3
|
+
export declare const FOLDER_MODEL_ID = "acoFolder";
|
|
4
4
|
export declare const createFolderModelDefinition: () => FolderModelDefinition;
|
package/folder/folder.model.js
CHANGED
|
@@ -8,7 +8,6 @@ var _createModelField = require("../utils/createModelField");
|
|
|
8
8
|
const titleField = () => (0, _createModelField.createModelField)({
|
|
9
9
|
label: "Title",
|
|
10
10
|
type: "text",
|
|
11
|
-
parent: "folder",
|
|
12
11
|
validation: [{
|
|
13
12
|
name: "required",
|
|
14
13
|
message: "Value is required."
|
|
@@ -23,7 +22,6 @@ const titleField = () => (0, _createModelField.createModelField)({
|
|
|
23
22
|
const slugField = () => (0, _createModelField.createModelField)({
|
|
24
23
|
label: "Slug",
|
|
25
24
|
type: "text",
|
|
26
|
-
parent: "folder",
|
|
27
25
|
validation: [{
|
|
28
26
|
name: "required",
|
|
29
27
|
message: "Value is required."
|
|
@@ -52,7 +50,6 @@ const slugField = () => (0, _createModelField.createModelField)({
|
|
|
52
50
|
const typeField = () => (0, _createModelField.createModelField)({
|
|
53
51
|
label: "Type",
|
|
54
52
|
type: "text",
|
|
55
|
-
parent: "folder",
|
|
56
53
|
validation: [{
|
|
57
54
|
name: "required",
|
|
58
55
|
message: "Value is required."
|
|
@@ -60,17 +57,16 @@ const typeField = () => (0, _createModelField.createModelField)({
|
|
|
60
57
|
});
|
|
61
58
|
const parentIdField = () => (0, _createModelField.createModelField)({
|
|
62
59
|
label: "Parent Id",
|
|
63
|
-
type: "text"
|
|
64
|
-
parent: "folder"
|
|
60
|
+
type: "text"
|
|
65
61
|
});
|
|
66
|
-
const FOLDER_MODEL_ID = "
|
|
62
|
+
const FOLDER_MODEL_ID = "acoFolder";
|
|
67
63
|
exports.FOLDER_MODEL_ID = FOLDER_MODEL_ID;
|
|
68
64
|
const createFolderModelDefinition = () => {
|
|
69
65
|
return {
|
|
70
66
|
name: "ACO - Folder",
|
|
71
67
|
modelId: FOLDER_MODEL_ID,
|
|
72
68
|
titleFieldId: "title",
|
|
73
|
-
layout: [["
|
|
69
|
+
layout: [["title"], ["slug"], ["type"], ["parentId"]],
|
|
74
70
|
fields: [titleField(), slugField(), typeField(), parentIdField()],
|
|
75
71
|
description: "ACO - Folder content model",
|
|
76
72
|
isPrivate: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["titleField","createModelField","label","type","
|
|
1
|
+
{"version":3,"names":["titleField","createModelField","label","type","validation","name","message","settings","value","slugField","preset","regex","flags","typeField","parentIdField","FOLDER_MODEL_ID","createFolderModelDefinition","modelId","titleFieldId","layout","fields","description","isPrivate"],"sources":["folder.model.ts"],"sourcesContent":["import { createModelField } from \"~/utils/createModelField\";\nimport { CmsPrivateModelFull } from \"@webiny/api-headless-cms\";\n\nexport type FolderModelDefinition = Omit<CmsPrivateModelFull, \"noValidate\" | \"group\">;\n\nconst titleField = () =>\n createModelField({\n label: \"Title\",\n type: \"text\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n },\n {\n name: \"minLength\",\n settings: {\n value: \"3\"\n },\n message: \"Value is too short.\"\n }\n ]\n });\n\nconst slugField = () =>\n createModelField({\n label: \"Slug\",\n type: \"text\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n },\n {\n name: \"minLength\",\n settings: {\n value: \"3\"\n },\n message: \"Value is too short.\"\n },\n {\n name: \"maxLength\",\n settings: {\n value: \"100\"\n },\n message: \"Value is too long.\"\n },\n {\n name: \"pattern\",\n settings: {\n preset: \"custom\",\n regex: \"^[a-z0-9]+(-[a-z0-9]+)*$\",\n flags: \"g\"\n },\n message: \"Value must consist of only 'a-z', '0-9' and '-'.\"\n }\n ]\n });\n\nconst typeField = () =>\n createModelField({\n label: \"Type\",\n type: \"text\",\n validation: [\n {\n name: \"required\",\n message: \"Value is required.\"\n }\n ]\n });\n\nconst parentIdField = () =>\n createModelField({\n label: \"Parent Id\",\n type: \"text\"\n });\n\nexport const FOLDER_MODEL_ID = \"acoFolder\";\n\nexport const createFolderModelDefinition = (): FolderModelDefinition => {\n return {\n name: \"ACO - Folder\",\n modelId: FOLDER_MODEL_ID,\n titleFieldId: \"title\",\n layout: [[\"title\"], [\"slug\"], [\"type\"], [\"parentId\"]],\n fields: [titleField(), slugField(), typeField(), parentIdField()],\n description: \"ACO - Folder content model\",\n isPrivate: true\n };\n};\n"],"mappings":";;;;;;AAAA;AAKA,MAAMA,UAAU,GAAG,MACf,IAAAC,kCAAgB,EAAC;EACbC,KAAK,EAAE,OAAO;EACdC,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,CACR;IACIC,IAAI,EAAE,UAAU;IAChBC,OAAO,EAAE;EACb,CAAC,EACD;IACID,IAAI,EAAE,WAAW;IACjBE,QAAQ,EAAE;MACNC,KAAK,EAAE;IACX,CAAC;IACDF,OAAO,EAAE;EACb,CAAC;AAET,CAAC,CAAC;AAEN,MAAMG,SAAS,GAAG,MACd,IAAAR,kCAAgB,EAAC;EACbC,KAAK,EAAE,MAAM;EACbC,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,CACR;IACIC,IAAI,EAAE,UAAU;IAChBC,OAAO,EAAE;EACb,CAAC,EACD;IACID,IAAI,EAAE,WAAW;IACjBE,QAAQ,EAAE;MACNC,KAAK,EAAE;IACX,CAAC;IACDF,OAAO,EAAE;EACb,CAAC,EACD;IACID,IAAI,EAAE,WAAW;IACjBE,QAAQ,EAAE;MACNC,KAAK,EAAE;IACX,CAAC;IACDF,OAAO,EAAE;EACb,CAAC,EACD;IACID,IAAI,EAAE,SAAS;IACfE,QAAQ,EAAE;MACNG,MAAM,EAAE,QAAQ;MAChBC,KAAK,EAAE,0BAA0B;MACjCC,KAAK,EAAE;IACX,CAAC;IACDN,OAAO,EAAE;EACb,CAAC;AAET,CAAC,CAAC;AAEN,MAAMO,SAAS,GAAG,MACd,IAAAZ,kCAAgB,EAAC;EACbC,KAAK,EAAE,MAAM;EACbC,IAAI,EAAE,MAAM;EACZC,UAAU,EAAE,CACR;IACIC,IAAI,EAAE,UAAU;IAChBC,OAAO,EAAE;EACb,CAAC;AAET,CAAC,CAAC;AAEN,MAAMQ,aAAa,GAAG,MAClB,IAAAb,kCAAgB,EAAC;EACbC,KAAK,EAAE,WAAW;EAClBC,IAAI,EAAE;AACV,CAAC,CAAC;AAEC,MAAMY,eAAe,GAAG,WAAW;AAAC;AAEpC,MAAMC,2BAA2B,GAAG,MAA6B;EACpE,OAAO;IACHX,IAAI,EAAE,cAAc;IACpBY,OAAO,EAAEF,eAAe;IACxBG,YAAY,EAAE,OAAO;IACrBC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;IACrDC,MAAM,EAAE,CAACpB,UAAU,EAAE,EAAES,SAAS,EAAE,EAAEI,SAAS,EAAE,EAAEC,aAAa,EAAE,CAAC;IACjEO,WAAW,EAAE,4BAA4B;IACzCC,SAAS,EAAE;EACf,CAAC;AACL,CAAC;AAAC"}
|
package/folder/folder.so.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
1
|
import { CreateAcoStorageOperationsParams } from "../createAcoStorageOperations";
|
|
3
|
-
import { AcoFolderStorageOperations
|
|
4
|
-
interface AcoFolderStorageOperations extends BaseAcoFolderStorageOperations {
|
|
5
|
-
getFolderModel(): Promise<CmsModel>;
|
|
6
|
-
}
|
|
2
|
+
import { AcoFolderStorageOperations } from "./folder.types";
|
|
7
3
|
export declare const createFolderOperations: (params: CreateAcoStorageOperationsParams) => AcoFolderStorageOperations;
|
|
8
|
-
export {};
|
package/folder/folder.so.js
CHANGED
|
@@ -9,147 +9,142 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
|
|
|
9
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
10
|
var _folder = require("./folder.model");
|
|
11
11
|
var _createAcoStorageOperations = require("../createAcoStorageOperations");
|
|
12
|
+
var _createListSort = require("../utils/createListSort");
|
|
13
|
+
var _createOperationsWrapper = require("../utils/createOperationsWrapper");
|
|
12
14
|
var _getFieldValues = require("../utils/getFieldValues");
|
|
13
15
|
const createFolderOperations = params => {
|
|
14
16
|
const {
|
|
15
|
-
cms
|
|
16
|
-
security
|
|
17
|
+
cms
|
|
17
18
|
} = params;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
return model;
|
|
26
|
-
};
|
|
27
|
-
const getFolder = async ({
|
|
19
|
+
const {
|
|
20
|
+
withModel
|
|
21
|
+
} = (0, _createOperationsWrapper.createOperationsWrapper)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
22
|
+
modelName: _folder.FOLDER_MODEL_ID
|
|
23
|
+
}));
|
|
24
|
+
const getFolder = ({
|
|
28
25
|
id,
|
|
29
26
|
slug,
|
|
30
27
|
type,
|
|
31
28
|
parentId
|
|
32
29
|
}) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
return withModel(async model => {
|
|
31
|
+
let entry;
|
|
32
|
+
if (id) {
|
|
33
|
+
entry = await cms.getEntryById(model, id);
|
|
34
|
+
} else if (slug && type) {
|
|
35
|
+
entry = await cms.getEntry(model, {
|
|
36
|
+
where: {
|
|
37
|
+
slug,
|
|
38
|
+
type,
|
|
39
|
+
parentId,
|
|
40
|
+
latest: true
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!entry) {
|
|
45
|
+
throw new _error.default("Could not load folder.", "GET_FOLDER_ERROR", {
|
|
46
|
+
id,
|
|
41
47
|
slug,
|
|
42
48
|
type,
|
|
43
|
-
parentId
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
if (!entry) {
|
|
49
|
-
throw new _error.default("Could not load folder.", "GET_FOLDER_ERROR", {
|
|
50
|
-
id,
|
|
51
|
-
slug,
|
|
52
|
-
type,
|
|
53
|
-
parentId
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
security.enableAuthorization();
|
|
57
|
-
return (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields);
|
|
49
|
+
parentId
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return (0, _getFieldValues.getFolderFieldValues)(entry, _createAcoStorageOperations.baseFields);
|
|
53
|
+
});
|
|
58
54
|
};
|
|
59
|
-
const checkExistingFolder =
|
|
55
|
+
const checkExistingFolder = ({
|
|
60
56
|
id,
|
|
61
57
|
params
|
|
62
58
|
}) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const {
|
|
66
|
-
type,
|
|
67
|
-
slug,
|
|
68
|
-
parentId
|
|
69
|
-
} = params;
|
|
70
|
-
const [existings] = await cms.listLatestEntries(model, {
|
|
71
|
-
where: {
|
|
59
|
+
return withModel(async model => {
|
|
60
|
+
const {
|
|
72
61
|
type,
|
|
73
62
|
slug,
|
|
74
|
-
parentId
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
63
|
+
parentId
|
|
64
|
+
} = params;
|
|
65
|
+
const [existings] = await cms.listLatestEntries(model, {
|
|
66
|
+
where: {
|
|
67
|
+
type,
|
|
68
|
+
slug,
|
|
69
|
+
parentId,
|
|
70
|
+
id_not: id
|
|
71
|
+
},
|
|
72
|
+
limit: 1
|
|
83
73
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
74
|
+
if (existings.length > 0) {
|
|
75
|
+
throw new _error.default(`Folder with slug "${slug}" already exists at this level.`, "FOLDER_ALREADY_EXISTS", {
|
|
76
|
+
id,
|
|
77
|
+
params
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
});
|
|
87
82
|
};
|
|
88
83
|
return {
|
|
89
|
-
getFolderModel,
|
|
90
84
|
getFolder,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
listFolders(params) {
|
|
86
|
+
return withModel(async model => {
|
|
87
|
+
const {
|
|
88
|
+
sort,
|
|
89
|
+
where
|
|
90
|
+
} = params;
|
|
91
|
+
const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
92
|
+
sort: (0, _createListSort.createListSort)(sort),
|
|
93
|
+
where: (0, _objectSpread2.default)({}, where || {})
|
|
94
|
+
}));
|
|
95
|
+
return [entries.map(entry => (0, _getFieldValues.getFolderFieldValues)(entry, _createAcoStorageOperations.baseFields)), meta];
|
|
96
|
+
});
|
|
99
97
|
},
|
|
100
|
-
|
|
98
|
+
createFolder({
|
|
101
99
|
data
|
|
102
100
|
}) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
101
|
+
return withModel(async model => {
|
|
102
|
+
await checkExistingFolder({
|
|
103
|
+
params: {
|
|
104
|
+
type: data.type,
|
|
105
|
+
slug: data.slug,
|
|
106
|
+
parentId: data.parentId
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const entry = await cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
|
|
110
|
+
parentId: data.parentId || null
|
|
111
|
+
}));
|
|
112
|
+
return (0, _getFieldValues.getFolderFieldValues)(entry, _createAcoStorageOperations.baseFields);
|
|
111
113
|
});
|
|
112
|
-
const entry = await cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
|
|
113
|
-
parentId: data.parentId || null
|
|
114
|
-
}));
|
|
115
|
-
security.enableAuthorization();
|
|
116
|
-
return (0, _getFieldValues.getFieldValues)(entry, _createAcoStorageOperations.baseFields);
|
|
117
114
|
},
|
|
118
|
-
|
|
115
|
+
updateFolder({
|
|
119
116
|
id,
|
|
120
117
|
data
|
|
121
118
|
}) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
});
|
|
119
|
+
return withModel(async model => {
|
|
120
|
+
const {
|
|
121
|
+
slug,
|
|
122
|
+
parentId
|
|
123
|
+
} = data;
|
|
124
|
+
const original = await getFolder({
|
|
125
|
+
id
|
|
126
|
+
});
|
|
127
|
+
await checkExistingFolder({
|
|
128
|
+
id,
|
|
129
|
+
params: {
|
|
130
|
+
type: original.type,
|
|
131
|
+
slug: slug || original.slug,
|
|
132
|
+
parentId: parentId !== undefined ? parentId : original.parentId // parentId can be `null`
|
|
133
|
+
}
|
|
134
|
+
});
|
|
139
135
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
const input = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), data);
|
|
137
|
+
const entry = await cms.updateEntry(model, id, input);
|
|
138
|
+
return (0, _getFieldValues.getFolderFieldValues)(entry, _createAcoStorageOperations.baseFields);
|
|
139
|
+
});
|
|
144
140
|
},
|
|
145
|
-
|
|
141
|
+
deleteFolder({
|
|
146
142
|
id
|
|
147
143
|
}) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return true;
|
|
144
|
+
return withModel(async model => {
|
|
145
|
+
await cms.deleteEntry(model, id);
|
|
146
|
+
return true;
|
|
147
|
+
});
|
|
153
148
|
}
|
|
154
149
|
};
|
|
155
150
|
};
|