Browse Source

refactor: avoid duplicate code block by moving logic to a method

pull/9499/head
Pranav C 2 months ago
parent
commit
3216b04517
  1. 5
      packages/nocodb/src/controllers/api-tokens.controller.ts
  2. 5
      packages/nocodb/src/controllers/org-tokens.controller.ts
  3. 13
      packages/nocodb/src/models/Integration.ts
  4. 16
      packages/nocodb/src/models/Source.ts

5
packages/nocodb/src/controllers/api-tokens.controller.ts

@ -51,7 +51,10 @@ export class ApiTokensController {
'/api/v2/meta/bases/:baseId/api-tokens/:tokenId', '/api/v2/meta/bases/:baseId/api-tokens/:tokenId',
]) ])
@Acl('baseApiTokenDelete') @Acl('baseApiTokenDelete')
async apiTokenDelete(@Req() req: NcRequest, @Param('tokenId') tokenId: string) { async apiTokenDelete(
@Req() req: NcRequest,
@Param('tokenId') tokenId: string,
) {
return await this.apiTokensService.apiTokenDelete({ return await this.apiTokensService.apiTokenDelete({
tokenId, tokenId,
user: req['user'], user: req['user'],

5
packages/nocodb/src/controllers/org-tokens.controller.ts

@ -61,7 +61,10 @@ export class OrgTokensController {
// allowedRoles: [OrgUserRoles.SUPER], // allowedRoles: [OrgUserRoles.SUPER],
blockApiTokenAccess: true, blockApiTokenAccess: true,
}) })
async apiTokenDelete(@Req() req: NcRequest, @Param('tokenId') tokenId: string) { async apiTokenDelete(
@Req() req: NcRequest,
@Param('tokenId') tokenId: string,
) {
await this.orgTokensService.apiTokenDelete({ await this.orgTokensService.apiTokenDelete({
tokenId, tokenId,
user: req['user'], user: req['user'],

13
packages/nocodb/src/models/Integration.ts

@ -41,6 +41,11 @@ export default class Integration implements IntegrationType {
return integration && new Integration(integration); return integration && new Integration(integration);
} }
protected static encryptConfigIfRequired(obj: Record<string, unknown>) {
obj.config = encryptPropIfRequired({ data: obj });
obj.is_encrypted = isEncryptionRequired();
}
public static async createIntegration( public static async createIntegration(
integration: IntegrationType & { integration: IntegrationType & {
workspaceId?: string; workspaceId?: string;
@ -63,11 +68,7 @@ export default class Integration implements IntegrationType {
'is_encrypted', 'is_encrypted',
]); ]);
insertObj.config = encryptPropIfRequired({ this.encryptConfigIfRequired(insertObj);
data: insertObj,
});
insertObj.is_encrypted = isEncryptionRequired();
if ('meta' in insertObj) { if ('meta' in insertObj) {
insertObj.meta = stringifyMetaProp(insertObj); insertObj.meta = stringifyMetaProp(insertObj);
@ -138,6 +139,8 @@ export default class Integration implements IntegrationType {
data: updateObj, data: updateObj,
}); });
updateObj.is_encrypted = isEncryptionRequired(); updateObj.is_encrypted = isEncryptionRequired();
this.encryptConfigIfRequired(updateObj);
} }
// type property is undefined even if not provided // type property is undefined even if not provided

16
packages/nocodb/src/models/Source.ts

@ -62,6 +62,11 @@ export default class Source implements SourceType {
return source && new Source(source); return source && new Source(source);
} }
protected static encryptConfigIfRequired(obj: Record<string, unknown>) {
obj.config = encryptPropIfRequired({ data: obj });
obj.is_encrypted = isEncryptionRequired();
}
public static async createBase( public static async createBase(
context: NcContext, context: NcContext,
source: SourceType & { source: SourceType & {
@ -91,11 +96,7 @@ export default class Source implements SourceType {
'is_encrypted', 'is_encrypted',
]); ]);
insertObj.config = encryptPropIfRequired({ this.encryptConfigIfRequired(insertObj);
data: insertObj,
});
insertObj.is_encrypted = isEncryptionRequired();
if ('meta' in insertObj) { if ('meta' in insertObj) {
insertObj.meta = stringifyMetaProp(insertObj); insertObj.meta = stringifyMetaProp(insertObj);
@ -158,10 +159,7 @@ export default class Source implements SourceType {
]); ]);
if (updateObj.config) { if (updateObj.config) {
updateObj.config = encryptPropIfRequired({ this.encryptConfigIfRequired(updateObj);
data: updateObj,
});
updateObj.is_encrypted = isEncryptionRequired();
} }
// type property is undefined even if not provided // type property is undefined even if not provided

Loading…
Cancel
Save