insomnia/packages/insomnia-app/app/models/helpers/git-repository-operations.ts
Dimitri Mitropoulos 5f4c19da35
[TypeScript] Phase 1 & 2 (#3370)
Co-authored-by: Opender Singh <opender.singh@konghq.com>
2021-05-12 18:35:00 +12:00

27 lines
874 B
TypeScript

import * as models from '../../models';
import type { GitRepository } from '../../models/git-repository';
export const createGitRepository = async (workspaceId: string, repo: Partial<GitRepository>) => {
const newRepo = await models.gitRepository.create(repo);
const meta = await models.workspaceMeta.getOrCreateByParentId(workspaceId);
await models.workspaceMeta.update(meta, {
gitRepositoryId: newRepo._id,
});
};
export const deleteGitRepository = async (repo: GitRepository) => {
const id = repo._id;
const workspaceMeta = await models.workspaceMeta.getByGitRepositoryId(id);
if (workspaceMeta) {
await models.workspaceMeta.update(workspaceMeta, {
gitRepositoryId: null,
cachedGitLastCommitTime: null,
cachedGitRepositoryBranch: null,
cachedGitLastAuthor: null,
});
}
await models.gitRepository.remove(repo);
};