feat: update database schema to support item trading

This commit is contained in:
syntaxbullet
2025-12-13 12:00:02 +01:00
parent 8262eb8f02
commit 29899acc7f
2 changed files with 31 additions and 1 deletions

View File

@@ -72,12 +72,28 @@ export const transactions = pgTable('transactions', {
id: bigserial('id', { mode: 'bigint' }).primaryKey(), id: bigserial('id', { mode: 'bigint' }).primaryKey(),
userId: bigint('user_id', { mode: 'bigint' }) userId: bigint('user_id', { mode: 'bigint' })
.references(() => users.id, { onDelete: 'cascade' }), .references(() => users.id, { onDelete: 'cascade' }),
relatedUserId: bigint('related_user_id', { mode: 'bigint' })
.references(() => users.id, { onDelete: 'set null' }),
amount: bigint('amount', { mode: 'bigint' }).notNull(), amount: bigint('amount', { mode: 'bigint' }).notNull(),
type: varchar('type', { length: 50 }).notNull(), type: varchar('type', { length: 50 }).notNull(),
description: text('description'), description: text('description'),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(), createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
}); });
export const itemTransactions = pgTable('item_transactions', {
id: bigserial('id', { mode: 'bigint' }).primaryKey(),
userId: bigint('user_id', { mode: 'bigint' })
.references(() => users.id, { onDelete: 'cascade' }).notNull(),
relatedUserId: bigint('related_user_id', { mode: 'bigint' })
.references(() => users.id, { onDelete: 'set null' }), // who they got it from/gave it to
itemId: integer('item_id')
.references(() => items.id, { onDelete: 'cascade' }).notNull(),
quantity: bigint('quantity', { mode: 'bigint' }).notNull(), // positive = gain, negative = loss
type: varchar('type', { length: 50 }).notNull(), // e.g., 'TRADE', 'SHOP_BUY', 'DROP'
description: text('description'),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
});
// 6. Quests // 6. Quests
export const quests = pgTable('quests', { export const quests = pgTable('quests', {
id: serial('id').primaryKey(), id: serial('id').primaryKey(),
@@ -169,4 +185,19 @@ export const cooldownsRelations = relations(cooldowns, ({ one }) => ({
fields: [cooldowns.userId], fields: [cooldowns.userId],
references: [users.id], references: [users.id],
}), }),
}));
export const itemTransactionsRelations = relations(itemTransactions, ({ one }) => ({
user: one(users, {
fields: [itemTransactions.userId],
references: [users.id],
}),
relatedUser: one(users, {
fields: [itemTransactions.relatedUserId],
references: [users.id],
}),
item: one(items, {
fields: [itemTransactions.itemId],
references: [items.id],
}),
})); }));

View File

@@ -29,7 +29,6 @@ export async function generateStudentIdCard(data: StudentCardData): Promise<Buff
// Draw Background Gradient with random hue // Draw Background Gradient with random hue
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height); const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
const hue = Math.random() * 360;
const saturation = 40 + Math.random() * 20; // 40-60% const saturation = 40 + Math.random() * 20; // 40-60%
const lightness = 20 + Math.random() * 20; // 20-40% const lightness = 20 + Math.random() * 20; // 20-40%
const color2 = `hsl(${Math.random() * 360}, ${saturation}%, ${lightness}%)`; const color2 = `hsl(${Math.random() * 360}, ${saturation}%, ${lightness}%)`;