Skip to content

Commit

Permalink
Merge branch 'develop' into feature/increase-angular-version
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihar committed Oct 4, 2024
2 parents 5921793 + 410caff commit 59339bd
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 14,113 deletions.
76 changes: 67 additions & 9 deletions api-gateway/src/api/service/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,9 @@ export class SchemaApi {
const schemas = await guardians.createSchema(newSchema, owner);
SchemaHelper.updatePermission(schemas, owner);

await this.cacheService.invalidate(getCacheKey([req.url], user))
const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`];

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

return SchemaUtils.toOld(schemas);
} catch (error) {
Expand Down Expand Up @@ -830,7 +832,8 @@ export class SchemaApi {
@HttpCode(HttpStatus.ACCEPTED)
async copySchemaAsync(
@AuthUser() user: IAuthUser,
@Body() body: any
@Body() body: any,
@Req() req
): Promise<TaskDTO> {
const taskManager = new TaskManager();
const guardians = new Guardians();
Expand All @@ -844,6 +847,11 @@ 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 @@ -884,7 +892,8 @@ export class SchemaApi {
async createNewSchemaAsync(
@AuthUser() user: IAuthUser,
@Param('topicId') topicId: string,
@Body() newSchema: SchemaDTO
@Body() newSchema: SchemaDTO,
@Req() req
): Promise<TaskDTO> {
const owner = new EntityOwner(user);
const guardians = new Guardians();
Expand All @@ -903,6 +912,11 @@ 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 @@ -1034,7 +1048,9 @@ export class SchemaApi {
const schemas = (await guardians.deleteSchema(schemaId, owner, true) as ISchema[]);
SchemaHelper.updatePermission(schemas, owner);

await this.cacheService.invalidate(getCacheKey([req.url], user))
const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`];

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

return SchemaUtils.toOld(schemas);
} catch (error) {
Expand Down Expand Up @@ -1420,7 +1436,8 @@ export class SchemaApi {
@AuthUser() user: IAuthUser,
@Param('topicId') topicId: string,
@Body() body: MessageSchemaDTO,
@Response() res: any
@Response() res: any,
@Req() req
): Promise<SchemaDTO[]> {
const guardians = new Guardians();
const messageId = body?.messageId;
Expand All @@ -1434,6 +1451,11 @@ 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 @@ -1485,6 +1507,7 @@ export class SchemaApi {
@AuthUser() user: IAuthUser,
@Param('topicId') topicId: string,
@Body() body: MessageSchemaDTO,
@Req() req
): Promise<TaskDTO> {
const messageId = body?.messageId;
if (!messageId) {
Expand All @@ -1500,6 +1523,11 @@ 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 @@ -1542,7 +1570,8 @@ export class SchemaApi {
@AuthUser() user: IAuthUser,
@Param('topicId') topicId: string,
@Body() zip: any,
@Response() res: any
@Response() res: any,
@Req() req
): Promise<SchemaDTO[]> {
const guardians = new Guardians();
if (!zip) {
Expand All @@ -1556,6 +1585,11 @@ 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 @@ -1599,6 +1633,7 @@ export class SchemaApi {
@AuthUser() user: IAuthUser,
@Param('topicId') topicId: string,
@Body() zip: any,
@Req() req
): Promise<TaskDTO> {
if (!zip) {
throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY)
Expand All @@ -1614,6 +1649,11 @@ 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 @@ -1788,7 +1828,9 @@ export class SchemaApi {
SchemaHelper.updateOwner(newSchema, owner);
const schema = await guardians.createSystemSchema(newSchema);

await this.cacheService.invalidate(getCacheKey([req.url], req.user))
const invalidedCacheKeys = [`${PREFIXES.SCHEMES}schema-with-sub-schemas`];

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

return SchemaUtils.toOld(schema);
} catch (error) {
Expand Down Expand Up @@ -1957,6 +1999,7 @@ export class SchemaApi {
async deleteSystemSchema(
@AuthUser() user: IAuthUser,
@Param('schemaId') schemaId: string,
@Req() req
): Promise<any> {
try {
const guardians = new Guardians();
Expand All @@ -1973,6 +2016,10 @@ export class SchemaApi {
throw new HttpException('Schema is active.', HttpStatus.UNPROCESSABLE_ENTITY);
}
await guardians.deleteSchema(schemaId, owner);

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

await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheKeys], user))
} catch (error) {
await InternalException(error, this.logger);
}
Expand Down Expand Up @@ -2246,7 +2293,8 @@ export class SchemaApi {
@AuthUser() user: IAuthUser,
@Param('topicId') topicId: string,
@Body() file: ArrayBuffer,
@Response() res: any
@Response() res: any,
@Req() req
): Promise<any> {
if (!file) {
throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY)
Expand All @@ -2259,6 +2307,11 @@ 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 @@ -2305,7 +2358,8 @@ export class SchemaApi {
@AuthUser() user: IAuthUser,
@Param('topicId') topicId: string,
@Body() file: ArrayBuffer,
@Response() res: any
@Response() res: any,
@Req() req
): Promise<any> {
if (!file) {
throw new HttpException('File in body is empty', HttpStatus.UNPROCESSABLE_ENTITY)
Expand All @@ -2320,6 +2374,10 @@ 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
4 changes: 2 additions & 2 deletions common/src/database-modules/database-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
* @param filters
* @param options
*/
public async count<T extends BaseEntity>(entityClass: new () => T, filters: FilterObject<T>, options?: FindOptions<unknown>): Promise<number> {
public async count<T extends BaseEntity>(entityClass: new () => T, filters: FilterQuery<T>, options?: FindOptions<unknown>): Promise<number> {
if (this.dryRun) {

const _filters = {
Expand Down Expand Up @@ -280,7 +280,7 @@ export class DatabaseServer extends AbstractDatabaseServer {
* @param filters
* @param options
*/
public async findAndCount<T extends BaseEntity>(entityClass: new () => T, filters: FilterObject<T> | string | ObjectId, options?: unknown): Promise<[T[], number]> {
public async findAndCount<T extends BaseEntity>(entityClass: new () => T, filters: FilterQuery<T> | string | ObjectId, options?: unknown): Promise<[T[], number]> {
return await new DataBaseHelper(entityClass).findAndCount(filters, options);
}

Expand Down
4 changes: 2 additions & 2 deletions common/src/helpers/db-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export class DataBaseHelper<T extends BaseEntity> extends AbstractDataBaseHelper
* @returns Entities and count
*/
@CreateRequestContext(() => DataBaseHelper.orm)
public async findAndCount(filters: FilterObject<T> | string | ObjectId, options?: unknown): Promise<[T[], number]> {
public async findAndCount(filters: FilterQuery<T> | string | ObjectId, options?: unknown): Promise<[T[], number]> {
return await this._em.findAndCount(this.entityClass, filters, options);
}

Expand All @@ -588,7 +588,7 @@ export class DataBaseHelper<T extends BaseEntity> extends AbstractDataBaseHelper
* @returns Count
*/
@CreateRequestContext(() => DataBaseHelper.orm)
public async count(filters?: FilterObject<T> | string | ObjectId, options?: FindOptions<unknown>): Promise<number> {
public async count(filters?: FilterQuery<T> | string | ObjectId, options?: FindOptions<unknown>): Promise<number> {
return await this._em.count(this.entityClass, filters, options);
}

Expand Down
Loading

0 comments on commit 59339bd

Please sign in to comment.