Skip to content

Commit

Permalink
fix eslint and ts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Feb 4, 2025
1 parent 76bf90c commit ebd8e58
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
5 changes: 2 additions & 3 deletions app/api/entities/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,11 @@ const validateWritePermissions = (ids, entitiesToUpdate) => {
}
};

const withDocuments = async (entities, documentsFullText, options = {}) => {
const withDocuments = async (entities, documentsFullText) => {
const sharedIds = entities.map(entity => entity.sharedId);
const allFiles = await files.get(
{ entity: { $in: sharedIds } },
documentsFullText ? '+fullText ' : ' ',
options
documentsFullText ? '+fullText ' : ' '
);
const idFileMap = new Map();
allFiles.forEach(file => {
Expand Down
6 changes: 3 additions & 3 deletions app/api/entities/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ export default app => {
try {
const result = await withTransaction(async ({ abort }) => {
const entityToSave = req.body.entity ? JSON.parse(req.body.entity) : req.body;
const result = await saveEntity(entityToSave, {
const saveResult = await saveEntity(entityToSave, {
user: req.user,
language: req.language,
socketEmiter: req.emitToSessionSocket,
files: req.files,
});
const { entity, errors } = result;
const { entity, errors } = saveResult;
await updateThesauriWithEntity(entity, req);
if (errors.length) {
await abort();
}
return req.body.entity ? result : entity;
return req.body.entity ? saveResult : entity;
});
res.json(result);
} catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions app/api/files/specs/storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ describe('storage', () => {

it('should rollback already uploaded files if an error occurs', async () => {
const files = [
{ filename: 'file1.txt', file: Readable.from(['content1']), type: 'document' },
{ filename: 'file2.txt', file: Readable.from(['content2']), type: 'document' },
{ filename: 'file3.txt', file: Readable.from(['content3']), type: 'document' },
{ filename: 'file1.txt', file: Readable.from(['content1']), type: 'document' as const },
{ filename: 'file2.txt', file: Readable.from(['content2']), type: 'document' as const },
{ filename: 'file3.txt', file: Readable.from(['content3']), type: 'document' as const },
];

const originalStoreFile = storage.storeFile.bind(storage);
Expand Down
2 changes: 1 addition & 1 deletion app/api/files/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from './filesystem';
import { S3Storage } from './S3Storage';

type FileTypes = NonNullable<FileType['type']> | 'activitylog' | 'segmentation';
export type FileTypes = NonNullable<FileType['type']> | 'activitylog' | 'segmentation';

let s3Instance: S3Storage;
const s3 = () => {
Expand Down
10 changes: 7 additions & 3 deletions app/api/odm/sessionsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { tenants } from 'api/tenants';
import { appContext } from 'api/utils/AppContext';

import { DB } from './DB';
import { FileTypes } from 'api/files/storage';

export const dbSessionContext = {
getSession() {
Expand All @@ -20,8 +21,11 @@ export const dbSessionContext = {

getFileOperations() {
return (
(appContext.get('fileOperations') as { filename: string; file: Readable; type: string }[]) ||
[]
(appContext.get('fileOperations') as {
filename: string;
file: Readable;
type: FileTypes;
}[]) || []
);
},

Expand Down Expand Up @@ -49,7 +53,7 @@ export const dbSessionContext = {
appContext.set('reindexOperations', reindexOperations);
},

registerFileOperation(args: { filename: string; file: Readable; type: string }) {
registerFileOperation(args: { filename: string; file: Readable; type: FileTypes }) {
const fileOperations = dbSessionContext.getFileOperations();
fileOperations.push(args);
appContext.set('fileOperations', fileOperations);
Expand Down
6 changes: 3 additions & 3 deletions app/api/utils/specs/withTransaction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { ClientSession } from 'mongodb';
import { model, Schema } from 'mongoose';
import { Schema } from 'mongoose';

import entities from 'api/entities';
import { instanceModel } from 'api/odm/model';
import { dbSessionContext } from 'api/odm/sessionsContext';
import { EntitySchema } from 'shared/types/entityType';

import { storage } from 'api/files';
import { Readable } from 'stream';
import { appContext } from '../AppContext';
import { elasticTesting } from '../elastic_testing';
import { getFixturesFactory } from '../fixturesFactory';
import { testingEnvironment } from '../testingEnvironment';
import { withTransaction } from '../withTransaction';
import { storage } from 'api/files';
import { Readable } from 'stream';

const factory = getFixturesFactory();

Expand Down

0 comments on commit ebd8e58

Please sign in to comment.