add view routes
This commit is contained in:
38
src/view/view.service.ts
Normal file
38
src/view/view.service.ts
Normal 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 });
|
||||
}
|
||||
Reference in New Issue
Block a user