-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
152 lines (145 loc) · 4.43 KB
/
index.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Path: index.ts
import { AccessModifier } from "@prisma/client";
import { UserTable, ProfileTable, TweetTable } from "./Tables";
console.log("APP: Application Started");
const executor = async () => {
// Fetching all the users
const UsersList = await (await UserTable.getAll()).users;
if (UsersList && UsersList.length === 0)
console.log(
"APP: Creating a new user",
// Creating a new user if nothing exists
await UserTable.create({
email: "[email protected]",
password: "password",
phoneNumber: "+977-9000000012",
})
);
// Fetching all the users
const UpdatedUserList = await (await UserTable.getAll()).users;
console.log("APP: Users List", UpdatedUserList);
if (UpdatedUserList && UpdatedUserList.length !== 0) {
console.log(
"APP: Updating the user",
// Updating the user if only one exists
await UserTable.update({
...UpdatedUserList[0],
password: "p@ssw0rd",
isSuspended: true,
})
);
}
if (UpdatedUserList)
console.log(
"APP: Selecting First User From Db",
// Selecting the user if the only one exists
await UserTable.getById(UpdatedUserList[0].id)
);
// Fetching all the profiles
const ProfilesList = await (await ProfileTable.getAll()).profile;
if (ProfilesList && UpdatedUserList && ProfilesList.length === 0)
console.log(
"APP: Creating a new profile",
// Creating a new profile if nothing exists
await ProfileTable.create({
userName: "test23",
userId: UpdatedUserList[0].id,
})
);
// Fetching all the profiles
const UpdatedProfilesList = await (await ProfileTable.getAll()).profile;
console.log("APP: Profiles List", UpdatedProfilesList);
if (UpdatedProfilesList && UpdatedProfilesList.length !== 0) {
console.log(
"APP: Updating the profile",
// Updating the profile if only one exists
await ProfileTable.update({
...UpdatedProfilesList[0],
userName: "test24",
isOnline: true,
followers: BigInt(100),
})
);
}
if (UpdatedProfilesList)
console.log(
"APP: Selecting First Profile From Db",
// Selecting the profile if the only one exists
await ProfileTable.getById(UpdatedProfilesList[0].id)
);
// Fetching all the tweets
const TweetsList = await (await TweetTable.getAll()).tweet;
if (TweetsList && UpdatedProfilesList && TweetsList.length === 0)
console.log(
"APP: Creating a new tweet",
// Creating a new tweet if nothing exists
await TweetTable.create({
description: "This is a test tweet",
access: AccessModifier.PUBLIC,
profileId: UpdatedProfilesList[0].id,
})
);
// Fetching all the tweets
const UpdatedTweetsList = await (await TweetTable.getAll()).tweet;
console.log("APP: Tweets List", UpdatedTweetsList);
if (UpdatedTweetsList && UpdatedTweetsList.length !== 0) {
console.log(
"APP: Updating the tweet",
// Updating the tweet if only one exists
await TweetTable.update({
...UpdatedTweetsList[0],
description: "This is a test tweet 2",
access: AccessModifier.PRIVATE,
})
);
}
if (UpdatedTweetsList)
console.log(
"APP: Selecting First Tweet From Db",
// Selecting the tweet if the only one exists
await TweetTable.getById(UpdatedTweetsList[0].id)
);
// Listing Details With Linkage
console.dirxml(
"APP: Listing Details With Linkage",
"Tweets:",
await TweetTable.getAll(true),
"Profile:",
await ProfileTable.getAll(true),
"User:",
await UserTable.getAll(true)
);
// Deleting the data
if (UpdatedTweetsList)
console.log(
"APP: Deleting First Tweet From Db",
// Deleting the tweet if the only one exists
await TweetTable.delete(UpdatedTweetsList[0])
);
if (UpdatedProfilesList)
console.log(
"APP: Deleting First Profile From Db",
// Deleting the profile if the only one exists
await ProfileTable.delete(UpdatedProfilesList[0])
);
if (UpdatedUserList)
console.log(
"APP: Deleting First User From Db",
// Deleting the user if the only one exists
await UserTable.delete(UpdatedUserList[0])
);
// Getting the final list
const FinalTweetsList = await (await TweetTable.getAll()).tweet;
console.log("APP: Final Tweets List", FinalTweetsList);
// Getting the final list
const FinalProfilesList = await (await ProfileTable.getAll()).profile;
console.log("APP: Final Profiles List", FinalProfilesList);
const FinalUserList = await (await UserTable.getAll(true)).users;
console.log("APP: Final Users List", FinalUserList);
};
executor()
.then()
.catch()
.finally(() => {
console.log("APP: Application Ended");
});