Skip to content

Commit 8fcc03d

Browse files
authored
Merge pull request #1 from arnabuchiha/dev/phase2/arnab
Dev/phase2/arnab
2 parents d33d576 + c8f7845 commit 8fcc03d

21 files changed

Lines changed: 2786 additions & 2422 deletions

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bunx lint-staged

.prettierignore

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Ignore artifacts:
2+
build
3+
coverage
4+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
5+
6+
# dependencies
7+
/node_modules
8+
/.pnp
9+
.pnp.*
10+
.yarn/*
11+
!.yarn/patches
12+
!.yarn/plugins
13+
!.yarn/releases
14+
!.yarn/versions
15+
16+
# testing
17+
/coverage
18+
19+
# next.js
20+
/.next/
21+
/out/
22+
23+
# production
24+
/build
25+
26+
# misc
27+
.DS_Store
28+
*.pem
29+
30+
# debug
31+
npm-debug.log*
32+
yarn-debug.log*
33+
yarn-error.log*
34+
35+
# env files (can opt-in for committing if needed)
36+
.env*
37+
38+
# vercel
39+
.vercel
40+
.turbo
41+
.idea
42+
.vscode
43+
44+
.next/
45+
out/
46+
dist
47+
48+
49+
# typescript
50+
*.tsbuildinfo
51+
next-env.d.ts

.prettierrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"htmlWhitespaceSensitivity": "css",
5+
"insertPragma": false,
6+
"jsxBracketSameLine": false,
7+
"jsxSingleQuote": false,
8+
"printWidth": 80,
9+
"proseWrap": "always",
10+
"quoteProps": "as-needed",
11+
"requirePragma": false,
12+
"semi": true,
13+
"singleQuote": false,
14+
"tabWidth": 2,
15+
"trailingComma": "all",
16+
"useTabs": false
17+
}

README.md

Lines changed: 220 additions & 66 deletions
Large diffs are not rendered by default.

apps/auction-distributor/prisma/schema.prisma

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ enum SellerType {
7474
}
7575

7676
enum Category {
77-
OUDE_RAM
78-
SCHAAP
7977
OOI
8078
RAM
79+
SCHAAP
80+
OUDE_RAM
8181
}
8282

8383
model Seller {
@@ -86,7 +86,7 @@ model Seller {
8686
user User @relation(fields: [userId], references: [id])
8787
companyName String
8888
ubnNumber String @unique
89-
//TODO Needs to replaced with street,house...Refer Phase 2 Doc
89+
// TODO Needs to replaced with street,house...Refer Phase 2 Doc
9090
street String
9191
houseNumber Int
9292
suffix String @default("")
@@ -138,7 +138,7 @@ model Buyer {
138138
houseNumber Int
139139
suffix String @default("")
140140
postalCode String
141-
province Province
141+
province String @default("OTHERS")
142142
country String @default("NL")
143143
vatNumber String
144144
kvkNumber String
@@ -176,6 +176,7 @@ enum Province {
176176
ZUID_HOLLAND
177177
UTRECHT
178178
ZEELAND
179+
OTHERS
179180
}
180181

181182
enum ProductQualification {
@@ -210,7 +211,7 @@ model Product {
210211
breed String @default("Sheep")
211212
breedDetails Breed @relation(fields: [breed], references: [name])
212213
qualification ProductQualification
213-
minPrice1 Float @default(0) //per kg
214+
minPrice1 Float @default(0) // per kg
214215
minPrice2 Float @default(0)
215216
estimatedWeight Float
216217
unit String
@@ -276,8 +277,8 @@ model AuctionItem {
276277
auction Auction @relation(fields: [auctionId], references: [id])
277278
productId String @db.ObjectId
278279
product Product @relation(fields: [productId], references: [id])
279-
startingPrice Float // minPrice + operationalCost/100 + initialPrice/100 + (additionalPrice||0)/100 --Update this after starting auction if needed
280-
endingPrice Float // minPrice + operationalCost/100
280+
startingPrice Float // minPrice + operationalCost/100 + initialPrice/100 + (additionalPrice||0)/100 --Update this after starting auction if needed
281+
endingPrice Float // minPrice + operationalCost/100
281282
roundNumber Int @default(0)
282283
decrementIteration Int @default(0)
283284
sellingPrice Float? // startingPrice - (decrementPrice * round_number)/100
Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,66 @@
1-
import { AuctionItem, Product, PrismaClient } from "@prisma/client";
1+
import { AuctionItem, PrismaClient } from "@prisma/client";
22
import { redisCache } from "../config/redis";
33
import prisma from "../config/prisma";
4+
import { CurrentAuctionMeta } from "../types/interfaceTypes";
45

56
const prismaClient = new PrismaClient();
67

78
class AuctionService {
8-
public getAuctionItems = async (
9-
auctionId: string,
10-
roundNumber: 1 | 2,
11-
forceUpdate: boolean = false
12-
): Promise<AuctionItem[] | null> => {
13-
let auctionItemIds = forceUpdate
14-
? null
15-
: await redisCache.get<string[]>(`auctionItems:${auctionId}`);
16-
17-
if (!auctionItemIds) {
18-
// Fetch IDs from DB if cache misses or forceUpdate is true
19-
const dbAuctionItems = await prisma.auctionItem.findMany({
20-
where: { auctionId, roundNumber },
21-
select: { id: true },
22-
});
23-
24-
auctionItemIds = dbAuctionItems.map((item) => item.id);
25-
26-
// Store fetched IDs in cache
27-
await redisCache.set(`auctionItems:${auctionId}`, auctionItemIds);
28-
}
9+
public getAuctionItems = async (
10+
auctionId: string,
11+
roundNumber: 1 | 2,
12+
forceUpdate: boolean = false,
13+
): Promise<AuctionItem[] | null> => {
14+
const meta = await redisCache.get<CurrentAuctionMeta>(
15+
`currentAuctionMeta:${auctionId}`,
16+
);
17+
roundNumber = meta?.currentRoundNumber || 1;
18+
const listKey =
19+
roundNumber === 1
20+
? `auctionItems:${auctionId}`
21+
: `auctionItems2:${auctionId}`;
22+
let auctionItemIds = forceUpdate
23+
? null
24+
: await redisCache.get<string[]>(listKey);
25+
26+
if (!auctionItemIds) {
27+
// Fetch IDs from DB if cache misses or forceUpdate is true
28+
const dbAuctionItems = await prisma.auctionItem.findMany({
29+
where: { auctionId, roundNumber },
30+
select: { id: true },
31+
});
32+
33+
auctionItemIds = dbAuctionItems.map((item) => item.id);
34+
35+
// Store fetched IDs in cache
36+
await redisCache.set(listKey, auctionItemIds);
37+
}
38+
39+
const result: AuctionItem[] = [];
40+
41+
for (const auctionItemId of auctionItemIds) {
42+
let auctionItem = forceUpdate
43+
? null
44+
: await redisCache.get<AuctionItem>("auctionItem:" + auctionItemId);
2945

30-
const result: AuctionItem[] = [];
31-
32-
for (const auctionItemId of auctionItemIds) {
33-
let auctionItem = forceUpdate
34-
? null
35-
: await redisCache.get<AuctionItem>(
36-
"auctionItem:" + auctionItemId
37-
);
38-
39-
if (!auctionItem) {
40-
// Fetch from DB if not found in cache or forceUpdate is true
41-
auctionItem = await prisma.auctionItem.findUnique({
42-
where: { id: auctionItemId },
43-
include: {
44-
product: true, // Fetch all fields inside product
45-
},
46-
});
47-
if (auctionItem) {
48-
await redisCache.set(
49-
"auctionItem:" + auctionItemId,
50-
auctionItem
51-
);
52-
result.push(auctionItem);
53-
}
54-
} else {
55-
result.push(auctionItem);
56-
}
46+
if (!auctionItem) {
47+
// Fetch from DB if not found in cache or forceUpdate is true
48+
auctionItem = await prisma.auctionItem.findUnique({
49+
where: { id: auctionItemId },
50+
include: {
51+
product: true, // Fetch all fields inside product
52+
},
53+
});
54+
if (auctionItem) {
55+
await redisCache.set("auctionItem:" + auctionItemId, auctionItem);
56+
result.push(auctionItem);
5757
}
58-
return result;
59-
};
58+
} else {
59+
result.push(auctionItem);
60+
}
61+
}
62+
return result;
63+
};
6064
}
6165

6266
export = AuctionService;

0 commit comments

Comments
 (0)