1 import { Repository } from "./base";
2 import { v4 as uuid } from 'uuid';
4 export type Message = {
15 export type MessageWithNames = {
19 export class MailRepository extends Repository<Message> {
24 async createSystemMessage(from: string, to: string, subject: string, message: string) {
25 const msg: Message = {
36 await this.Insert(msg);
40 async markAsRead(id: string, to: string) {
41 return this.Save({read_at: Date.now()}, {
47 async getMessage(id: string, to: string): Promise<MessageWithNames> {
48 const res = await this.db.raw<MessageWithNames[]>(`select m.*, a.username
50 join accounts a on a.id = m.from_account
51 where m.to_account = ?
59 async listReceivedMessages(to: string): Promise<MessageWithNames[]> {
60 return this.db.raw<MessageWithNames[]>(`select m.*, a.username
62 join accounts a on a.id = m.from_account
63 where m.to_account = ?
64 order by sent_at desc`, to);