only show user's views

This commit is contained in:
2025-05-01 09:45:34 +05:30
parent b741c929bf
commit 1f9970366c
2 changed files with 24 additions and 55 deletions

View File

@@ -1,13 +1,13 @@
import { FastifyReply, FastifyRequest } from "fastify";
import { CreateViewInput, UpdateViewInput } from "./view.schema";
import { FastifyReply, FastifyRequest } from 'fastify';
import { CreateViewInput, UpdateViewInput } from './view.schema';
import {
createView,
deleteView,
getView,
listViews,
updateView,
} from "./view.service";
import { PageQueryParams } from "../pagination";
} from './view.service';
import { PageQueryParams } from '../pagination';
export async function createViewHandler(
req: FastifyRequest,
@@ -29,7 +29,7 @@ export async function getViewHandler(req: FastifyRequest, res: FastifyReply) {
try {
const view = await getView(viewId, req.user.tenantId);
if (view === null)
return res.code(404).send({ error: "resource not found" });
return res.code(404).send({ error: 'resource not found' });
return res.code(200).send(view);
} catch (err) {
@@ -41,8 +41,8 @@ export async function listViewHandler(req: FastifyRequest, res: FastifyReply) {
const params = req.query as PageQueryParams;
try {
const views = await listViews(params, req.user.tenantId);
return res.code(200).send(views);
const views = await listViews(params, req.user);
return res.code(200).send({ views: views });
} catch (err) {
return err;
}
@@ -58,7 +58,7 @@ export async function updateViewHandler(
try {
const updatedView = await updateView(viewId, input, req.user.tenantId);
if (!updatedView)
return res.code(404).send({ error: "resource not found" });
return res.code(404).send({ error: 'resource not found' });
return res.code(200).send(updateView);
} catch (err) {
@@ -75,7 +75,7 @@ export async function deleteViewHandler(
try {
const deleteResult = await deleteView(viewId);
if (deleteResult.deletedCount == 0)
return res.code(404).send({ error: "resource not found" });
return res.code(404).send({ error: 'resource not found' });
return res.code(204).send();
} catch (err) {