add view routes

This commit is contained in:
2025-02-27 16:45:10 +05:30
parent 63bcc4bafd
commit 550f600a35
4 changed files with 102 additions and 0 deletions

38
src/view/view.service.ts Normal file
View File

@@ -0,0 +1,38 @@
import { AuthenticatedUser } from "../auth";
import { generateId } from "../utils/id";
import { CreateViewInput, UpdateViewInput, viewModel } from "./view.schema";
export async function createView(
input: CreateViewInput,
user: AuthenticatedUser
) {
return await viewModel.create({
tenantId: user.tenantId,
pid: generateId(),
createdBy: user.userId,
...input,
});
}
export async function getView(viewId: string, tenantId: string) {
return await viewModel.findOne({
$and: [{ pid: viewId }, { tenantId: tenantId }],
});
}
export async function listViews() {}
export async function updateView(
viewId: string,
input: UpdateViewInput,
tenantId: string
) {
return await viewModel.findOneAndUpdate(
{ $and: [{ pid: viewId }, { tenantId: tenantId }] },
{ ...input }
);
}
export async function deletView(viewId: string) {
return await viewModel.findOneAndDelete({ pid: viewId });
}