add view routes
This commit is contained in:
64
src/view/view.schema.ts
Normal file
64
src/view/view.schema.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { buildJsonSchemas } from "fastify-zod";
|
||||
import mongoose from "mongoose";
|
||||
import { z } from "zod";
|
||||
import { pageQueryParams } from "../pagination";
|
||||
|
||||
export const viewModel = mongoose.model(
|
||||
"view",
|
||||
new mongoose.Schema({
|
||||
tenantId: String,
|
||||
pid: {
|
||||
type: String,
|
||||
unique: true,
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
collection: String,
|
||||
createdBy: {
|
||||
type: mongoose.Types.ObjectId,
|
||||
ref: "user",
|
||||
},
|
||||
hide: new mongoose.Schema({}, { strict: false, _id: false }),
|
||||
sort: new mongoose.Schema({}, { strict: false, _id: false }),
|
||||
group: new mongoose.Schema({}, { strict: false, _id: false }),
|
||||
filters: [new mongoose.Schema({}, { strict: false, _id: false })],
|
||||
match: [new mongoose.Schema({}, { strict: false, _id: false })],
|
||||
})
|
||||
);
|
||||
|
||||
export const viewFields = ["name", "collection"];
|
||||
|
||||
const createViewInput = z.object({
|
||||
name: z.string(),
|
||||
collection: z.string(),
|
||||
hide: z.record(z.string(), z.any()).optional(),
|
||||
sort: z.record(z.string(), z.any()).optional(),
|
||||
group: z.record(z.any()).optional(),
|
||||
filters: z.array(z.any()).optional(),
|
||||
match: z.array(z.any()).optional(),
|
||||
});
|
||||
|
||||
const updateViewInput = z.object({
|
||||
name: z.string().optional(),
|
||||
collection: z.string().optional(),
|
||||
hide: z.record(z.string(), z.any()).optional(),
|
||||
sort: z.record(z.string(), z.any()).optional(),
|
||||
group: z.record(z.any()).optional(),
|
||||
filters: z.array(z.any()).optional(),
|
||||
match: z.array(z.any()).optional(),
|
||||
});
|
||||
|
||||
export type CreateViewInput = z.infer<typeof createViewInput>;
|
||||
export type UpdateViewInput = z.infer<typeof updateViewInput>;
|
||||
|
||||
export const { schemas: viewSchemas, $ref: $view } = buildJsonSchemas(
|
||||
{
|
||||
createViewInput,
|
||||
updateViewInput,
|
||||
pageQueryParams,
|
||||
},
|
||||
{ $id: "view" }
|
||||
);
|
||||
Reference in New Issue
Block a user