Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "bun",
"request": "attach",
"name": "[Bun] Backend",
"url": "ws://localhost:6499",
"localRoot": "${workspaceFolder}"
},
]
"version": "0.2.0",
"configurations": [
{
"type": "bun",
"request": "attach",
"name": "[Bun] Backend",
"url": "ws://localhost:6499",
"localRoot": "${workspaceFolder}"
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"manashield",
"manaspent",
"mariadb",
"mercadopago",
"miforge",
"mitg",
"mitgdev",
Expand Down Expand Up @@ -176,11 +177,13 @@
"roboto",
"safelist",
"serverinfo",
"serviceid",
"sessionkey",
"showrewardnews",
"SKRS",
"skulltime",
"stayloggedin",
"stonebar",
"synchronisation",
"tailwindcss",
"tanstack",
Expand All @@ -192,6 +195,7 @@
"tibiaclient",
"tibiacoin",
"tibiacointrusted",
"tibiora",
"Toplayers",
"torsocolor",
"tournamentticketpurchasestate",
Expand All @@ -212,6 +216,7 @@
"warid",
"wheeldata",
"worldid",
"xlarge",
"xpboost"
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- CreateTable
CREATE TABLE `miforge_shop_service` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`type` ENUM('COINS') NOT NULL,
`slug` VARCHAR(100) NOT NULL,
`title` VARCHAR(255) NOT NULL,
`description` TEXT NULL,
`price` INTEGER UNSIGNED NOT NULL DEFAULT 0,
`quantity` INTEGER UNSIGNED NOT NULL DEFAULT 1,
`is_active` BOOLEAN NOT NULL DEFAULT true,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

UNIQUE INDEX `miforge_shop_service_slug_key`(`slug`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `miforge_shop_transactions` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`status` ENUM('PENDING', 'COMPLETED', 'FAILED', 'CANCELED', 'REFUNDED') NOT NULL DEFAULT 'PENDING',
`method` ENUM('MERCADO_PAGO_PIX') NOT NULL,
`units` INTEGER UNSIGNED NOT NULL DEFAULT 1,
`total` INTEGER UNSIGNED NOT NULL DEFAULT 0,
`service_id` INTEGER UNSIGNED NOT NULL,
`account_id` INTEGER UNSIGNED NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `miforge_shop_transactions` ADD CONSTRAINT `miforge_shop_transactions_service_id_fkey` FOREIGN KEY (`service_id`) REFERENCES `miforge_shop_service`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `miforge_shop_transactions` ADD CONSTRAINT `miforge_shop_transactions_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:

- You are about to drop the column `price` on the `miforge_shop_service` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE `miforge_shop_service` DROP COLUMN `price`,
ADD COLUMN `unit_price` INTEGER UNSIGNED NOT NULL DEFAULT 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `miforge_shop_transactions` ADD COLUMN `method_transaction_id` VARCHAR(255) NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Warnings:

- The values [MERCADO_PAGO_PIX] on the enum `miforge_shop_transactions_method` will be removed. If these variants are still used in the database, this will fail.
- Added the required column `provider` to the `miforge_shop_transactions` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE `miforge_shop_transactions` ADD COLUMN `provider` ENUM('MERCADO_PAGO') NOT NULL,
MODIFY `method` ENUM('PIX') NOT NULL;

-- CreateIndex
CREATE INDEX `idx_service_account_provider` ON `miforge_shop_transactions`(`service_id`, `account_id`);

-- CreateIndex
CREATE INDEX `idx_method_transaction_id` ON `miforge_shop_transactions`(`method_transaction_id`);

-- CreateIndex
CREATE INDEX `idx_status` ON `miforge_shop_transactions`(`status`);

-- CreateIndex
CREATE INDEX `idx_provider` ON `miforge_shop_transactions`(`provider`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Warnings:

- You are about to drop the column `method` on the `miforge_shop_transactions` table. All the data in the column will be lost.
- You are about to drop the column `provider` on the `miforge_shop_transactions` table. All the data in the column will be lost.
- Added the required column `provider_id` to the `miforge_shop_transactions` table without a default value. This is not possible if the table is not empty.

*/
-- DropIndex
DROP INDEX `idx_provider` ON `miforge_shop_transactions`;

-- AlterTable
ALTER TABLE `miforge_shop_transactions` DROP COLUMN `method`,
DROP COLUMN `provider`,
ADD COLUMN `provider_id` INTEGER UNSIGNED NOT NULL;

-- CreateTable
CREATE TABLE `miforge_shop_providers` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`description` TEXT NULL,
`method` ENUM('PIX') NOT NULL,
`provider` ENUM('MERCADO_PAGO') NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

UNIQUE INDEX `miforge_shop_providers_method_provider_key`(`method`, `provider`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `miforge_shop_transactions` ADD CONSTRAINT `miforge_shop_transactions_provider_id_fkey` FOREIGN KEY (`provider_id`) REFERENCES `miforge_shop_providers`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `miforge_shop_providers` ADD COLUMN `is_active` BOOLEAN NOT NULL DEFAULT true;
1 change: 1 addition & 0 deletions apps/api/prisma/models/base.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ model accounts {
audits miforge_account_audit[]
confirmations miforge_account_confirmations[]
oauths miforge_account_oauths[]
transactions miforge_shop_transactions[]

two_factor_enabled Boolean @default(false)
two_factor_secret String? @db.VarChar(64)
Expand Down
80 changes: 80 additions & 0 deletions apps/api/prisma/models/shop.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
enum ShopServiceType {
COINS
}

model miforge_shop_service {
id Int @id @default(autoincrement()) @db.UnsignedInt
type ShopServiceType
slug String @unique @db.VarChar(100)
title String @db.VarChar(255)
description String? @db.Text

transactions miforge_shop_transactions[]

unit_price Int @default(0) @db.UnsignedInt
quantity Int @default(1) @db.UnsignedInt
is_active Boolean @default(true)

created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
}

enum ShopTransactionStatus {
PENDING
COMPLETED
FAILED
CANCELED
REFUNDED
}

enum ShopProviderMethod {
PIX
}

enum ShopProvider {
MERCADO_PAGO
}

model miforge_shop_providers {
id Int @id @default(autoincrement()) @db.UnsignedInt

name String @db.VarChar(100)
description String? @db.Text
isActive Boolean @default(true) @map("is_active")

method ShopProviderMethod
provider ShopProvider

transactions miforge_shop_transactions[]

created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt

@@unique([method, provider], name: "uniq_method_provider")
}

model miforge_shop_transactions {
id Int @id @default(autoincrement()) @db.UnsignedInt

status ShopTransactionStatus @default(PENDING)
methodTransactionId String? @map("method_transaction_id") @db.VarChar(255)

units Int @default(1) @db.UnsignedInt
total Int @default(0) @db.UnsignedInt

providerId Int @map("provider_id") @db.UnsignedInt
provider miforge_shop_providers @relation(fields: [providerId], references: [id], onDelete: Cascade)

serviceId Int @map("service_id") @db.UnsignedInt
service miforge_shop_service @relation(fields: [serviceId], references: [id], onDelete: Cascade)

accountId Int @map("account_id") @db.UnsignedInt
account accounts @relation(fields: [accountId], references: [id], onDelete: Cascade)

created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt

@@index([serviceId, accountId], name: "idx_service_account_provider")
@@index([methodTransactionId], name: "idx_method_transaction_id")
@@index([status], name: "idx_status")
}
76 changes: 75 additions & 1 deletion apps/api/prisma/seed/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { env } from '@/infra/env'
import {PrismaClient} from 'generated/client'
import {PrismaClient, type miforge_shop_service} from 'generated/client'
import {PrismaMariaDb} from "@prisma/adapter-mariadb"
import crypto from "node:crypto";
import { MiforgeConfigSchema } from '@/shared/schemas/Config';
Expand Down Expand Up @@ -39,13 +39,60 @@ const miforgeConfig = MiforgeConfigSchema.decode({
discord: {
enabled: Boolean(env.DISCORD_ENABLED)
},
mercado_pago: {
enabled: Boolean(env.MERCADO_PAGO_ENABLED)
},
account: {
emailConfirmationRequired: Boolean(env.MAILER_PROVIDER),
emailChangeConfirmationRequired: Boolean(env.MAILER_PROVIDER),
passwordResetConfirmationRequired: Boolean(env.MAILER_PROVIDER)
}
})

const DEFAULT_SHOP_SERVICES: Pick<miforge_shop_service, "title" | "slug" | "unit_price" | "quantity" | "description" | "type">[] = [{
type: "COINS",
title: "250 Coins",
slug: "250-coins",
unit_price: 10, // cents = 0.10 = 10/100 = 0.1
quantity: 250,
description: null
}, {
type: "COINS",
title: "750 Coins",
slug: "750-coins",
unit_price: 10,
quantity: 750,
description: null
}, {
type: "COINS",
title: "1500 Coins",
slug: "1500-coins",
unit_price: 10,
quantity: 1500,
description: null
}, {
type: "COINS",
title: "3000 Coins",
slug: "3000-coins",
unit_price: 10,
quantity: 3000,
description: null
}, {
type: "COINS",
title: "4000 Coins",
slug: "4000-coins",
unit_price: 10,
quantity: 4000,
description: null
}, {
type: "COINS",
title: "12000 Coins",
slug: "12000-coins",
unit_price: 10,
quantity: 12000,
description: null
}]

async function main() {
console.log("[seed] Seeding miforge_configs")
await prisma.miforge_config.upsert({
Expand All @@ -61,6 +108,33 @@ async function main() {
}
})

console.log("[seed] Seeding default shop services")
for (const service of DEFAULT_SHOP_SERVICES) {
await prisma.miforge_shop_service.upsert({
where: {
slug: service.slug
},
create: service,
update: service
})
}

console.log("[seed] Seeding default payment providers")
await prisma.miforge_shop_providers.upsert({
where: {
uniq_method_provider: {
method: "PIX",
provider: "MERCADO_PAGO"
}
},
create: {
method: "PIX",
provider: "MERCADO_PAGO",
name: "Mercado Pago PIX"
},
update: {}
})

for (const config of server_configs) {
const existing = await prisma.server_config.findUnique({
where: {
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/application/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ export * from "./accountTwoFactor";
export * from "./audit";
export * from "./config";
export * from "./lostAccount";
export * from "./mercadoPago";
export * from "./players";
export * from "./recoveryKey";
export * from "./session";
export * from "./shop";
export * from "./tibiaclient";
export * from "./worlds";
Loading