feat: initial commit - Band Management application

This commit is contained in:
2026-01-06 03:11:46 +01:00
commit 34e12e00b3
24543 changed files with 3991790 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { db } from '@/server/fake-db/apps/chat'
export default defineEventHandler(async event => {
const { q = '' } = getQuery(event)
const qLowered = q.toLowerCase()
const chatsContacts = db.chats
.map(chat => {
const contact = JSON.parse(JSON.stringify(db.contacts.find(c => c.id === chat.userId)))
contact.chat = { id: chat.id, unseenMsgs: chat.unseenMsgs, lastMessage: chat.messages.at(-1) }
return contact
})
.reverse()
const profileUserData = db.profileUser
return {
chatsContacts: chatsContacts.filter(c => c.fullName.toLowerCase().includes(qLowered)),
contacts: db.contacts.filter(c => c.fullName.toLowerCase().includes(qLowered)),
profileUser: profileUserData,
}
})

View File

@@ -0,0 +1,13 @@
import { db } from '@/server/fake-db/apps/chat'
export default defineEventHandler(async event => {
const userId = getIntId(event, 'User id is required to get chat messages')
const chat = db.chats.find(c => c.userId === userId)
if (chat)
chat.unseenMsgs = 0
return {
chat,
contact: db.contacts.find(c => c.id === userId),
}
})

View File

@@ -0,0 +1,44 @@
import { db } from '@/server/fake-db/apps/chat'
export default defineEventHandler(async event => {
// Get user id from URL
const chatId = getIntId(event, 'Chat id is required to send message')
// Get message from post data
const { message, senderId } = await readBody(event)
let activeChat = db.chats.find(chat => chat.userId === chatId)
const newMessageData = {
message,
time: String(new Date()),
senderId,
feedback: {
isSent: true,
isDelivered: false,
isSeen: false,
},
}
// If there's new chat for user create one
let isNewChat = false
if (activeChat === undefined) {
isNewChat = true
db.chats.push({
id: db.chats.length + 1,
userId: chatId,
unseenMsgs: 0,
messages: [newMessageData],
})
activeChat = db.chats.at(-1)
}
else {
activeChat.messages.push(newMessageData)
}
const response = { msg: newMessageData }
if (isNewChat)
response.chat = activeChat
setResponseStatus(event, 201)
return response
})