Skip to content

Commit 1538e89

Browse files
committed
fix: remove location field from file model
1 parent 8e16abd commit 1538e89

6 files changed

Lines changed: 57 additions & 6 deletions

File tree

packages/api-file-manager/src/domain/file/file.model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class FilePrivateModelImpl implements ModelFactory.Interface {
1111
const privateFiles = this.wcp.canUsePrivateFiles();
1212

1313
model.fields(fields => ({
14-
location: fields.location(),
1514
name: fields.text().label("Name").required("Value is required."),
1615
key: fields.text().label("Key").required("Value is required."),
1716
type: fields.text().label("Type").required("Value is required."),

packages/api-file-manager/src/features/file/CreateFile/CreateFileRepository.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { FileModel } from "~/domain/file/abstractions.js";
55
import type { File, FileInput } from "~/domain/file/types.js";
66
import { EntryToFileMapper } from "../shared/EntryToFileMapper.js";
77
import { FileNotAuthorizedError, FilePersistenceError } from "~/domain/file/errors.js";
8+
import { FileInputToEntryInputMapper } from "~/features/file/shared/FileInputToEntryInputMapper.js";
89

910
class CreateFileRepositoryImpl implements RepositoryAbstraction.Interface {
1011
constructor(
@@ -13,10 +14,10 @@ class CreateFileRepositoryImpl implements RepositoryAbstraction.Interface {
1314
) {}
1415

1516
async execute(data: FileInput): Promise<Result<File, RepositoryAbstraction.Error>> {
16-
const result = await this.createEntry.execute(this.fileModel, {
17-
...data,
18-
values: data
19-
});
17+
const result = await this.createEntry.execute(
18+
this.fileModel,
19+
FileInputToEntryInputMapper.toEntry(data)
20+
);
2021

2122
if (result.isFail()) {
2223
if (result.error.code === "Cms/Entry/NotAuthorized") {

packages/api-file-manager/src/features/file/shared/EntryToFileMapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class EntryToFileMapper {
1717
type: entry.values.type,
1818
meta: entry.values.meta || {},
1919
accessControl: entry.values.accessControl,
20-
location: entry.values.location || { folderId: "root" },
20+
location: { folderId: entry.location?.folderId ?? "root" },
2121
tags: entry.values.tags || [],
2222
extensions: entry.values.extensions
2323
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { CreateCmsEntryInput } from "@webiny/api-headless-cms/types";
2+
import type { FileInput } from "~/domain/file/types.js";
3+
4+
export class FileInputToEntryInputMapper {
5+
static toEntry(file: FileInput): CreateCmsEntryInput {
6+
return {
7+
id: file.id,
8+
createdOn: file.createdOn,
9+
modifiedOn: file.modifiedOn,
10+
savedOn: file.savedOn,
11+
createdBy: file.createdBy,
12+
modifiedBy: file.modifiedBy,
13+
savedBy: file.savedBy,
14+
location: file.location || { folderId: "root" },
15+
values: {
16+
name: file.name,
17+
key: file.key,
18+
size: file.size,
19+
type: file.type,
20+
meta: file.meta || {},
21+
accessControl: {
22+
type: "public"
23+
},
24+
tags: file.tags || [],
25+
extensions: file.extensions
26+
}
27+
};
28+
}
29+
}

packages/api-file-manager/src/graphql/createFilesTypeDefs.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ export const createFilesTypeDefs = (params: CreateFilesTypeDefsParams): string =
7272
});
7373

7474
return /* GraphQL */ `
75+
type FmLocation {
76+
folderId: String!
77+
}
78+
79+
input FmLocationInput {
80+
folderId: String!
81+
}
82+
83+
input FmLocationWhereInput {
84+
folderId: ID
85+
folderId_in: [ID!]
86+
folderId_not: ID
87+
folderId_not_in: [ID!]
88+
}
89+
7590
${fieldTypes.map(f => f.typeDefs).join("\n")}
7691
7792
type FmFile {
@@ -82,6 +97,7 @@ export const createFilesTypeDefs = (params: CreateFilesTypeDefsParams): string =
8297
createdBy: FmCreatedBy!
8398
modifiedBy: FmCreatedBy
8499
savedBy: FmCreatedBy!
100+
location: FmLocation!
85101
src: String
86102
${fieldTypes.map(f => f.fields).join("\n")}
87103
}
@@ -102,6 +118,7 @@ export const createFilesTypeDefs = (params: CreateFilesTypeDefsParams): string =
102118
createdBy: FmCreatedByInput
103119
modifiedBy: FmCreatedByInput
104120
savedBy: FmCreatedByInput
121+
location: FmLocationInput!
105122
${inputCreateFields.map(f => f.fields).join("\n")}
106123
}
107124
@@ -112,6 +129,7 @@ export const createFilesTypeDefs = (params: CreateFilesTypeDefsParams): string =
112129
createdBy: FmCreatedByInput
113130
modifiedBy: FmCreatedByInput
114131
savedBy: FmCreatedByInput
132+
location: FmLocationInput
115133
${inputUpdateFields.map(f => f.fields).join("\n")}
116134
}
117135
@@ -121,6 +139,7 @@ export const createFilesTypeDefs = (params: CreateFilesTypeDefsParams): string =
121139
}
122140
123141
input FmFileListWhereInput {
142+
location: FmLocationWhereInput
124143
${listFilterFieldsRender.allFiltersAsString()}
125144
AND: [FmFileListWhereInput!]
126145
OR: [FmFileListWhereInput!]

packages/app-file-manager/src/modules/FileManagerApiProvider/FileManagerApiContext/getFileGraphQLSelection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export const getFileGraphQLSelection = (model: ReturnType<typeof useFileModel>)
2222
displayName
2323
}
2424
src
25+
location {
26+
folderId
27+
}
2528
${fields}
2629
}`;
2730
};

0 commit comments

Comments
 (0)