-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
553 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20240410082629_removed_virification_token_field/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `verificationToken` on the `User` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "User" DROP COLUMN "verificationToken"; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240410230439_working_hours_sum_field/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "EventAssignment" ADD COLUMN "hoursWorked" INTEGER; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240411123158_soft_delete_user/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "deletedAt" TIMESTAMP(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ import { | |
AccountType, | ||
ColorVariant, | ||
Event, | ||
EventAssignmentStatus, | ||
EventPresenceStatus, | ||
EventStatus, | ||
PrismaClient, | ||
SallaryType, | ||
|
@@ -30,11 +32,17 @@ const getRandomimage = () => | |
max: 1000 | ||
})}/1280/720`; | ||
|
||
const getRandomUser = (type: AccountType, n: number, email?: string) => { | ||
const getRandomUser = ( | ||
type: AccountType, | ||
n: number, | ||
email?: string, | ||
id?: string | ||
) => { | ||
return Array(n) | ||
.fill("") | ||
.map((_, i) => { | ||
return { | ||
id: id ? id : undefined, | ||
email: email ? email : faker.internet.email(), | ||
name: faker.person.fullName(), | ||
phoneNumber: faker.phone.number(), | ||
|
@@ -45,15 +53,18 @@ const getRandomUser = (type: AccountType, n: number, email?: string) => { | |
}); | ||
}; | ||
|
||
const getRandomEventData = () => { | ||
const getRandomEventData = (capacity?: number, id?: string) => { | ||
const sallaryType = faker.datatype.boolean() | ||
? SallaryType.GOODS | ||
: SallaryType.MONEY; | ||
|
||
const ret = { | ||
capacity: faker.number.int({ min: 5, max: 10 }), | ||
id: id ? id : undefined, | ||
capacity: capacity ? capacity : faker.number.int({ min: 5, max: 10 }), | ||
description: faker.commerce.productDescription(), | ||
happeningAt: faker.date.future(), | ||
happeningAt: moment(faker.date.soon()) | ||
.set("hour", faker.number.int({ min: 6, max: 10 })) | ||
.toDate(), | ||
name: faker.commerce.productName(), | ||
sallaryType: sallaryType, | ||
sallaryAmount: | ||
|
@@ -98,6 +109,21 @@ function slugify(title: string) { | |
.toLowerCase(); // Convert to lowercase | ||
} | ||
|
||
function generateNearbyCoordinate( | ||
centerLat: number, | ||
centerLon: number, | ||
radius = 0.1 | ||
) { | ||
return { | ||
latitude: | ||
centerLat + | ||
faker.number.float() * radius * (faker.datatype.boolean() ? 1 : -1), | ||
longitude: | ||
centerLon + | ||
faker.number.float() * radius * (faker.datatype.boolean() ? 1 : -1) | ||
}; | ||
} | ||
|
||
async function main() { | ||
const fruitsAndVegetablesEmojis: { | ||
emoji: string; | ||
|
@@ -150,23 +176,29 @@ async function main() { | |
|
||
await prisma.user.createMany({ | ||
data: [ | ||
...getRandomUser("ORGANISER", 1, "[email protected]"), | ||
...getRandomUser("ORGANISER", 1, "[email protected]"), | ||
...getRandomUser("ORGANISER", 1, "[email protected]") | ||
...getRandomUser("ORGANISER", 1, "[email protected]", "admin1"), | ||
...getRandomUser("ORGANISER", 1, "[email protected]", "admin2"), | ||
...getRandomUser("ORGANISER", 1, "[email protected]", "admin3") | ||
] | ||
}); | ||
const adminUsers = await prisma.user.findMany({ select: { id: true } }); | ||
|
||
await prisma.location.createMany({ | ||
data: Array(15) | ||
.fill("") | ||
.map((_, i) => ({ | ||
name: faker.company.name(), | ||
address: faker.location.streetAddress(), | ||
city: faker.location.city(), | ||
locationLat: faker.location.latitude({ max: 180, min: -180 }), | ||
locationLon: faker.location.longitude({ max: 180, min: -180 }) | ||
})) | ||
.map((_, i) => { | ||
const { latitude, longitude } = generateNearbyCoordinate( | ||
48.934328, | ||
18.160032 | ||
); | ||
return { | ||
name: faker.company.name(), | ||
address: faker.location.streetAddress(), | ||
city: faker.location.city(), | ||
locationLat: latitude, | ||
locationLon: longitude | ||
}; | ||
}) | ||
}); | ||
|
||
const locations = await prisma.location.findMany({ select: { id: true } }); | ||
|
@@ -193,7 +225,7 @@ async function main() { | |
{ length: faker.number.int({ min: 0, max: event.capacity }) }, | ||
async () => | ||
prisma.user.create({ | ||
data: getRandomUser("ORGANISER", 1)[0], | ||
data: getRandomUser("HARVESTER", 1)[0], | ||
select: { id: true } | ||
}) | ||
); | ||
|
@@ -248,7 +280,12 @@ async function main() { | |
}); | ||
|
||
const workerId = await prisma.user.create({ | ||
data: getRandomUser("ORGANISER", 1, "[email protected]")[0], | ||
data: getRandomUser( | ||
"HARVESTER", | ||
1, | ||
"[email protected]", | ||
"harvester1" | ||
)[0], | ||
select: { | ||
id: true | ||
} | ||
|
@@ -258,7 +295,11 @@ async function main() { | |
data: { | ||
userId: adminUsers[0].id, | ||
locationId: locations[0].id, | ||
...{ ...getRandomEventData(), status: "PROGRESS" } | ||
...{ | ||
...getRandomEventData(15, "liveEventId"), | ||
status: "PROGRESS", | ||
happeningAt: moment().set("hours", 7).toDate() | ||
} | ||
}, | ||
select: { | ||
id: true, | ||
|
@@ -278,7 +319,7 @@ async function main() { | |
|
||
const userIds = await Promise.all(userPromises); | ||
|
||
await Promise.all( | ||
const assignments = await Promise.all( | ||
userIds.map((user) => | ||
prisma.eventAssignment.create({ | ||
data: { | ||
|
@@ -296,6 +337,45 @@ async function main() { | |
} | ||
}); | ||
|
||
await Promise.all( | ||
assignments.map((assignment) => { | ||
const statusChangeTo = faker.helpers.arrayElement([ | ||
EventPresenceStatus.PRESENT, | ||
EventPresenceStatus.LEFT, | ||
EventPresenceStatus.DID_NOT_ARRIVE | ||
]); | ||
|
||
const arrivedAt = [ | ||
EventPresenceStatus.PRESENT.toString(), | ||
EventPresenceStatus.LEFT.toString() | ||
].includes(statusChangeTo) | ||
? moment(liveEvent.happeningAt) | ||
.add(faker.number.int({ min: 2, max: 45 }), "minutes") | ||
.toDate() | ||
: undefined; | ||
|
||
const leftAt = [EventPresenceStatus.LEFT.toString()].includes( | ||
statusChangeTo | ||
) | ||
? moment(arrivedAt) | ||
.add(faker.number.int({ min: 2, max: 12 }), "hours") | ||
.add(faker.number.int({ min: 2, max: 45 }), "minutes") | ||
.toDate() | ||
: undefined; | ||
|
||
return prisma.eventAssignment.update({ | ||
data: { | ||
presenceStatus: statusChangeTo, | ||
arrivedAt: arrivedAt, | ||
leftAt: leftAt | ||
}, | ||
where: { | ||
id: assignment.id | ||
} | ||
}); | ||
}) | ||
); | ||
|
||
await Promise.all( | ||
Array(5) | ||
.fill("") | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.