Skip to content

Commit

Permalink
fix: remove invalidation preview and xlsx
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihar committed Oct 3, 2024
1 parent 343b50c commit 560c583
Showing 1 changed file with 6 additions and 41 deletions.
47 changes: 6 additions & 41 deletions api-gateway/src/api/service/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1279,20 +1279,14 @@ export class SchemaApi {
@ApiExtraModels(MessageSchemaDTO, SchemaDTO, InternalServerErrorDTO)
@HttpCode(HttpStatus.OK)
async importFromMessagePreview(
@Body() body: MessageSchemaDTO,
@Req() req
@Body() body: MessageSchemaDTO
): Promise<SchemaDTO[]> {
const messageId = body?.messageId;
if (!messageId) {
throw new HttpException('Message ID in body is empty', HttpStatus.UNPROCESSABLE_ENTITY);
}
try {
const guardians = new Guardians();

const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`];

await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], req.user))

return await guardians.previewSchemasByMessages([messageId]);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -1335,8 +1329,7 @@ export class SchemaApi {
@HttpCode(HttpStatus.ACCEPTED)
async importFromMessagePreviewAsync(
@AuthUser() user: IAuthUser,
@Body() body: MessageSchemaDTO,
@Req() req
@Body() body: MessageSchemaDTO
): Promise<TaskDTO> {
const messageId = body?.messageId;
if (!messageId) {
Expand All @@ -1351,10 +1344,6 @@ export class SchemaApi {
await this.logger.error(error, ['API_GATEWAY']);
taskManager.addError(task.taskId, { code: 500, message: error.message });
});
const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`];

await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user))

return task;
}

Expand Down Expand Up @@ -1386,20 +1375,14 @@ export class SchemaApi {
@ApiExtraModels(SchemaDTO, InternalServerErrorDTO)
@HttpCode(HttpStatus.OK)
async importFromFilePreview(
@Body() zip: any,
@Req() req
@Body() zip: any
): Promise<SchemaDTO[]> {
if (!zip) {
throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY)
}
try {
const guardians = new Guardians();
const { schemas } = await SchemaImportExport.parseZipFile(zip);

const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`];

await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], req.user))

return await guardians.previewSchemasByFile(schemas);
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -2310,8 +2293,7 @@ export class SchemaApi {
@AuthUser() user: IAuthUser,
@Param('topicId') topicId: string,
@Body() file: ArrayBuffer,
@Response() res: any,
@Req() req
@Response() res: any
): Promise<any> {
if (!file) {
throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY)
Expand All @@ -2324,11 +2306,6 @@ export class SchemaApi {
category: SchemaCategory.POLICY
}, owner);
SchemaHelper.updatePermission(items, owner);

const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`];

await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user))

return res.status(201).header('X-Total-Count', count).send(SchemaUtils.toOld(items));
} catch (error) {
await InternalException(error, this.logger);
Expand Down Expand Up @@ -2375,8 +2352,7 @@ export class SchemaApi {
@AuthUser() user: IAuthUser,
@Param('topicId') topicId: string,
@Body() file: ArrayBuffer,
@Response() res: any,
@Req() req
@Response() res: any
): Promise<any> {
if (!file) {
throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY)
Expand All @@ -2391,11 +2367,6 @@ export class SchemaApi {
await this.logger.error(error, ['API_GATEWAY']);
taskManager.addError(task.taskId, { code: 500, message: 'Unknown error: ' + error.message });
});

const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`];

await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user))

return res.status(202).send(task);
}

Expand Down Expand Up @@ -2430,20 +2401,14 @@ export class SchemaApi {
@HttpCode(HttpStatus.OK)
async importPolicyFromXlsxPreview(
@AuthUser() user: IAuthUser,
@Body() file: ArrayBuffer,
@Req() req
@Body() file: ArrayBuffer
) {
if (!file) {
throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY)
}
try {
const guardians = new Guardians();
const owner = new EntityOwner(user);

const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`];

await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user))

return await guardians.previewSchemasByFileXlsx(owner, file);
} catch (error) {
await InternalException(error, this.logger);
Expand Down

0 comments on commit 560c583

Please sign in to comment.