-
Notifications
You must be signed in to change notification settings - Fork 14
/
schema.ts
103 lines (93 loc) · 2.12 KB
/
schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
export type User = {
username: string;
profilePic: string;
bio: string;
shippingAddress: string;
timestamp: string;
balance: number;
password: string;
};
export const UserSchema = `CREATE TABLE IF NOT EXISTS users (
username TEXT PRIMARY KEY,
profilePic TEXT,
bio TEXT,
shippingAddress TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
balance INTEGER DEFAULT 0,
password TEXT
)`;
export type Item = {
id: string;
owner: string;
title: string;
description: string;
price: number;
totalSupply: number;
availableSupply: number;
timestamp: string;
listed: 0 | 1; // 0 = false, 1 = true
image: string;
category: string;
};
export const ItemSchema = `CREATE TABLE IF NOT EXISTS items (
id TEXT PRIMARY KEY,
title TEXT,
description TEXT,
price INTEGER,
totalSupply INTEGER,
availableSupply INTEGER,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
listed BOOLEAN DEFAULT TRUE,
image TEXT,
owner TEXT,
category TEXT
)`;
export type Rating = {
id: number;
target: string;
author: string;
stars: number;
comment: string;
timestamp: string;
};
export const RatingSchema = `CREATE TABLE IF NOT EXISTS ratings (
id INTEGER PRIMARY KEY DEFAULT AUTO_INCREMENT,
target TEXT,
author TEXT,
stars INTEGER,
comment TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)`;
export type Purchase = {
id: number;
itemId: string;
buyer: string;
seller: string;
timestamp: string;
quantity: number;
itemPrice: number;
status: "pending" | "shipped" | "delivered";
txnDigest: string;
};
export const PurchaseSchema = `CREATE TABLE IF NOT EXISTS purchases (
id INTEGER PRIMARY KEY DEFAULT AUTO_INCREMENT,
itemId TEXT,
buyer TEXT,
seller TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
quantity INTEGER,
itemPrice INTEGER,
status TEXT DEFAULT 'pending',
txnDigest TEXT
)`;
export const isPurchase = (item: Item | Purchase): boolean => {
return (item as Purchase).seller !== undefined;
};
export type WatchList = {
userId: string;
itemId: string;
};
export const WatchlistSchema = `CREATE TABLE IF NOT EXISTS watchlist (
userId TEXT,
itemId TEXT
)`;