-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add transaction entity to store payment information (#45)
feat: add transaction entity to store payment information
- Loading branch information
Showing
4 changed files
with
160 additions
and
24 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
15 changes: 15 additions & 0 deletions
15
prisma/migrations/20211225043237_add_transaction_table/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,15 @@ | ||
-- CreateTable | ||
CREATE TABLE "Transaction" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" DATETIME NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"subscriptionId" TEXT NOT NULL, | ||
"bankName" TEXT NOT NULL, | ||
"bankAccountNumber" TEXT NOT NULL, | ||
"bankAccountName" TEXT NOT NULL, | ||
"amount" INTEGER NOT NULL, | ||
"status" TEXT NOT NULL, | ||
CONSTRAINT "Transaction_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT "Transaction_subscriptionId_fkey" FOREIGN KEY ("subscriptionId") REFERENCES "Subscription" ("id") ON DELETE CASCADE ON UPDATE CASCADE | ||
); |
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 |
---|---|---|
@@ -1,16 +1,102 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
import { ROLES } from '../app/models/enum' | ||
import { | ||
ROLES, | ||
SUBSCRIPTION_STATUS, | ||
TRANSACTION_STATUS, | ||
} from '../app/models/enum' | ||
|
||
const prisma = new PrismaClient() | ||
|
||
async function main() { | ||
await Promise.all( | ||
getUsers().map((user) => | ||
prisma.user.create({ | ||
data: user, | ||
// update or insert user with admin role | ||
await prisma.user.upsert({ | ||
where: { email: '[email protected]' }, | ||
update: {}, | ||
create: { | ||
email: '[email protected]', | ||
name: 'Zain', | ||
phoneNumber: '+6512345678', | ||
role: ROLES.ADMIN, | ||
}, | ||
}) | ||
|
||
// update or insert user with author role | ||
const author = await prisma.user.upsert({ | ||
where: { email: '[email protected]' }, | ||
update: {}, | ||
create: { | ||
email: '[email protected]', | ||
name: 'Vika', | ||
role: ROLES.AUTHOR, | ||
}, | ||
}) | ||
|
||
// update or insert user with member role | ||
const member = await prisma.user.upsert({ | ||
where: { email: '[email protected]' }, | ||
update: {}, | ||
create: { | ||
email: '[email protected]', | ||
name: 'Pejuang Kode', | ||
role: ROLES.MEMBER, | ||
}, | ||
}) | ||
|
||
// create courses | ||
const courses = await Promise.all( | ||
getCourse().map((course) => | ||
prisma.course.create({ | ||
data: { | ||
authorId: author.id, | ||
...course, | ||
}, | ||
}) | ||
) | ||
) | ||
|
||
// create subscription | ||
const subscription1 = await prisma.subscription.create({ | ||
data: { | ||
userId: member.id, | ||
courseId: courses[0].id, | ||
status: SUBSCRIPTION_STATUS.ACTIVE, | ||
}, | ||
}) | ||
|
||
// create subscription | ||
const subscription2 = await prisma.subscription.create({ | ||
data: { | ||
userId: member.id, | ||
courseId: courses[1].id, | ||
status: SUBSCRIPTION_STATUS.ACTIVE, | ||
}, | ||
}) | ||
|
||
// create transaction with status SUBMITTED | ||
await prisma.transaction.create({ | ||
data: { | ||
userId: member.id, | ||
subscriptionId: subscription1.id, | ||
bankName: 'Bank Mandiri', | ||
bankAccountName: 'Pejuang Kode', | ||
bankAccountNumber: '123456789', | ||
amount: 25000, | ||
status: TRANSACTION_STATUS.SUBMITTED, | ||
}, | ||
}) | ||
|
||
// create transaction with status VERIFIED | ||
await prisma.transaction.create({ | ||
data: { | ||
userId: member.id, | ||
subscriptionId: subscription2.id, | ||
bankName: 'Bank Mandiri', | ||
bankAccountName: 'Pejuang Kode', | ||
bankAccountNumber: '123456789', | ||
amount: 50000, | ||
status: TRANSACTION_STATUS.VERIFIED, | ||
}, | ||
}) | ||
} | ||
|
||
main() | ||
|
@@ -22,23 +108,31 @@ main() | |
await prisma.$disconnect() | ||
}) | ||
|
||
function getUsers() { | ||
function getCourse() { | ||
return [ | ||
{ | ||
email: '[email protected]', | ||
name: 'Zain', | ||
phoneNumber: '+6512345678', | ||
role: ROLES.ADMIN, | ||
name: 'Menumbuhkan Minat Baca Anak', | ||
description: | ||
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", | ||
price: 25000, | ||
image: 'https://picsum.photos/id/1073/1200/800', | ||
category: 'Parenting', | ||
}, | ||
{ | ||
email: '[email protected]', | ||
name: 'Vika', | ||
role: ROLES.AUTHOR, | ||
name: 'Mengelola Konflik dalam Keluarga', | ||
description: | ||
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", | ||
price: 50000, | ||
image: 'https://picsum.photos/id/146/1200/800', | ||
category: 'Parenting', | ||
}, | ||
{ | ||
email: '[email protected]', | ||
name: 'Pejuang Kode', | ||
role: ROLES.MEMBER, | ||
name: 'Menumbuhkan Rasa Percaya Diri Sejak Dini', | ||
description: | ||
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", | ||
price: 100000, | ||
image: 'https://picsum.photos/id/1001/1200/800', | ||
category: 'Parenting', | ||
}, | ||
] | ||
} |