feat(backend): complete AI and business migration
This commit is contained in:
@@ -167,15 +167,31 @@ export function createDomainRepositories(db: DomainDatabase) {
|
||||
listSessions: (scope: OwnerScope) => db.select().from(chatSessions).where(eq(chatSessions.ownerUserId, scope.ownerUserId)).orderBy(desc(chatSessions.updatedAt)).all(),
|
||||
getSession: (scope: OwnerScope, id: string) => db.select().from(chatSessions).where(and(eq(chatSessions.id, id), eq(chatSessions.ownerUserId, scope.ownerUserId))).get(),
|
||||
createSession: (scope: OwnerScope, value: Omit<typeof chatSessions.$inferInsert, "ownerUserId">) => db.insert(chatSessions).values({ ...value, ownerUserId: scope.ownerUserId }).returning().get(),
|
||||
removeSession: (scope: OwnerScope, id: string) => db.delete(chatSessions).where(and(eq(chatSessions.id, id), eq(chatSessions.ownerUserId, scope.ownerUserId))).returning().get(),
|
||||
listMessages: (scope: OwnerScope, sessionId: string) => db.select({ message: chatMessages }).from(chatMessages).innerJoin(chatSessions, eq(chatMessages.sessionId, chatSessions.id)).where(and(eq(chatMessages.sessionId, sessionId), eq(chatSessions.ownerUserId, scope.ownerUserId))).orderBy(asc(chatMessages.createdAt)).all().map(({ message }) => message),
|
||||
createMessage: (value: typeof chatMessages.$inferInsert) => db.insert(chatMessages).values(value).returning().get(),
|
||||
},
|
||||
business: {
|
||||
listProposals: (scope: OwnerScope) => db.select().from(proposals).where(eq(proposals.ownerUserId, scope.ownerUserId)).orderBy(desc(proposals.createdAt)).all(),
|
||||
getProposal: (scope: OwnerScope, id: string) => db.select().from(proposals).where(and(eq(proposals.id, id), eq(proposals.ownerUserId, scope.ownerUserId))).get(),
|
||||
createProposal: (scope: OwnerScope, value: Omit<typeof proposals.$inferInsert, "ownerUserId">) => db.insert(proposals).values({ ...value, ownerUserId: scope.ownerUserId }).returning().get(),
|
||||
updateProposal: (scope: OwnerScope, id: string, value: Partial<typeof proposals.$inferInsert>) => db.update(proposals).set({ ...value, updatedAt: new Date() }).where(and(eq(proposals.id, id), eq(proposals.ownerUserId, scope.ownerUserId))).returning().get(),
|
||||
removeProposal: (scope: OwnerScope, id: string) => db.delete(proposals).where(and(eq(proposals.id, id), eq(proposals.ownerUserId, scope.ownerUserId))).returning().get(),
|
||||
listContracts: (scope: OwnerScope) => db.select().from(contracts).where(eq(contracts.ownerUserId, scope.ownerUserId)).orderBy(desc(contracts.createdAt)).all(),
|
||||
getContract: (scope: OwnerScope, id: string) => db.select().from(contracts).where(and(eq(contracts.id, id), eq(contracts.ownerUserId, scope.ownerUserId))).get(),
|
||||
createContract: (scope: OwnerScope, value: Omit<typeof contracts.$inferInsert, "ownerUserId">) => db.insert(contracts).values({ ...value, ownerUserId: scope.ownerUserId }).returning().get(),
|
||||
updateContract: (scope: OwnerScope, id: string, value: Partial<typeof contracts.$inferInsert>) => db.update(contracts).set({ ...value, updatedAt: new Date() }).where(and(eq(contracts.id, id), eq(contracts.ownerUserId, scope.ownerUserId))).returning().get(),
|
||||
removeContract: (scope: OwnerScope, id: string) => db.delete(contracts).where(and(eq(contracts.id, id), eq(contracts.ownerUserId, scope.ownerUserId))).returning().get(),
|
||||
listInvoices: (scope: OwnerScope) => db.select().from(invoices).where(eq(invoices.ownerUserId, scope.ownerUserId)).orderBy(desc(invoices.createdAt)).all(),
|
||||
getInvoice: (scope: OwnerScope, id: string) => db.select().from(invoices).where(and(eq(invoices.id, id), eq(invoices.ownerUserId, scope.ownerUserId))).get(),
|
||||
createInvoice: (scope: OwnerScope, value: Omit<typeof invoices.$inferInsert, "ownerUserId">) => db.insert(invoices).values({ ...value, ownerUserId: scope.ownerUserId }).returning().get(),
|
||||
updateInvoice: (scope: OwnerScope, id: string, value: Partial<typeof invoices.$inferInsert>) => db.update(invoices).set({ ...value, updatedAt: new Date() }).where(and(eq(invoices.id, id), eq(invoices.ownerUserId, scope.ownerUserId))).returning().get(),
|
||||
removeInvoice: (scope: OwnerScope, id: string) => db.delete(invoices).where(and(eq(invoices.id, id), eq(invoices.ownerUserId, scope.ownerUserId))).returning().get(),
|
||||
listSubscriptions: (scope: OwnerScope) => db.select().from(subscriptions).where(eq(subscriptions.ownerUserId, scope.ownerUserId)).orderBy(desc(subscriptions.createdAt)).all(),
|
||||
getSubscription: (scope: OwnerScope, id: string) => db.select().from(subscriptions).where(and(eq(subscriptions.id, id), eq(subscriptions.ownerUserId, scope.ownerUserId))).get(),
|
||||
createSubscription: (scope: OwnerScope, value: Omit<typeof subscriptions.$inferInsert, "ownerUserId">) => db.insert(subscriptions).values({ ...value, ownerUserId: scope.ownerUserId }).returning().get(),
|
||||
updateSubscription: (scope: OwnerScope, id: string, value: Partial<typeof subscriptions.$inferInsert>) => db.update(subscriptions).set({ ...value, updatedAt: new Date() }).where(and(eq(subscriptions.id, id), eq(subscriptions.ownerUserId, scope.ownerUserId))).returning().get(),
|
||||
removeSubscription: (scope: OwnerScope, id: string) => db.delete(subscriptions).where(and(eq(subscriptions.id, id), eq(subscriptions.ownerUserId, scope.ownerUserId))).returning().get(),
|
||||
},
|
||||
analytics: {
|
||||
summary: (scope: OwnerScope) => db.select({
|
||||
|
||||
Reference in New Issue
Block a user