Skip to content

Commit

Permalink
Merge pull request #50 from casesandberg/feature/option-colors
Browse files Browse the repository at this point in the history
Store market option color in database
  • Loading branch information
casesandberg authored Jul 10, 2024
2 parents 5e4c264 + 6159f78 commit 2efa7a8
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 17 deletions.
8 changes: 0 additions & 8 deletions apps/web/app/(app)/questions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,10 @@ export default async function AppQuestionsPage() {
return {
...market,
user: sanitizeUser(market.user),
options: market.options.map((option) => ({
...option,
color: option.currencyCode === 'YES' ? '#3b82f6' : '#ec4899',
})),
marketResolution: market.marketResolution
? {
...market.marketResolution,
resolvedBy: sanitizeUser(market.marketResolution.resolvedBy),
resolution: {
...market.marketResolution.resolution,
color: market.marketResolution.resolution.currencyCode === 'YES' ? '#3b82f6' : '#ec4899',
},
}
: undefined,
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"db:push": "dotenv -- turbo db:push",
"db:generate": "dotenv -- turbo db:generate",
"db:script": "dotenv -- npm run script -w @play-money/database",
"db:reset": "dotenv -- turbo db:reset",
"test": "turbo run test",
"test:watch": "turbo run test:watch"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "MarketOption" ADD COLUMN "color" TEXT NOT NULL DEFAULT '#FF00FF';

UPDATE "MarketOption" SET "color" = '#3B82F6' WHERE "currencyCode" = 'YES';
UPDATE "MarketOption" SET "color" = '#EC4899' WHERE "currencyCode" = 'NO';
1 change: 1 addition & 0 deletions packages/database/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export function mockMarketOption(overrides?: Partial<MarketOption>): MarketOptio
id: faker.string.uuid(),
name: currencyCode === 'YES' ? 'Yes' : 'No',
currencyCode,
color: currencyCode === 'YES' ? '#3B82F6' : '#EC4899',
marketId: faker.string.uuid(),
createdAt: faker.date.past(),
updatedAt: faker.date.past(),
Expand Down
1 change: 1 addition & 0 deletions packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"db:generate": "prisma generate && prisma format",
"db:push": "prisma db push --skip-generate",
"db:reset": "prisma migrate reset --force",
"dev": "cross-env BROWSER=none prisma studio",
"type-check": "tsc --noEmit",
"script": "tsx scripts/run.js"
Expand Down
1 change: 1 addition & 0 deletions packages/database/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ model MarketOption {
market Market @relation(fields: [marketId], references: [id])
currencyCode CurrencyCode
currency Currency @relation(fields: [currencyCode], references: [code])
color String @default("#FF00FF") /// @zod.string.regex(/^#[0-9A-Fa-f]{6}$/)
resolutions MarketResolution[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod';

export const MarketOptionScalarFieldEnumSchema = z.enum(['id','name','marketId','currencyCode','createdAt','updatedAt']);
export const MarketOptionScalarFieldEnumSchema = z.enum(['id','name','marketId','currencyCode','color','createdAt','updatedAt']);

export default MarketOptionScalarFieldEnumSchema;
1 change: 1 addition & 0 deletions packages/database/zod/modelSchema/MarketOptionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const MarketOptionSchema = z.object({
id: z.string().cuid(),
name: z.string(),
marketId: z.string(),
color: z.string().regex(/^#[0-9A-Fa-f]{6}$/),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
})
Expand Down
1 change: 1 addition & 0 deletions packages/markets/lib/createMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export async function createMarket({
data: parsedOptions.map((option) => ({
name: option.name,
currencyCode: option.currencyCode,
color: option.currencyCode === 'YES' ? '#3B82F6' : '#EC4899',
updatedAt: new Date(),
createdAt: new Date(),
})),
Expand Down
8 changes: 0 additions & 8 deletions packages/markets/lib/getMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,10 @@ export async function getMarket({
return {
...market,
user: sanitizeUser(market.user),
options: market.options.map((option) => ({
...option,
color: option.currencyCode === 'YES' ? '#3b82f6' : '#ec4899',
})),
marketResolution: market.marketResolution
? {
...market.marketResolution,
resolvedBy: sanitizeUser(market.marketResolution.resolvedBy),
resolution: {
...market.marketResolution.resolution,
color: market.marketResolution.resolution.currencyCode === 'YES' ? '#3b82f6' : '#ec4899',
},
}
: undefined,
}
Expand Down
3 changes: 3 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"db:push": {
"cache": false
},
"db:reset": {
"cache": false
},
"test": {},
"test:watch": {
"cache": false
Expand Down

0 comments on commit 2efa7a8

Please sign in to comment.