mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 08:29:55 +00:00
Minor improvements on commits code quality
This commit is contained in:
@@ -13,10 +13,10 @@ export const folderCommitDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findByFolderId = async (folderId: string, tx?: Knex): Promise<TFolderCommits[]> => {
|
||||
try {
|
||||
const docs = await (tx || db.replicaNode())<TFolderCommits>(TableName.FolderCommit)
|
||||
const docs = await (tx || db.replicaNode())(TableName.FolderCommit)
|
||||
.where({ folderId })
|
||||
.select(selectAllTableCols(TableName.FolderCommit))
|
||||
.orderBy("date", "desc");
|
||||
.orderBy("createdAt", "desc");
|
||||
return docs;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "FindByFolderId" });
|
||||
@@ -25,7 +25,7 @@ export const folderCommitDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findById = async (id: string, tx?: Knex): Promise<TFolderCommits | undefined> => {
|
||||
try {
|
||||
const doc = await (tx || db.replicaNode())<TFolderCommits>(TableName.FolderCommit)
|
||||
const doc = await (tx || db.replicaNode())(TableName.FolderCommit)
|
||||
.where({ id })
|
||||
.select(selectAllTableCols(TableName.FolderCommit))
|
||||
.first();
|
||||
@@ -37,10 +37,10 @@ export const folderCommitDALFactory = (db: TDbClient) => {
|
||||
|
||||
const findLatestCommit = async (folderId: string, tx?: Knex): Promise<TFolderCommits | undefined> => {
|
||||
try {
|
||||
const doc = await (tx || db.replicaNode())<TFolderCommits>(TableName.FolderCommit)
|
||||
const doc = await (tx || db.replicaNode())(TableName.FolderCommit)
|
||||
.where({ folderId })
|
||||
.select(selectAllTableCols(TableName.FolderCommit))
|
||||
.orderBy("date", "desc")
|
||||
.orderBy("createdAt", "desc")
|
||||
.first();
|
||||
return doc;
|
||||
} catch (error) {
|
||||
|
||||
@@ -77,18 +77,15 @@ export const folderCommitServiceFactory = ({
|
||||
},
|
||||
tx
|
||||
);
|
||||
for (const change of data.changes) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await folderCommitChangesDAL.create(
|
||||
{
|
||||
folderCommitId: newCommit.id,
|
||||
changeType: change.type,
|
||||
secretVersionId: change.secretVersionId,
|
||||
folderVersionId: change.folderVersionId
|
||||
},
|
||||
tx
|
||||
);
|
||||
}
|
||||
await folderCommitChangesDAL.insertMany(
|
||||
data.changes.map((change) => ({
|
||||
folderCommitId: newCommit.id,
|
||||
changeType: change.type,
|
||||
secretVersionId: change.secretVersionId,
|
||||
folderVersionId: change.folderVersionId
|
||||
})),
|
||||
tx
|
||||
);
|
||||
|
||||
return newCommit;
|
||||
} catch (error) {
|
||||
@@ -96,7 +93,7 @@ export const folderCommitServiceFactory = ({
|
||||
}
|
||||
};
|
||||
|
||||
// Add a change to a commit and trigger checkpoints as needed
|
||||
// Add a change to an existing commit
|
||||
const addCommitChange = async (data: TCommitChangeDTO, tx?: Knex) => {
|
||||
try {
|
||||
if (!data.secretVersionId && !data.folderVersionId) {
|
||||
|
||||
Reference in New Issue
Block a user