mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
refactor: Use string ids on Credentials, Workflows, Tags, and Executions DB entities (#5041)
This commit is contained in:
committed by
GitHub
parent
8bee04cd2a
commit
ee28213538
@@ -11,7 +11,7 @@ import { getLogger } from '@/Logger';
|
||||
import { EECredentialsController } from './credentials.controller.ee';
|
||||
import { CredentialsService } from './credentials.service';
|
||||
|
||||
import type { ICredentialsResponse } from '@/Interfaces';
|
||||
import type { ICredentialsDb } from '@/Interfaces';
|
||||
import type { CredentialRequest } from '@/requests';
|
||||
|
||||
export const credentialsController = express.Router();
|
||||
@@ -35,14 +35,8 @@ credentialsController.use('/', EECredentialsController);
|
||||
*/
|
||||
credentialsController.get(
|
||||
'/',
|
||||
ResponseHelper.send(async (req: CredentialRequest.GetAll): Promise<ICredentialsResponse[]> => {
|
||||
const credentials = await CredentialsService.getAll(req.user, { roles: ['owner'] });
|
||||
|
||||
return credentials.map((credential) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
credential.id = credential.id.toString();
|
||||
return credential as ICredentialsResponse;
|
||||
});
|
||||
ResponseHelper.send(async (req: CredentialRequest.GetAll): Promise<ICredentialsDb[]> => {
|
||||
return CredentialsService.getAll(req.user, { roles: ['owner'] });
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -69,15 +63,11 @@ credentialsController.get(
|
||||
* GET /credentials/:id
|
||||
*/
|
||||
credentialsController.get(
|
||||
'/:id',
|
||||
'/:id(\\d+)',
|
||||
ResponseHelper.send(async (req: CredentialRequest.Get) => {
|
||||
const { id: credentialId } = req.params;
|
||||
const includeDecryptedData = req.query.includeData === 'true';
|
||||
|
||||
if (Number.isNaN(Number(credentialId))) {
|
||||
throw new ResponseHelper.BadRequestError('Credential ID must be a number.');
|
||||
}
|
||||
|
||||
const sharing = await CredentialsService.getSharing(req.user, credentialId, ['credentials']);
|
||||
|
||||
if (!sharing) {
|
||||
@@ -88,11 +78,10 @@ credentialsController.get(
|
||||
|
||||
const { credentials: credential } = sharing;
|
||||
|
||||
const { id, data: _, ...rest } = credential;
|
||||
const { data: _, ...rest } = credential;
|
||||
|
||||
if (!includeDecryptedData) {
|
||||
// @TODO_TECH_DEBT: Stringify `id` with entity field transformer
|
||||
return { id: id.toString(), ...rest };
|
||||
return { ...rest };
|
||||
}
|
||||
|
||||
const key = await CredentialsService.getEncryptionKey();
|
||||
@@ -101,8 +90,7 @@ credentialsController.get(
|
||||
credential,
|
||||
);
|
||||
|
||||
// @TODO_TECH_DEBT: Stringify `id` with entity field transformer
|
||||
return { id: id.toString(), data: decryptedData, ...rest };
|
||||
return { data: decryptedData, ...rest };
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -139,15 +127,15 @@ credentialsController.post(
|
||||
|
||||
const key = await CredentialsService.getEncryptionKey();
|
||||
const encryptedData = CredentialsService.createEncryptedData(key, null, newCredential);
|
||||
const { id, ...rest } = await CredentialsService.save(newCredential, encryptedData, req.user);
|
||||
const credential = await CredentialsService.save(newCredential, encryptedData, req.user);
|
||||
|
||||
void InternalHooksManager.getInstance().onUserCreatedCredentials({
|
||||
credential_type: rest.type,
|
||||
credential_id: id.toString(),
|
||||
credential_type: credential.type,
|
||||
credential_id: credential.id,
|
||||
public_api: false,
|
||||
});
|
||||
|
||||
return { id: id.toString(), ...rest };
|
||||
return credential;
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -155,8 +143,8 @@ credentialsController.post(
|
||||
* PATCH /credentials/:id
|
||||
*/
|
||||
credentialsController.patch(
|
||||
'/:id',
|
||||
ResponseHelper.send(async (req: CredentialRequest.Update): Promise<ICredentialsResponse> => {
|
||||
'/:id(\\d+)',
|
||||
ResponseHelper.send(async (req: CredentialRequest.Update): Promise<ICredentialsDb> => {
|
||||
const { id: credentialId } = req.params;
|
||||
|
||||
const sharing = await CredentialsService.getSharing(req.user, credentialId);
|
||||
@@ -194,14 +182,11 @@ credentialsController.patch(
|
||||
}
|
||||
|
||||
// Remove the encrypted data as it is not needed in the frontend
|
||||
const { id, data: _, ...rest } = responseData;
|
||||
const { data: _, ...rest } = responseData;
|
||||
|
||||
LoggerProxy.verbose('Credential updated', { credentialId });
|
||||
|
||||
return {
|
||||
id: id.toString(),
|
||||
...rest,
|
||||
};
|
||||
return { ...rest };
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -209,7 +194,7 @@ credentialsController.patch(
|
||||
* DELETE /credentials/:id
|
||||
*/
|
||||
credentialsController.delete(
|
||||
'/:id',
|
||||
'/:id(\\d+)',
|
||||
ResponseHelper.send(async (req: CredentialRequest.Delete) => {
|
||||
const { id: credentialId } = req.params;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user