Skip to content

Commit d005a0e

Browse files
fix patch files
1 parent 8b6247e commit d005a0e

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

src/api/catalog/validators/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const fileSchema = Joi.object({
2121
original_mimetype: Joi.string().optional(),
2222
mimetype: Joi.string().optional(),
2323
signature: Joi.string().required(),
24-
size: Joi.number().required()
24+
size: Joi.number().allow(null).optional()
2525
});
2626

2727
interface ValidateSchemaProps {
@@ -31,7 +31,7 @@ interface ValidateSchemaProps {
3131

3232
interface ValidationErrorDetail {
3333
message: string;
34-
path: (string | number)[];
34+
path: ( string | number )[];
3535
type: string;
3636
context?: {
3737
key?: string;

src/api/controllers/files.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ export const patchAssets = async (req: Request, res: Response) => {
8888
}
8989
const fileInfo = generateFileInfo(file);
9090
const version = req.files ? file.catalogItem.version + 1 : file.catalogItem.version;
91-
const updatedItem = await updateCatalogItem(file.uuid, {
91+
const updatedItem = await updateCatalogItem(file.uuid ?? file.catalogItem.uuid, {
9292
...file.catalogItem,
9393
...file.fileInfo,
9494
...fileInfo,
9595
version,
9696
...(signature && { signature }),
97-
...(file && { size: file.size })
97+
...(file?.size && { size: file.size })
9898
});
9999
if (updatedItem.datum) {
100100
return { data: [...data, updatedItem.datum], errors };

src/api/middleware/validators/multipleFilesValidators.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,8 @@ export const validatorFilesBody = async (req: Request, res: Response, next: Next
115115
const { validFiles, invalidFiles } = await validFilesFromLocal.reduce(
116116
async (accumulator, file) => {
117117
const { validFiles, invalidFiles } = await accumulator;
118-
const uniqueName = !file.uuid && generateUniqueName(file, req.body, namespace, toWebp);
119-
const itemFound = await findFileInCatalog(file.uuid ? file.uuid : uniqueName, file.uuid ?
120-
'uuid' :
121-
'unique_name');
122-
if (itemFound && req.method === 'POST') {
118+
119+
if (file.catalogItem && req.method === 'POST') {
123120
return {
124121
validFiles,
125122
invalidFiles: [
@@ -149,12 +146,11 @@ export const validatorFilesBody = async (req: Request, res: Response, next: Next
149146
...validFiles,
150147
{
151148
...file,
152-
uniqueName: itemFound ?
153-
itemFound.unique_name :
149+
uniqueName: file.catalogItem ?
150+
file.catalogItem.unique_name :
154151
generateUniqueName(file, req.body, namespace, toWebp),
155152
fileInfo,
156-
toWebp,
157-
catalogItem: itemFound
153+
toWebp
158154
}
159155
],
160156
invalidFiles
@@ -174,6 +170,7 @@ export const validatorFilesBody = async (req: Request, res: Response, next: Next
174170
next();
175171
};
176172

173+
177174
const _checkFilesInCatalog = async (files: any[], invalidFilesFromNamespace) => {
178175
return await files.reduce(
179176
async (accumulator, file) => {

src/api/middleware/validators/oneFileValidators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const generateFileInfo = (body, method = 'PATCH') => {
113113
const fileInfo = {};
114114
for (let key of bodyKeys) {
115115
if (keysAllowed.includes(key)) {
116-
fileInfo[key] = body[key];
116+
fileInfo[key] = body.changes ? body.changes[key] : body[key];
117117
}
118118
}
119119
return fileInfo;

src/api/props/catalog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface FileProps {
1515
original_mimetype?: string;
1616
mimetype?: string;
1717
signature?: string;
18-
size?: number | string;
18+
size?: number | string ;
1919
}
2020

2121
export interface ICatalogResponse {

0 commit comments

Comments
 (0)