code made pretty
This commit is contained in:
@@ -10,7 +10,7 @@ import{
|
||||
CreateCategoryInput,
|
||||
UpdateCategoryInput,
|
||||
DeleteCategoryInput,
|
||||
DeleteCategoriesByInstanceIdInput
|
||||
DeleteCategoriesByInstanceIdInput,
|
||||
} from "../validators/categoryValidator";
|
||||
|
||||
export async function createNewCategory(data: CreateCategoryInput) {
|
||||
@@ -33,7 +33,8 @@ export async function deleteExistingCategory(data: DeleteCategoryInput) {
|
||||
return await deleteCategory(data);
|
||||
}
|
||||
|
||||
export async function deleteAllCategoriesByInstance(data: DeleteCategoriesByInstanceIdInput) {
|
||||
export async function deleteAllCategoriesByInstance(
|
||||
data: DeleteCategoriesByInstanceIdInput,
|
||||
) {
|
||||
return await deleteAllCategoriesFromInstance(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ import{
|
||||
getChannelsByCategory,
|
||||
updateChannel,
|
||||
deleteChannel,
|
||||
deleteAllChannelsFromCategory
|
||||
deleteAllChannelsFromCategory,
|
||||
} from "../services/channelService";
|
||||
import {
|
||||
CreateChannelInput,
|
||||
UpdateChannelInput,
|
||||
DeleteChannelInput,
|
||||
DeleteChannelsByCategoryIdInput
|
||||
DeleteChannelsByCategoryIdInput,
|
||||
} from "../validators/channelValidator";
|
||||
|
||||
export async function createNewChannel(data: CreateChannelInput) {
|
||||
@@ -33,6 +33,8 @@ export async function deleteExistingChannel(data: DeleteChannelInput) {
|
||||
return await deleteChannel(data);
|
||||
}
|
||||
|
||||
export async function deleteAllChannelsByCategory(data: DeleteChannelsByCategoryIdInput) {
|
||||
export async function deleteAllChannelsByCategory(
|
||||
data: DeleteChannelsByCategoryIdInput,
|
||||
) {
|
||||
return await deleteAllChannelsFromCategory(data);
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
import { getMessageInformation, getMessagesBefore, sendMessageToChannel } from "../services/messageService";
|
||||
import {
|
||||
getMessageInformation,
|
||||
getMessagesBefore,
|
||||
sendMessageToChannel,
|
||||
} from "../services/messageService";
|
||||
|
||||
export async function fetchMessageData(id: string) {
|
||||
return await getMessageInformation(id);
|
||||
@@ -13,13 +17,13 @@ export async function sendMessage(
|
||||
userId: string,
|
||||
content: string,
|
||||
token: string,
|
||||
repliedMessageId: string | null
|
||||
repliedMessageId: string | null,
|
||||
) {
|
||||
return await sendMessageToChannel(
|
||||
channelId,
|
||||
userId,
|
||||
content,
|
||||
token,
|
||||
repliedMessageId
|
||||
repliedMessageId,
|
||||
);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { Hono } from "hono";
|
||||
import { describeRoute, resolver } from "hono-openapi";
|
||||
const categoryRoutes = new Hono()
|
||||
const categoryRoutes = new Hono();
|
||||
|
||||
// Create a new category
|
||||
categoryRoutes.post(
|
||||
@@ -67,8 +67,8 @@ categoryRoutes.post(
|
||||
} else {
|
||||
return c.json({ error: "Failed to create category" }, 400);
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
// Get a category by ID
|
||||
categoryRoutes.get(
|
||||
@@ -98,7 +98,7 @@ categoryRoutes.get(
|
||||
} else {
|
||||
return c.json({ error: "Category not found" }, 404);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Get all categories by instance ID
|
||||
@@ -110,13 +110,17 @@ categoryRoutes.get(
|
||||
200: {
|
||||
description: "Success getting all categories in instance",
|
||||
content: {
|
||||
"application/json": { schema: resolver(getCategoriesByInstanceIdSchema) },
|
||||
"application/json": {
|
||||
schema: resolver(getCategoriesByInstanceIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
400: {
|
||||
description: "Bad Request - Missing instance ID",
|
||||
content: {
|
||||
"application/json": { schema: resolver(getCategoriesByInstanceIdSchema) },
|
||||
"application/json": {
|
||||
schema: resolver(getCategoriesByInstanceIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -131,9 +135,12 @@ categoryRoutes.get(
|
||||
if (categoryData) {
|
||||
return c.json(categoryData);
|
||||
} else {
|
||||
return c.json({ error: "Error getting all categories from instance" }, 500);
|
||||
}
|
||||
return c.json(
|
||||
{ error: "Error getting all categories from instance" },
|
||||
500,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Update a category
|
||||
@@ -189,7 +196,7 @@ categoryRoutes.put(
|
||||
} else {
|
||||
return c.json({ error: "Failed to update category" }, 400);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Delete a specific category
|
||||
@@ -240,8 +247,8 @@ categoryRoutes.delete(
|
||||
} else {
|
||||
return c.json({ error: "Failed to delete category" }, 400);
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
// Delete all categories by instance ID
|
||||
categoryRoutes.delete(
|
||||
@@ -252,25 +259,33 @@ categoryRoutes.delete(
|
||||
200: {
|
||||
description: "Success deleting all categories in instance",
|
||||
content: {
|
||||
"application/json": { schema: resolver(deleteCategoriesByInstanceIdSchema) },
|
||||
"application/json": {
|
||||
schema: resolver(deleteCategoriesByInstanceIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
400: {
|
||||
description: "Bad Request - Invalid input data",
|
||||
content: {
|
||||
"application/json": { schema: resolver(deleteCategoriesByInstanceIdSchema)},
|
||||
"application/json": {
|
||||
schema: resolver(deleteCategoriesByInstanceIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
401: {
|
||||
description: "Unauthorized - Admin access required",
|
||||
content: {
|
||||
"application/json": { schema: resolver(deleteCategoriesByInstanceIdSchema)},
|
||||
"application/json": {
|
||||
schema: resolver(deleteCategoriesByInstanceIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
404: {
|
||||
description: "Instance id or User Id not found",
|
||||
content: {
|
||||
"application/json": { schema: resolver(deleteCategoriesByInstanceIdSchema)},
|
||||
"application/json": {
|
||||
schema: resolver(deleteCategoriesByInstanceIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -282,7 +297,10 @@ categoryRoutes.delete(
|
||||
|
||||
// Ensure the instanceId in the path matches the one in the body
|
||||
if (data.instanceId !== instanceId) {
|
||||
return c.json({ error: "Instance ID in path does not match Instance ID in body" }, 400);
|
||||
return c.json(
|
||||
{ error: "Instance ID in path does not match Instance ID in body" },
|
||||
400,
|
||||
);
|
||||
}
|
||||
|
||||
const categoryData = await deleteAllCategoriesByInstance(data);
|
||||
@@ -291,7 +309,7 @@ categoryRoutes.delete(
|
||||
} else {
|
||||
return c.json({ error: "Failed to delete categories" }, 400);
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
export { categoryRoutes };
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
updateChannelSchema,
|
||||
deleteChannelSchema,
|
||||
deleteChannelsByCategoryIdSchema,
|
||||
|
||||
CreateChannelInput,
|
||||
GetChannelInput,
|
||||
GetChannelsByCategoryIdInput,
|
||||
@@ -26,7 +25,7 @@ import { zValidator } from "@hono/zod-validator";
|
||||
import { Hono } from "hono";
|
||||
import { describeRoute, resolver } from "hono-openapi";
|
||||
|
||||
const channelRoutes = new Hono()
|
||||
const channelRoutes = new Hono();
|
||||
|
||||
// Create a new channel
|
||||
channelRoutes.post(
|
||||
@@ -69,8 +68,8 @@ channelRoutes.post(
|
||||
} else {
|
||||
return c.json({ error: "Failed to create channel" }, 400);
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
// Get a channel by ID
|
||||
channelRoutes.get(
|
||||
@@ -100,7 +99,7 @@ channelRoutes.get(
|
||||
} else {
|
||||
return c.json({ error: "Channel not found" }, 404);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Get all channels by category ID
|
||||
@@ -112,13 +111,17 @@ channelRoutes.get(
|
||||
200: {
|
||||
description: "Success getting all channels in category",
|
||||
content: {
|
||||
"application/json": { schema: resolver(getChannelsByCategoryIdSchema) },
|
||||
"application/json": {
|
||||
schema: resolver(getChannelsByCategoryIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
400: {
|
||||
description: "Bad Request - Missing category ID",
|
||||
content: {
|
||||
"application/json": { schema: resolver(getChannelsByCategoryIdSchema) },
|
||||
"application/json": {
|
||||
schema: resolver(getChannelsByCategoryIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -135,7 +138,7 @@ channelRoutes.get(
|
||||
} else {
|
||||
return c.json({ error: "Error getting channels from category" }, 500);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Update a channel
|
||||
@@ -191,7 +194,7 @@ channelRoutes.put(
|
||||
} else {
|
||||
return c.json({ error: "Failed to update channel" }, 400);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Delete a specific channel
|
||||
@@ -242,7 +245,7 @@ channelRoutes.delete(
|
||||
} else {
|
||||
return c.json({ error: "Failed to delete channel" }, 400);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Delete all channels by category ID
|
||||
@@ -254,25 +257,33 @@ channelRoutes.delete(
|
||||
200: {
|
||||
description: "Success deleting all channels in category",
|
||||
content: {
|
||||
"application/json": { schema: resolver(deleteChannelsByCategoryIdSchema) },
|
||||
"application/json": {
|
||||
schema: resolver(deleteChannelsByCategoryIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
400: {
|
||||
description: "Bad Request - Invalid input data",
|
||||
content: {
|
||||
"application/json": { schema: resolver(deleteChannelsByCategoryIdSchema)},
|
||||
"application/json": {
|
||||
schema: resolver(deleteChannelsByCategoryIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
401: {
|
||||
description: "Unauthorized - Admin access required",
|
||||
content: {
|
||||
"application/json": { schema: resolver(deleteChannelsByCategoryIdSchema)},
|
||||
"application/json": {
|
||||
schema: resolver(deleteChannelsByCategoryIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
404: {
|
||||
description: "Category id or User Id not found",
|
||||
content: {
|
||||
"application/json": { schema: resolver(deleteChannelsByCategoryIdSchema)},
|
||||
"application/json": {
|
||||
schema: resolver(deleteChannelsByCategoryIdSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -284,7 +295,10 @@ channelRoutes.delete(
|
||||
|
||||
// Ensure the categoryId in the path matches the one in the body
|
||||
if (data.categoryId !== categoryId) {
|
||||
return c.json({ error: "Category ID in path does not match Category ID in body" }, 400);
|
||||
return c.json(
|
||||
{ error: "Category ID in path does not match Category ID in body" },
|
||||
400,
|
||||
);
|
||||
}
|
||||
|
||||
const result = await deleteAllChannelsByCategory(data);
|
||||
@@ -293,7 +307,7 @@ channelRoutes.delete(
|
||||
} else {
|
||||
return c.json({ error: "Failed to delete channels" }, 400);
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
export { channelRoutes };
|
||||
@@ -1,8 +1,14 @@
|
||||
import { Hono } from "hono";
|
||||
import { describeRoute, resolver } from "hono-openapi";
|
||||
import { createInstanceRequestSchema, getAllInstancesResponseSchema } from "../validators/instanceValidator";
|
||||
import {
|
||||
createInstanceRequestSchema,
|
||||
getAllInstancesResponseSchema,
|
||||
} from "../validators/instanceValidator";
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { createInstanceReq, getAllInstancesReq } from "../controller/instanceController";
|
||||
import {
|
||||
createInstanceReq,
|
||||
getAllInstancesReq,
|
||||
} from "../controller/instanceController";
|
||||
|
||||
const instanceRoutes = new Hono();
|
||||
|
||||
@@ -14,15 +20,15 @@ instanceRoutes.post(
|
||||
200: {
|
||||
description: "Instance created",
|
||||
content: {
|
||||
"application/json": { schema: resolver(createInstanceRequestSchema) }
|
||||
"application/json": { schema: resolver(createInstanceRequestSchema) },
|
||||
},
|
||||
},
|
||||
400: {
|
||||
description: "Invalid request",
|
||||
},
|
||||
}
|
||||
},
|
||||
}),
|
||||
zValidator('json', createInstanceRequestSchema),
|
||||
zValidator("json", createInstanceRequestSchema),
|
||||
async (c) => {
|
||||
const data = await c.req.json();
|
||||
if (!data) {
|
||||
@@ -31,7 +37,7 @@ instanceRoutes.post(
|
||||
|
||||
const instance = await createInstanceReq(data);
|
||||
return c.json(instance, 201);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
instanceRoutes.get(
|
||||
@@ -42,22 +48,30 @@ instanceRoutes.get(
|
||||
200: {
|
||||
description: "List of all instances",
|
||||
content: {
|
||||
"application/json": { schema: resolver(getAllInstancesResponseSchema) }
|
||||
"application/json": {
|
||||
schema: resolver(getAllInstancesResponseSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
500: {
|
||||
description: "Server error",
|
||||
},
|
||||
}
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const instances = await getAllInstancesReq();
|
||||
if (instances.success) {
|
||||
return c.json(instances, 200);
|
||||
} else {
|
||||
return c.json({ success: false, error: instances.error || "Failed to fetch instances" }, 500);
|
||||
}
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
error: instances.error || "Failed to fetch instances",
|
||||
},
|
||||
500,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export default instanceRoutes;
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import { Hono } from "hono";
|
||||
import { describeResponse, describeRoute, resolver } from "hono-openapi";
|
||||
import { getMessageByIdSchema, getMessagesBeforeDate, sendMessageSchema } from "../validators/messageValidator";
|
||||
import {
|
||||
getMessageByIdSchema,
|
||||
getMessagesBeforeDate,
|
||||
sendMessageSchema,
|
||||
} from "../validators/messageValidator";
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { fetchMessageData, fetchMessagesBefore, sendMessage } from "../controller/messageController";
|
||||
import {
|
||||
fetchMessageData,
|
||||
fetchMessagesBefore,
|
||||
sendMessage,
|
||||
} from "../controller/messageController";
|
||||
|
||||
const messageRoutes = new Hono();
|
||||
|
||||
@@ -14,16 +22,16 @@ messageRoutes.get(
|
||||
200: {
|
||||
description: "Success getting message",
|
||||
content: {
|
||||
"application/json": { schema: resolver(getMessageByIdSchema) }
|
||||
}
|
||||
"application/json": { schema: resolver(getMessageByIdSchema) },
|
||||
},
|
||||
},
|
||||
404: {
|
||||
description: "Message id not found",
|
||||
content: {
|
||||
"application/json": { schema: resolver(getMessageByIdSchema) }
|
||||
}
|
||||
}
|
||||
}
|
||||
"application/json": { schema: resolver(getMessageByIdSchema) },
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
zValidator("param", getMessageByIdSchema),
|
||||
async (c) => {
|
||||
@@ -35,8 +43,8 @@ messageRoutes.get(
|
||||
} else {
|
||||
return c.json({ error: "Message not found" }, 404);
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
messageRoutes.get(
|
||||
"",
|
||||
@@ -46,10 +54,10 @@ messageRoutes.get(
|
||||
200: {
|
||||
description: "Success getting up to 50 messages",
|
||||
content: {
|
||||
"application/json": { schema: resolver(getMessagesBeforeDate) }
|
||||
}
|
||||
}
|
||||
}
|
||||
"application/json": { schema: resolver(getMessagesBeforeDate) },
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
zValidator("query", getMessagesBeforeDate),
|
||||
async (c) => {
|
||||
@@ -70,8 +78,8 @@ messageRoutes.get(
|
||||
} else {
|
||||
return c.json({ error: "Failed to fetch messages" }, 500);
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
messageRoutes.post(
|
||||
"",
|
||||
@@ -81,41 +89,58 @@ messageRoutes.post(
|
||||
201: {
|
||||
description: "Message sent successfully",
|
||||
content: {
|
||||
"application/json": { schema: resolver(sendMessageSchema) }
|
||||
}
|
||||
"application/json": { schema: resolver(sendMessageSchema) },
|
||||
},
|
||||
},
|
||||
401: {
|
||||
description: "Unauthorized - invalid token or user credentials",
|
||||
content: {
|
||||
"application/json": { schema: { type: "object", properties: { error: { type: "string" } } } }
|
||||
}
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: { error: { type: "string" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
500: {
|
||||
description: "Server error",
|
||||
content: {
|
||||
"application/json": { schema: { type: "object", properties: { error: { type: "string" } } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
"application/json": {
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: { error: { type: "string" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
zValidator("json", sendMessageSchema),
|
||||
async (c) => {
|
||||
const { channelId, userId, content, token, repliedMessageId } = await c.req.json();
|
||||
const { channelId, userId, content, token, repliedMessageId } =
|
||||
await c.req.json();
|
||||
|
||||
const result = await sendMessage(
|
||||
channelId,
|
||||
userId,
|
||||
content,
|
||||
token,
|
||||
repliedMessageId || null
|
||||
repliedMessageId || null,
|
||||
);
|
||||
|
||||
if (result) {
|
||||
return c.json(result, 201);
|
||||
} else {
|
||||
return c.json({ error: "Failed to send message. Check your credentials and try again." }, 401);
|
||||
return c.json(
|
||||
{
|
||||
error:
|
||||
"Failed to send message. Check your credentials and try again.",
|
||||
},
|
||||
401,
|
||||
);
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
export default messageRoutes;
|
||||
@@ -1,33 +1,30 @@
|
||||
import{
|
||||
Channel,
|
||||
Category
|
||||
} from '@prisma/client';
|
||||
import { Channel, Category } from "@prisma/client";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { getUserInformation, getUserCredentials } from './userService';
|
||||
import { getUserInformation, getUserCredentials } from "./userService";
|
||||
import {
|
||||
CreateChannelInput,
|
||||
UpdateChannelInput,
|
||||
DeleteChannelInput,
|
||||
DeleteChannelsByCategoryIdInput
|
||||
} from '../validators/channelValidator';
|
||||
DeleteChannelsByCategoryIdInput,
|
||||
} from "../validators/channelValidator";
|
||||
import {
|
||||
UpdateCategoryInput,
|
||||
DeleteCategoryInput,
|
||||
DeleteCategoriesByInstanceIdInput,
|
||||
CreateCategoryInput
|
||||
} from '../validators/categoryValidator';
|
||||
CreateCategoryInput,
|
||||
} from "../validators/categoryValidator";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
|
||||
export async function createCategory(data: CreateCategoryInput): Promise<Category | null>{
|
||||
export async function createCategory(
|
||||
data: CreateCategoryInput,
|
||||
): Promise<Category | null> {
|
||||
try {
|
||||
|
||||
//Confirm if user exists and is admin
|
||||
const requestingUser = await getUserInformation(data.requestingUserId);
|
||||
const requestingUserCredentials = await getUserCredentials(
|
||||
data.requestingUserId,
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
!requestingUser ||
|
||||
@@ -42,8 +39,8 @@ export async function createCategory(data: CreateCategoryInput): Promise<Categor
|
||||
const newCategory = await prisma.category.create({
|
||||
data: {
|
||||
name: data.name,
|
||||
position: data.position
|
||||
}
|
||||
position: data.position,
|
||||
},
|
||||
});
|
||||
|
||||
if (!newCategory) {
|
||||
@@ -54,11 +51,11 @@ export async function createCategory(data: CreateCategoryInput): Promise<Categor
|
||||
if (data.instanceId) {
|
||||
curInstance = await prisma.instance.findUnique({
|
||||
where: {
|
||||
id: data.instanceId
|
||||
id: data.instanceId,
|
||||
},
|
||||
include: {
|
||||
Category: true
|
||||
}
|
||||
Category: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!curInstance) {
|
||||
@@ -67,11 +64,11 @@ export async function createCategory(data: CreateCategoryInput): Promise<Categor
|
||||
|
||||
await prisma.category.update({
|
||||
where: {
|
||||
id: newCategory.id
|
||||
id: newCategory.id,
|
||||
},
|
||||
data: {
|
||||
instanceId: curInstance.id
|
||||
}
|
||||
instanceId: curInstance.id,
|
||||
},
|
||||
});
|
||||
|
||||
return newCategory;
|
||||
@@ -90,8 +87,8 @@ export async function getCategory(
|
||||
try {
|
||||
const category = await prisma.category.findUnique({
|
||||
where: {
|
||||
id: categoryId
|
||||
}
|
||||
id: categoryId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!category) {
|
||||
@@ -106,19 +103,19 @@ export async function getCategory(
|
||||
}
|
||||
|
||||
export async function getCategoriesByInstance(
|
||||
instanceId: string
|
||||
instanceId: string,
|
||||
): Promise<Category[] | null> {
|
||||
try {
|
||||
const categories = await prisma.category.findMany({
|
||||
where: {
|
||||
instanceId: instanceId
|
||||
instanceId: instanceId,
|
||||
},
|
||||
include: {
|
||||
Channel: true
|
||||
Channel: true,
|
||||
},
|
||||
orderBy: {
|
||||
position: 'asc'
|
||||
}
|
||||
position: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
if (!categories) {
|
||||
@@ -132,14 +129,15 @@ export async function getCategoriesByInstance(
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateCategory(data: UpdateCategoryInput): Promise<Category | null>{
|
||||
export async function updateCategory(
|
||||
data: UpdateCategoryInput,
|
||||
): Promise<Category | null> {
|
||||
try {
|
||||
|
||||
//Confirm if user exists and is admin
|
||||
const requestingUser = await getUserInformation(data.requestingUserId);
|
||||
const requestingUserCredentials = await getUserCredentials(
|
||||
data.requestingUserId,
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
!requestingUser ||
|
||||
@@ -153,13 +151,13 @@ export async function updateCategory(data: UpdateCategoryInput): Promise<Categor
|
||||
|
||||
const updatedCategory = await prisma.category.update({
|
||||
where: {
|
||||
id: data.id
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
name: data.name,
|
||||
position: data.position,
|
||||
Channel: data.channels ? { set: data.channels } : undefined
|
||||
}
|
||||
Channel: data.channels ? { set: data.channels } : undefined,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updatedCategory) {
|
||||
@@ -173,14 +171,15 @@ export async function updateCategory(data: UpdateCategoryInput): Promise<Categor
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteCategory(data: DeleteCategoryInput): Promise<boolean | null>{
|
||||
export async function deleteCategory(
|
||||
data: DeleteCategoryInput,
|
||||
): Promise<boolean | null> {
|
||||
try {
|
||||
|
||||
//Confirm if user exists and is admin
|
||||
const requestingUser = await getUserInformation(data.requestingUserId);
|
||||
const requestingUserCredentials = await getUserCredentials(
|
||||
data.requestingUserId,
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
!requestingUser ||
|
||||
@@ -194,8 +193,8 @@ export async function deleteCategory(data: DeleteCategoryInput): Promise<boolean
|
||||
|
||||
const deleteAllChannels = await prisma.channel.deleteMany({
|
||||
where: {
|
||||
categoryId: data.id
|
||||
}
|
||||
categoryId: data.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (deleteAllChannels.count === 0) {
|
||||
@@ -204,8 +203,8 @@ export async function deleteCategory(data: DeleteCategoryInput): Promise<boolean
|
||||
|
||||
const deletedCategory = await prisma.category.delete({
|
||||
where: {
|
||||
id: data.id
|
||||
}
|
||||
id: data.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!deletedCategory) {
|
||||
@@ -219,14 +218,15 @@ export async function deleteCategory(data: DeleteCategoryInput): Promise<boolean
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteAllCategoriesFromInstance(data: DeleteCategoriesByInstanceIdInput): Promise<boolean | null>{
|
||||
export async function deleteAllCategoriesFromInstance(
|
||||
data: DeleteCategoriesByInstanceIdInput,
|
||||
): Promise<boolean | null> {
|
||||
try {
|
||||
|
||||
//Confirm if user exists and is admin
|
||||
const requestingUser = await getUserInformation(data.requestingUserId);
|
||||
const requestingUserCredentials = await getUserCredentials(
|
||||
data.requestingUserId,
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
!requestingUser ||
|
||||
@@ -240,8 +240,8 @@ export async function deleteAllCategoriesFromInstance(data: DeleteCategoriesByIn
|
||||
|
||||
const deletedCategories = await prisma.category.deleteMany({
|
||||
where: {
|
||||
instanceId: data.instanceId
|
||||
}
|
||||
instanceId: data.instanceId,
|
||||
},
|
||||
});
|
||||
|
||||
if (deletedCategories.count === 0) {
|
||||
@@ -250,19 +250,23 @@ export async function deleteAllCategoriesFromInstance(data: DeleteCategoriesByIn
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.log("services::channelService::deleteAllCategoriesFromInstance - ", err);
|
||||
console.log(
|
||||
"services::channelService::deleteAllCategoriesFromInstance - ",
|
||||
err,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function createChannel(data: CreateChannelInput): Promise<Channel | null>{
|
||||
export async function createChannel(
|
||||
data: CreateChannelInput,
|
||||
): Promise<Channel | null> {
|
||||
try {
|
||||
|
||||
//Confirm if user exists and is admin
|
||||
const requestingUser = await getUserInformation(data.requestingUserId);
|
||||
const requestingUserCredentials = await getUserCredentials(
|
||||
data.requestingUserId,
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
!requestingUser ||
|
||||
@@ -279,8 +283,8 @@ export async function createChannel(data: CreateChannelInput): Promise<Channel |
|
||||
type: data.type,
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
categoryId: data.categoryId ? data.categoryId : null
|
||||
}
|
||||
categoryId: data.categoryId ? data.categoryId : null,
|
||||
},
|
||||
});
|
||||
|
||||
if (!newChannel) {
|
||||
@@ -294,14 +298,12 @@ export async function createChannel(data: CreateChannelInput): Promise<Channel |
|
||||
}
|
||||
}
|
||||
|
||||
export async function getChannel(
|
||||
channelId: string
|
||||
): Promise<Channel | null>{
|
||||
export async function getChannel(channelId: string): Promise<Channel | null> {
|
||||
try {
|
||||
const channel = await prisma.channel.findUnique({
|
||||
where: {
|
||||
id: channelId
|
||||
}
|
||||
id: channelId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!channel) {
|
||||
@@ -316,34 +318,34 @@ export async function getChannel(
|
||||
}
|
||||
|
||||
export async function getChannelsByCategory(
|
||||
categoryId: string
|
||||
categoryId: string,
|
||||
): Promise<Channel[] | null> {
|
||||
try {
|
||||
const channels = await prisma.channel.findMany({
|
||||
where: {
|
||||
categoryId: categoryId
|
||||
}
|
||||
categoryId: categoryId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!channels) {
|
||||
throw new Error("could not find channels for category");
|
||||
}
|
||||
return channels;
|
||||
}
|
||||
catch(err){
|
||||
} catch (err) {
|
||||
console.log("services::channelService::getChannelsByCategory - ", err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateChannel(data: UpdateChannelInput): Promise<Channel | null>{
|
||||
export async function updateChannel(
|
||||
data: UpdateChannelInput,
|
||||
): Promise<Channel | null> {
|
||||
try {
|
||||
|
||||
//Confirm if user exists and is admin
|
||||
const requestingUser = await getUserInformation(data.requestingUserId);
|
||||
const requestingUserCredentials = await getUserCredentials(
|
||||
data.requestingUserId,
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
!requestingUser ||
|
||||
@@ -357,13 +359,13 @@ export async function updateChannel(data: UpdateChannelInput): Promise<Channel |
|
||||
|
||||
const updatedChannel = await prisma.channel.update({
|
||||
where: {
|
||||
id: data.id
|
||||
id: data.id,
|
||||
},
|
||||
data: {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
categoryId: data.categoryId ? data.categoryId : undefined
|
||||
}
|
||||
categoryId: data.categoryId ? data.categoryId : undefined,
|
||||
},
|
||||
});
|
||||
|
||||
if (!updatedChannel) {
|
||||
@@ -377,14 +379,15 @@ export async function updateChannel(data: UpdateChannelInput): Promise<Channel |
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteChannel(data: DeleteChannelInput): Promise<boolean | null>{
|
||||
export async function deleteChannel(
|
||||
data: DeleteChannelInput,
|
||||
): Promise<boolean | null> {
|
||||
try {
|
||||
|
||||
//Confirm if user exists and is admin
|
||||
const requestingUser = await getUserInformation(data.requestingUserId);
|
||||
const requestingUserCredentials = await getUserCredentials(
|
||||
data.requestingUserId,
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
!requestingUser ||
|
||||
@@ -398,8 +401,8 @@ export async function deleteChannel(data: DeleteChannelInput): Promise<boolean |
|
||||
|
||||
const deletedChannel = await prisma.channel.delete({
|
||||
where: {
|
||||
id: data.id
|
||||
}
|
||||
id: data.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!deletedChannel) {
|
||||
@@ -413,14 +416,15 @@ export async function deleteChannel(data: DeleteChannelInput): Promise<boolean |
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteAllChannelsFromCategory(data: DeleteChannelsByCategoryIdInput): Promise<boolean | null>
|
||||
{
|
||||
export async function deleteAllChannelsFromCategory(
|
||||
data: DeleteChannelsByCategoryIdInput,
|
||||
): Promise<boolean | null> {
|
||||
try {
|
||||
//Confirm if user exists and is admin
|
||||
const requestingUser = await getUserInformation(data.requestingUserId);
|
||||
const requestingUserCredentials = await getUserCredentials(
|
||||
data.requestingUserId,
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
!requestingUser ||
|
||||
@@ -434,8 +438,8 @@ export async function deleteAllChannelsFromCategory(data: DeleteChannelsByCatego
|
||||
|
||||
const deletedChannels = await prisma.channel.deleteMany({
|
||||
where: {
|
||||
categoryId: data.categoryId
|
||||
}
|
||||
categoryId: data.categoryId,
|
||||
},
|
||||
});
|
||||
|
||||
if (deletedChannels.count === 0) {
|
||||
@@ -444,7 +448,10 @@ export async function deleteAllChannelsFromCategory(data: DeleteChannelsByCatego
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.log("services::channelService::deleteAllChannelsFromCategory - ", err);
|
||||
console.log(
|
||||
"services::channelService::deleteAllChannelsFromCategory - ",
|
||||
err,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,29 +8,31 @@ export async function createInstance(data: CreateInstanceRequest) {
|
||||
try {
|
||||
const creds = await getUserCredentials(data.requestingUserId);
|
||||
const user = await getUserInformation(data.requestingUserId);
|
||||
if (!creds
|
||||
|| creds.token != data.requestingUserToken
|
||||
|| !user
|
||||
|| !user.admin) {
|
||||
if (
|
||||
!creds ||
|
||||
creds.token != data.requestingUserToken ||
|
||||
!user ||
|
||||
!user.admin
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const newInstance = await prisma.instance.create({
|
||||
data: {
|
||||
name: data.name,
|
||||
icon: data.icon
|
||||
}
|
||||
icon: data.icon,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: newInstance
|
||||
data: newInstance,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error creating instance:", error);
|
||||
return {
|
||||
success: false,
|
||||
error: "Failed to create instance"
|
||||
error: "Failed to create instance",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -39,19 +41,19 @@ export async function getAllInstances() {
|
||||
try {
|
||||
const instances = await prisma.instance.findMany({
|
||||
orderBy: {
|
||||
createdAt: 'desc'
|
||||
}
|
||||
createdAt: "desc",
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: instances
|
||||
data: instances,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching instances:", error);
|
||||
return {
|
||||
success: false,
|
||||
error: "Failed to fetch instances"
|
||||
error: "Failed to fetch instances",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,14 @@
|
||||
import {
|
||||
PrismaClient,
|
||||
} from "@prisma/client";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { getUserCredentials } from "./userService";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export async function getMessageInformation(id: string): Promise<{
|
||||
id: string,
|
||||
channelId: string,
|
||||
userId: string,
|
||||
text: string,
|
||||
deleted: boolean,
|
||||
id: string;
|
||||
channelId: string;
|
||||
userId: string;
|
||||
text: string;
|
||||
deleted: boolean;
|
||||
replies: null | {
|
||||
messageId: string;
|
||||
repliesToId: string;
|
||||
@@ -66,20 +64,22 @@ export async function getMessageInformation(id:string): Promise<{
|
||||
const errMessage = err as Error;
|
||||
|
||||
if (errMessage.message === "missing messageId") {
|
||||
console.log("services::actions::getMessageInformation - missing messageId");
|
||||
console.log(
|
||||
"services::actions::getMessageInformation - missing messageId",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (errMessage.message === "could not find message") {
|
||||
console.log(
|
||||
"services::actions::getMessageInformation - unable to find message"
|
||||
"services::actions::getMessageInformation - unable to find message",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log(
|
||||
"services::actions::getMessageInformation - unknown error",
|
||||
errMessage
|
||||
errMessage,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
@@ -141,13 +141,15 @@ export async function getMessagesBefore(date:string, channelId:string) {
|
||||
const errMessage = err as Error;
|
||||
|
||||
if (errMessage.message === "missing date or channelId") {
|
||||
console.log("services::actions::getMessagesBefore - missing date or channelId");
|
||||
console.log(
|
||||
"services::actions::getMessagesBefore - missing date or channelId",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log(
|
||||
"services::actions::getMessagesBefore - unknown error",
|
||||
errMessage
|
||||
errMessage,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import {
|
||||
Message,
|
||||
MessagePing,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
|
||||
//category validators
|
||||
|
||||
@@ -8,48 +8,54 @@ export const createCategorySchema = z.object({
|
||||
instanceId: z.uuidv7().optional(),
|
||||
admin: z.boolean(),
|
||||
requestingUserId: z.uuidv7(),
|
||||
requestingUserToken: z.uuidv4()
|
||||
})
|
||||
requestingUserToken: z.uuidv4(),
|
||||
});
|
||||
|
||||
export const getCategorySchema = z.object({
|
||||
id: z.uuidv7()
|
||||
})
|
||||
id: z.uuidv7(),
|
||||
});
|
||||
|
||||
export const getCategoriesByInstanceIdSchema = z.object({
|
||||
instanceId: z.uuidv7()
|
||||
|
||||
})
|
||||
instanceId: z.uuidv7(),
|
||||
});
|
||||
|
||||
export const updateCategorySchema = z.object({
|
||||
id: z.uuidv7(),
|
||||
name: z.string().min(1).max(50).optional(),
|
||||
position: z.number().min(0).optional(),
|
||||
channels: z.array(z.object({
|
||||
id: z.string()
|
||||
})).optional(),
|
||||
channels: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
admin: z.boolean(),
|
||||
requestingUserId: z.uuidv7(),
|
||||
requestingUserToken: z.uuidv4()
|
||||
})
|
||||
requestingUserToken: z.uuidv4(),
|
||||
});
|
||||
|
||||
export const deleteCategorySchema = z.object({
|
||||
id: z.uuidv7(),
|
||||
admin: z.boolean(),
|
||||
requestingUserId: z.uuidv7(),
|
||||
requestingUserToken: z.uuidv4()
|
||||
})
|
||||
requestingUserToken: z.uuidv4(),
|
||||
});
|
||||
|
||||
export const deleteCategoriesByInstanceIdSchema = z.object({
|
||||
instanceId: z.uuidv7(),
|
||||
admin: z.boolean(),
|
||||
requestingUserId: z.uuidv7(),
|
||||
requestingUserToken: z.uuidv4()
|
||||
})
|
||||
requestingUserToken: z.uuidv4(),
|
||||
});
|
||||
|
||||
|
||||
export type CreateCategoryInput = z.infer<typeof createCategorySchema>
|
||||
export type GetCategoryInput = z.infer<typeof getCategorySchema>
|
||||
export type GetCategoriesByInstanceIdInput = z.infer<typeof getCategoriesByInstanceIdSchema>
|
||||
export type UpdateCategoryInput = z.infer<typeof updateCategorySchema>
|
||||
export type DeleteCategoryInput = z.infer<typeof deleteCategorySchema>
|
||||
export type DeleteCategoriesByInstanceIdInput = z.infer<typeof deleteCategoriesByInstanceIdSchema>
|
||||
export type CreateCategoryInput = z.infer<typeof createCategorySchema>;
|
||||
export type GetCategoryInput = z.infer<typeof getCategorySchema>;
|
||||
export type GetCategoriesByInstanceIdInput = z.infer<
|
||||
typeof getCategoriesByInstanceIdSchema
|
||||
>;
|
||||
export type UpdateCategoryInput = z.infer<typeof updateCategorySchema>;
|
||||
export type DeleteCategoryInput = z.infer<typeof deleteCategorySchema>;
|
||||
export type DeleteCategoriesByInstanceIdInput = z.infer<
|
||||
typeof deleteCategoriesByInstanceIdSchema
|
||||
>;
|
||||
|
||||
@@ -3,22 +3,22 @@ import { z } from "zod";
|
||||
//channel validators
|
||||
|
||||
export const createChannelSchema = z.object({
|
||||
type: z.enum(['text', 'voice']),
|
||||
type: z.enum(["text", "voice"]),
|
||||
name: z.string().min(1).max(50),
|
||||
description: z.string().max(255),
|
||||
categoryId: z.uuidv7().optional(),
|
||||
admin: z.boolean(),
|
||||
requestingUserId: z.uuidv7(),
|
||||
requestingUserToken: z.uuidv4()
|
||||
})
|
||||
requestingUserToken: z.uuidv4(),
|
||||
});
|
||||
|
||||
export const getChannelSchema = z.object({
|
||||
id: z.uuidv7()
|
||||
})
|
||||
id: z.uuidv7(),
|
||||
});
|
||||
|
||||
export const getChannelsByCategoryIdSchema = z.object({
|
||||
categoryId: z.uuidv7()
|
||||
})
|
||||
categoryId: z.uuidv7(),
|
||||
});
|
||||
|
||||
export const updateChannelSchema = z.object({
|
||||
id: z.uuidv7(),
|
||||
@@ -27,26 +27,30 @@ export const updateChannelSchema = z.object({
|
||||
categoryId: z.uuidv7().optional(),
|
||||
admin: z.boolean(),
|
||||
requestingUserId: z.uuidv7(),
|
||||
requestingUserToken: z.uuidv4()
|
||||
})
|
||||
requestingUserToken: z.uuidv4(),
|
||||
});
|
||||
|
||||
export const deleteChannelSchema = z.object({
|
||||
id: z.uuidv7(),
|
||||
admin: z.boolean(),
|
||||
requestingUserId: z.uuidv7(),
|
||||
requestingUserToken: z.uuidv4()
|
||||
})
|
||||
requestingUserToken: z.uuidv4(),
|
||||
});
|
||||
|
||||
export const deleteChannelsByCategoryIdSchema = z.object({
|
||||
categoryId: z.uuidv7(),
|
||||
admin: z.boolean(),
|
||||
requestingUserId: z.uuidv7(),
|
||||
requestingUserToken: z.uuidv4()
|
||||
})
|
||||
requestingUserToken: z.uuidv4(),
|
||||
});
|
||||
|
||||
export type CreateChannelInput = z.infer<typeof createChannelSchema>
|
||||
export type GetChannelInput = z.infer<typeof getChannelSchema>
|
||||
export type GetChannelsByCategoryIdInput = z.infer<typeof getChannelsByCategoryIdSchema>
|
||||
export type UpdateChannelInput = z.infer<typeof updateChannelSchema>
|
||||
export type DeleteChannelInput = z.infer<typeof deleteChannelSchema>
|
||||
export type DeleteChannelsByCategoryIdInput = z.infer<typeof deleteChannelsByCategoryIdSchema>
|
||||
export type CreateChannelInput = z.infer<typeof createChannelSchema>;
|
||||
export type GetChannelInput = z.infer<typeof getChannelSchema>;
|
||||
export type GetChannelsByCategoryIdInput = z.infer<
|
||||
typeof getChannelsByCategoryIdSchema
|
||||
>;
|
||||
export type UpdateChannelInput = z.infer<typeof updateChannelSchema>;
|
||||
export type DeleteChannelInput = z.infer<typeof deleteChannelSchema>;
|
||||
export type DeleteChannelsByCategoryIdInput = z.infer<
|
||||
typeof deleteChannelsByCategoryIdSchema
|
||||
>;
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
import { z } from 'zod';
|
||||
import { z } from "zod";
|
||||
|
||||
export const createInstanceRequestSchema = z.object({
|
||||
name: z.string().min(1, 'Instance name cannot be empty'),
|
||||
name: z.string().min(1, "Instance name cannot be empty"),
|
||||
icon: z.url().optional(),
|
||||
requestingUserId: z.uuidv7(),
|
||||
requestingUserToken: z.string()
|
||||
requestingUserToken: z.string(),
|
||||
});
|
||||
|
||||
export const getAllInstancesResponseSchema = z.object({
|
||||
success: z.boolean(),
|
||||
data: z.array(
|
||||
data: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
icon: z.string().nullable(),
|
||||
createdAt: z.string().refine((val) => !isNaN(Date.parse(val)), {
|
||||
message: "Invalid date string format"
|
||||
message: "Invalid date string format",
|
||||
}),
|
||||
updatedAt: z.string().refine((val) => !isNaN(Date.parse(val)), {
|
||||
message: "Invalid date string format"
|
||||
})
|
||||
})
|
||||
).optional(),
|
||||
error: z.string().optional()
|
||||
message: "Invalid date string format",
|
||||
}),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
error: z.string().optional(),
|
||||
});
|
||||
|
||||
export type CreateInstanceRequest = z.infer<typeof createInstanceRequestSchema>;
|
||||
export type GetAllInstancesResponse = z.infer<typeof getAllInstancesResponseSchema>;
|
||||
export type GetAllInstancesResponse = z.infer<
|
||||
typeof getAllInstancesResponseSchema
|
||||
>;
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const getMessageByIdSchema = z.object({
|
||||
id: z.uuidv7()
|
||||
})
|
||||
id: z.uuidv7(),
|
||||
});
|
||||
|
||||
export const getMessagesBeforeDate = z.object({
|
||||
date: z.string().refine((val) => !isNaN(Date.parse(val)), {
|
||||
message: "Invalid date string format"
|
||||
message: "Invalid date string format",
|
||||
}),
|
||||
channelId: z.uuidv7()
|
||||
})
|
||||
channelId: z.uuidv7(),
|
||||
});
|
||||
|
||||
export const sendMessageSchema = z.object({
|
||||
channelId: z.uuidv7(),
|
||||
userId: z.uuidv7(),
|
||||
content: z.string(),
|
||||
token: z.string(),
|
||||
repliedMessageId: z.uuidv7().nullable().optional()
|
||||
})
|
||||
repliedMessageId: z.uuidv7().nullable().optional(),
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ export const queryUserByIdSchema = z.object({
|
||||
export const queryAllUsersByInstanceId = z.object({
|
||||
instanceId: z.uuidv7(),
|
||||
});
|
||||
import { is } from 'zod/v4/locales';
|
||||
import { is } from "zod/v4/locales";
|
||||
export const createUserSchema = z.object({
|
||||
username: z.string().min(3).max(30),
|
||||
nickname: z.string().min(1).max(30).optional(),
|
||||
|
||||
Reference in New Issue
Block a user