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',
])
@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({
tokenId,
user: req['user'],

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

@ -61,7 +61,10 @@ export class OrgTokensController {
// allowedRoles: [OrgUserRoles.SUPER],
blockApiTokenAccess: true,
})
async apiTokenDelete(@Req() req: NcRequest, @Param('tokenId') tokenId: string) {
async apiTokenDelete(
@Req() req: NcRequest,
@Param('tokenId') tokenId: string,
) {
await this.orgTokensService.apiTokenDelete({
tokenId,
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);
}
protected static encryptConfigIfRequired(obj: Record<string, unknown>) {
obj.config = encryptPropIfRequired({ data: obj });
obj.is_encrypted = isEncryptionRequired();
}
public static async createIntegration(
integration: IntegrationType & {
workspaceId?: string;
@ -63,11 +68,7 @@ export default class Integration implements IntegrationType {
'is_encrypted',
]);
insertObj.config = encryptPropIfRequired({
data: insertObj,
});
insertObj.is_encrypted = isEncryptionRequired();
this.encryptConfigIfRequired(insertObj);
if ('meta' in insertObj) {
insertObj.meta = stringifyMetaProp(insertObj);
@ -138,6 +139,8 @@ export default class Integration implements IntegrationType {
data: updateObj,
});
updateObj.is_encrypted = isEncryptionRequired();
this.encryptConfigIfRequired(updateObj);
}
// 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);
}
protected static encryptConfigIfRequired(obj: Record<string, unknown>) {
obj.config = encryptPropIfRequired({ data: obj });
obj.is_encrypted = isEncryptionRequired();
}
public static async createBase(
context: NcContext,
source: SourceType & {
@ -91,11 +96,7 @@ export default class Source implements SourceType {
'is_encrypted',
]);
insertObj.config = encryptPropIfRequired({
data: insertObj,
});
insertObj.is_encrypted = isEncryptionRequired();
this.encryptConfigIfRequired(insertObj);
if ('meta' in insertObj) {
insertObj.meta = stringifyMetaProp(insertObj);
@ -158,10 +159,7 @@ export default class Source implements SourceType {
]);
if (updateObj.config) {
updateObj.config = encryptPropIfRequired({
data: updateObj,
});
updateObj.is_encrypted = isEncryptionRequired();
this.encryptConfigIfRequired(updateObj);
}
// type property is undefined even if not provided

Loading…
Cancel
Save