fix: app.route overload
This commit is contained in:
6
concord-server/src/controller/actions.ts
Normal file
6
concord-server/src/controller/actions.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { getUserInformation } from "../services/actions";
|
||||
|
||||
|
||||
export async function fetchUserData(id: string) {
|
||||
return await getUserInformation(id);
|
||||
}
|
||||
@@ -42,12 +42,9 @@ app.use('*', cors({
|
||||
allowHeaders: ['Content-Type', 'Authorization'],
|
||||
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
credentials: true
|
||||
}))
|
||||
app.use(routes)
|
||||
})
|
||||
|
||||
app.route('/api', routes)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export default app
|
||||
export default app;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Hono } from "hono"
|
||||
import { fetchUserData } from "../controller/actions"
|
||||
const actions = new Hono()
|
||||
|
||||
|
||||
/*
|
||||
actions.post("actions/message/:id", (c) => {
|
||||
//todo: pass service function to send a message to user id
|
||||
})
|
||||
@@ -14,14 +15,22 @@ actions.get("actions/message/all/:userId", (c) => {
|
||||
//todo: pass service function to fetch all messages f a user
|
||||
})
|
||||
|
||||
actions.get("actions/:id", (c) => {
|
||||
//todo: pass service function to fetch user data by id
|
||||
})
|
||||
|
||||
|
||||
actions.get("actions/userChannels/:id", (c) => {
|
||||
//todo: pass service function to fetch all channels the id is part of
|
||||
})
|
||||
*/
|
||||
|
||||
actions.get("actions/:id", async (c) => {
|
||||
const id = c.req.param("id");
|
||||
const userData = await fetchUserData(id);
|
||||
if (userData) {
|
||||
return c.json(userData);
|
||||
} else {
|
||||
return c.json({ error: "User not found" }, 404);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
export default actions
|
||||
@@ -1,4 +1,4 @@
|
||||
//send a ping to a user
|
||||
import { Message, MessagePing, Role, UserAuth } from "@prisma/client";
|
||||
|
||||
export async function getUserChannels(userId: string): Promise<string[] | null> {
|
||||
try{
|
||||
@@ -24,16 +24,42 @@ export async function getUserChannels(userId: string): Promise<string[] | null>
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUserInformation(userId: string): Promise<{id: string, name: string} | null> {
|
||||
export async function getUserInformation(userId: string):
|
||||
Promise<{
|
||||
id: string,
|
||||
userName: string,
|
||||
nickName?: string,
|
||||
bio?: string,
|
||||
picture?: string,
|
||||
banner?: string,
|
||||
admin: boolean,
|
||||
status: 'online' | 'offline' | 'dnd' | 'idle' | 'invis',
|
||||
role: Role[],
|
||||
userAuth?: UserAuth,
|
||||
messages: Message[],
|
||||
MessagePing: MessagePing[]
|
||||
} | null> {
|
||||
try{
|
||||
if(!userId){
|
||||
throw new Error('missing userId');
|
||||
}
|
||||
|
||||
//TODO: add some prisma code here
|
||||
//to fetch user information
|
||||
|
||||
return {id: userId, name: "Test User"};
|
||||
return {
|
||||
id: userId,
|
||||
userName: "Test User",
|
||||
bio: "this is a bio",
|
||||
picture: "https://www.goodhousekeeping.com/life/pets/g61070837/cutest-cat-breeds/",
|
||||
banner: "https://www.goodhousekeeping.com/life/pets/g61070837/cutest-cat-breeds/",
|
||||
admin: false,
|
||||
status: "offline",
|
||||
role: [],
|
||||
userAuth: undefined,
|
||||
messages: [],
|
||||
MessagePing: []
|
||||
};
|
||||
|
||||
}catch(err){
|
||||
const errMessage = err as Error
|
||||
|
||||
@@ -47,4 +73,64 @@ export async function getUserInformation(userId: string): Promise<{id: string, n
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllMessage(userId: string): Promise<{}
|
||||
export async function getAllMessage(userId: string): Promise<{id: string, content: string, senderId: string, receiverId: string}[] | null> {
|
||||
try{
|
||||
if(!userId){
|
||||
throw new Error('missing userId');
|
||||
}
|
||||
|
||||
//TODO: add some prisma code here
|
||||
//to fetch all messages for a user
|
||||
|
||||
return [
|
||||
{id: "1", content: "Hello", senderId: userId, receiverId: "2"},
|
||||
{id: "2", content: "Hi", senderId: "2", receiverId: userId}
|
||||
];
|
||||
}catch(err){
|
||||
const errMessage = err as Error
|
||||
|
||||
if(errMessage.message === 'missing userId'){
|
||||
console.log('services::actions::getAllMessage - missing userId');
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log('services::actions::getAllMessage - unknown error', errMessage);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function sendMessage(userId: string, content: string): Promise<boolean> {
|
||||
try{
|
||||
if(!userId){
|
||||
throw new Error('missing userId');
|
||||
}
|
||||
|
||||
if(!content){
|
||||
throw new Error('missing content');
|
||||
}
|
||||
|
||||
//TODO: add some prisma code here
|
||||
//to save a message
|
||||
|
||||
//todo: add some socketio code to
|
||||
//emit the message to the receiver
|
||||
|
||||
return true;
|
||||
}catch(err){
|
||||
const errMessage = err as Error
|
||||
|
||||
if(errMessage.message === 'missing userId'){
|
||||
console.log('services::actions::sendMessage - missing userId');
|
||||
return false;
|
||||
}
|
||||
|
||||
if(errMessage.message === 'missing content'){
|
||||
console.log('services::actions::sendMessage - missing content');
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('services::actions::sendMessage - unknown error', errMessage);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
3
concord-server/src/validators/actions.ts
Normal file
3
concord-server/src/validators/actions.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { zValidator } from "@hono/zod-validator"
|
||||
|
||||
export const
|
||||
Reference in New Issue
Block a user