Skip to content

Commit 6d01dfa

Browse files
authored
Merge pull request #190 from chingu-x/fix/update-seed
Fix/update seed
2 parents e90d92c + 71df55d commit 6d01dfa

File tree

7 files changed

+61
-26
lines changed

7 files changed

+61
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Another example [here](https://co-pilot.dev/changelog)
106106
- Fix form responses giving error and not inserting values when the boolean value is false ([#156](https://github.com/chingu-x/chingu-dashboard-be/pull/156))
107107
- Fix a bug for check on voyageTeamMemberId ([#159](https://github.com/chingu-x/chingu-dashboard-be/pull/159))
108108
- Fix users unit test failing due to a schema change
109+
- Fix seed data for alpha test (check in form question changes, gravatar) ([#190](https://github.com/chingu-x/chingu-dashboard-be/pull/190))
109110

110111
### Removed
111112

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[name]` on the table `OAuthProvider` will be added. If there are existing duplicate values, this will fail.
5+
6+
*/
7+
-- CreateIndex
8+
CREATE UNIQUE INDEX "OAuthProvider_name_key" ON "OAuthProvider"("name");

prisma/production-seed/users.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { prisma } from "../seed/prisma-client";
22
import { hashPassword } from "../../src/utils/auth";
33
import { getRoleId } from "../seed/users";
4+
import { generateGravatarUrl } from "../seed/utils";
45

56
export const populateUsersProd = async () => {
67
const roles = await prisma.role.findMany({});
@@ -13,7 +14,7 @@ export const populateUsersProd = async () => {
1314
emailVerified: true,
1415
firstName: "Admin",
1516
lastName: "Surname",
16-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
17+
avatar: generateGravatarUrl("admin@example.com"),
1718
timezone: "US/Central",
1819
countryCode: "US",
1920
},
@@ -34,7 +35,7 @@ export const populateUsersProd = async () => {
3435
emailVerified: true,
3536
firstName: "Jim",
3637
lastName: "PO",
37-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
38+
avatar: generateGravatarUrl("jim@example.com"),
3839
timezone: "US/Central",
3940
countryCode: "US",
4041
},
@@ -54,7 +55,7 @@ export const populateUsersProd = async () => {
5455
emailVerified: true,
5556
firstName: "Razieh",
5657
lastName: "PO",
57-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
58+
avatar: generateGravatarUrl("razieh@example.com"),
5859
timezone: "Europe/Madrid",
5960
countryCode: "ES",
6061
},
@@ -74,7 +75,7 @@ export const populateUsersProd = async () => {
7475
emailVerified: true,
7576
firstName: "Mladen",
7677
lastName: "PO",
77-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
78+
avatar: generateGravatarUrl("mladen@example.com"),
7879
timezone: "Europe/Madrid",
7980
countryCode: "ES",
8081
},
@@ -96,7 +97,7 @@ export const populateUsersProd = async () => {
9697
emailVerified: true,
9798
firstName: "Eury",
9899
lastName: "Design",
99-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
100+
avatar: generateGravatarUrl("eury@example.com"),
100101
timezone: "US/Central",
101102
countryCode: "US",
102103
},
@@ -116,7 +117,7 @@ export const populateUsersProd = async () => {
116117
emailVerified: true,
117118
firstName: "Joe",
118119
lastName: "Design",
119-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
120+
avatar: generateGravatarUrl("joe@example.com"),
120121
timezone: "US/Central",
121122
countryCode: "US",
122123
},
@@ -136,7 +137,7 @@ export const populateUsersProd = async () => {
136137
emailVerified: true,
137138
firstName: "Joseph",
138139
lastName: "Design",
139-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
140+
avatar: generateGravatarUrl("joseph@example.com"),
140141
timezone: "America/Lima",
141142
countryCode: "PE",
142143
},
@@ -156,7 +157,7 @@ export const populateUsersProd = async () => {
156157
emailVerified: true,
157158
firstName: "Austin",
158159
lastName: "Design",
159-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
160+
avatar: generateGravatarUrl("austin@example.com"),
160161
timezone: "US/Pacific",
161162
countryCode: "US",
162163
},
@@ -178,7 +179,7 @@ export const populateUsersProd = async () => {
178179
emailVerified: true,
179180
firstName: "Dan",
180181
lastName: "Frontend",
181-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
182+
avatar: generateGravatarUrl("dan@example.com"),
182183
timezone: "US/Eastern",
183184
countryCode: "US",
184185
},
@@ -198,7 +199,7 @@ export const populateUsersProd = async () => {
198199
emailVerified: true,
199200
firstName: "Jane",
200201
lastName: "Frontend",
201-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
202+
avatar: generateGravatarUrl("jane@example.com"),
202203
timezone: "Asia/Tbilisi",
203204
countryCode: "GE",
204205
},
@@ -218,7 +219,7 @@ export const populateUsersProd = async () => {
218219
emailVerified: true,
219220
firstName: "Timothy",
220221
lastName: "Frontend",
221-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
222+
avatar: generateGravatarUrl("timothy@example.com"),
222223
timezone: "Europe/Rome",
223224
countryCode: "IT",
224225
},
@@ -238,7 +239,7 @@ export const populateUsersProd = async () => {
238239
emailVerified: true,
239240
firstName: "Winnie",
240241
lastName: "Frontend",
241-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
242+
avatar: generateGravatarUrl("winnie@example.com"),
242243
timezone: "US/Central",
243244
countryCode: "US",
244245
},
@@ -260,7 +261,7 @@ export const populateUsersProd = async () => {
260261
emailVerified: true,
261262
firstName: "Cheryl",
262263
lastName: "Backend",
263-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
264+
avatar: generateGravatarUrl("cheryl@example.com"),
264265
timezone: "Australia/Melbourne",
265266
countryCode: "AU",
266267
},
@@ -280,7 +281,7 @@ export const populateUsersProd = async () => {
280281
emailVerified: true,
281282
firstName: "Curt",
282283
lastName: "Backend",
283-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
284+
avatar: generateGravatarUrl("curt@example.com"),
284285
timezone: "US/Central",
285286
countryCode: "US",
286287
},
@@ -300,7 +301,7 @@ export const populateUsersProd = async () => {
300301
emailVerified: true,
301302
firstName: "Josh",
302303
lastName: "Backend",
303-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
304+
avatar: generateGravatarUrl("josh@example.com"),
304305
timezone: "US/Pacific",
305306
countryCode: "US",
306307
},
@@ -320,7 +321,7 @@ export const populateUsersProd = async () => {
320321
emailVerified: true,
321322
firstName: "Tim",
322323
lastName: "Backend",
323-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
324+
avatar: generateGravatarUrl("tim@example.com"),
324325
timezone: "US/Central",
325326
countryCode: "US",
326327
},
@@ -340,7 +341,7 @@ export const populateUsersProd = async () => {
340341
emailVerified: true,
341342
firstName: "Arman",
342343
lastName: "Backend",
343-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
344+
avatar: generateGravatarUrl("arman@example.com"),
344345
timezone: "Asia/Kolkata",
345346
countryCode: "IN",
346347
},

prisma/schema/user.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ model UserRole {
6565

6666
model OAuthProvider {
6767
id Int @id @default(autoincrement())
68-
name String
68+
name String @unique
6969
7070
createdAt DateTime @default(now()) @db.Timestamptz()
7171
updatedAt DateTime @updatedAt

prisma/seed/forms/checkinform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export const populateCheckinForm = async () => {
235235
},
236236
},
237237
text: "Is there anything else you'd like to tell us about your Voyage Guide?",
238-
answerRequired: true,
238+
answerRequired: false,
239239
},
240240
{
241241
order: 12,

prisma/seed/users.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { hashPassword } from "../../src/utils/auth";
22
import { prisma } from "./prisma-client";
3+
import { generateGravatarUrl } from "./utils";
34

45
export const getRoleId = (roles, name) => {
56
return roles.filter((role) => role.name == name)[0].id;
@@ -15,14 +16,30 @@ export const populateUsers = async () => {
1516
emailVerified: true,
1617
firstName: "Jessica",
1718
lastName: "Williamson",
18-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
19+
avatar: generateGravatarUrl("jessica.williamson@gmail.com"),
1920
timezone: "Australia/Melbourne",
2021
countryCode: "AU",
2122
gender: {
2223
connect: {
2324
abbreviation: "F",
2425
},
2526
},
27+
oAuthProfiles: {
28+
create: {
29+
providerUserId: "1234567",
30+
providerUsername: "jessica-discord",
31+
provider: {
32+
connectOrCreate: {
33+
where: {
34+
name: "discord",
35+
},
36+
create: {
37+
name: "discord",
38+
},
39+
},
40+
},
41+
},
42+
},
2643
},
2744
});
2845

@@ -47,7 +64,7 @@ export const populateUsers = async () => {
4764
emailVerified: true,
4865
firstName: "Larry",
4966
lastName: "Castro",
50-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=monsterid&r=x",
67+
avatar: generateGravatarUrl("l.castro@outlook.com"),
5168
timezone: "America/Chicago",
5269
comment: "Member seems to be inactive",
5370
countryCode: "US",
@@ -80,7 +97,7 @@ export const populateUsers = async () => {
8097
emailVerified: true,
8198
firstName: "Leonarda",
8299
lastName: "Rowe",
83-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=identicon&r=x",
100+
avatar: generateGravatarUrl("leo.rowe@outlook.com"),
84101
timezone: "America/Los_Angeles",
85102
comment: "This is a random admin comment",
86103
countryCode: "US",
@@ -106,7 +123,7 @@ export const populateUsers = async () => {
106123
emailVerified: true,
107124
firstName: "Joso",
108125
lastName: "Mađar",
109-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x",
126+
avatar: generateGravatarUrl("JosoMadar@dayrep.com"),
110127
timezone: "Europe/Zagreb",
111128
comment: "This is a random admin comment",
112129
countryCode: "HR",
@@ -127,7 +144,7 @@ export const populateUsers = async () => {
127144
emailVerified: true,
128145
firstName: "Dan",
129146
lastName: "Ko",
130-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x",
147+
avatar: generateGravatarUrl("dan@random.com"),
131148
timezone: "America/Los_Angeles",
132149
comment: "No comment",
133150
countryCode: "US",
@@ -148,7 +165,7 @@ export const populateUsers = async () => {
148165
emailVerified: true,
149166
firstName: "Not in a voyage",
150167
lastName: "Voyage",
151-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x",
168+
avatar: generateGravatarUrl("not_in_voyage@example.com"),
152169
timezone: "America/New_York",
153170
comment:
154171
"This user is not in a voyage - does not have the 'voyager' role",
@@ -163,7 +180,7 @@ export const populateUsers = async () => {
163180
emailVerified: false,
164181
firstName: "Yoshi",
165182
lastName: "Amano",
166-
avatar: "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x",
183+
avatar: generateGravatarUrl("yoshi@gmail.com"),
167184
timezone: "Australia/Melbourne",
168185
countryCode: "AU",
169186
gender: {

prisma/seed/utils/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { prisma } from "../prisma-client";
2+
import * as crypto from "crypto";
23

34
export const addDays = (date, days: number) => {
45
const newDate = new Date(date);
@@ -26,3 +27,10 @@ export const getRandomDateDuringSprint = async (sprintId) => {
2627
});
2728
return addDays(sprint?.startDate, Math.floor(Math.random() * 6));
2829
};
30+
31+
export const generateGravatarUrl = (email: string = "noemail@example.com") => {
32+
const themes = ["identicon", "monsterid", "wavatar", "retro", "robohash"];
33+
const hash = crypto.createHash("sha256").update(email).digest("hex");
34+
return `https://gravatar.com/avatar/${hash}?s=200&r=g&d=${themes[Math.floor(Math.random() * themes.length)]}
35+
`;
36+
};

0 commit comments

Comments
 (0)