parent
871fda173b
commit
3110dc9645
8 changed files with 141 additions and 21 deletions
@ -0,0 +1,56 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
up: async (queryInterface, Sequelize) => { |
||||||
|
await queryInterface.dropTable("Payments", { cascade: true }); |
||||||
|
await queryInterface.createTable('Payments', { |
||||||
|
id: { |
||||||
|
type: Sequelize.INTEGER, |
||||||
|
autoIncrement: true, |
||||||
|
primaryKey: true, |
||||||
|
allowNull: false, |
||||||
|
}, |
||||||
|
userId: { |
||||||
|
type: Sequelize.INTEGER, |
||||||
|
allowNull: false, |
||||||
|
references: { |
||||||
|
model: 'Users',
|
||||||
|
key: 'id', |
||||||
|
}, |
||||||
|
onDelete: 'CASCADE', |
||||||
|
}, |
||||||
|
walletId: { |
||||||
|
type: Sequelize.INTEGER, |
||||||
|
allowNull: false, |
||||||
|
references: { |
||||||
|
model: 'Wallets',
|
||||||
|
key: 'id', |
||||||
|
}, |
||||||
|
onDelete: 'CASCADE', |
||||||
|
}, |
||||||
|
paymentAmount: { |
||||||
|
type: Sequelize.INTEGER, |
||||||
|
allowNull: false, |
||||||
|
}, |
||||||
|
status: { |
||||||
|
type: Sequelize.ENUM('completed', 'failed'), |
||||||
|
allowNull: false, |
||||||
|
defaultValue: 'failed', |
||||||
|
}, |
||||||
|
paymentDate: { |
||||||
|
type: Sequelize.DATE, |
||||||
|
allowNull: false, |
||||||
|
defaultValue: Sequelize.fn('NOW'), |
||||||
|
}, |
||||||
|
updatedAt: { |
||||||
|
type: Sequelize.DATE, |
||||||
|
allowNull: false, |
||||||
|
defaultValue: Sequelize.fn('NOW'), |
||||||
|
}, |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
down: async (queryInterface, Sequelize) => { |
||||||
|
await queryInterface.dropTable('Payments'); |
||||||
|
}, |
||||||
|
}; |
@ -0,0 +1,41 @@ |
|||||||
|
import { BelongsTo, Column, DataType, ForeignKey, Model, Table } from "sequelize-typescript"; |
||||||
|
import { User } from "src/users/entities/user.entity"; |
||||||
|
import { Wallet } from "src/wallet/entities/wallet.entity"; |
||||||
|
|
||||||
|
@Table |
||||||
|
export class Payment extends Model<Payment> { |
||||||
|
@ForeignKey(() => User) |
||||||
|
@Column |
||||||
|
userId: number; |
||||||
|
|
||||||
|
@BelongsTo(() => User, { onDelete: "CASCADE" }) |
||||||
|
user: User; |
||||||
|
|
||||||
|
@ForeignKey(() => Wallet) |
||||||
|
@Column |
||||||
|
walletId: number; |
||||||
|
|
||||||
|
@BelongsTo(() => Wallet, { onDelete: "CASCADE" }) |
||||||
|
wallet: Wallet; |
||||||
|
|
||||||
|
@Column({ |
||||||
|
type: DataType.INTEGER, |
||||||
|
allowNull: false, |
||||||
|
}) |
||||||
|
paymentAmount: number; |
||||||
|
|
||||||
|
|
||||||
|
@Column({ |
||||||
|
type: DataType.ENUM( "completed", "failed",), |
||||||
|
allowNull: false, |
||||||
|
defaultValue: "failed", |
||||||
|
}) |
||||||
|
status: string; |
||||||
|
|
||||||
|
@Column({ |
||||||
|
type: DataType.DATE, |
||||||
|
allowNull: false, |
||||||
|
defaultValue: DataType.NOW, |
||||||
|
}) |
||||||
|
paymentDate: Date; |
||||||
|
} |
@ -1,16 +1,12 @@ |
|||||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from "@nestjs/common"; |
import { Controller, Get, Post, Body, Patch, Param, Delete } from "@nestjs/common"; |
||||||
import { WalletService } from "./wallet.service"; |
import { WalletService } from "./wallet.service"; |
||||||
import { AddBalanceResponse } from "./add-balance-response.interface"; |
|
||||||
|
|
||||||
@Controller("wallet") |
@Controller("wallet") |
||||||
export class WalletController { |
export class WalletController { |
||||||
constructor(private readonly walletService: WalletService) {} |
constructor(private readonly walletService: WalletService) {} |
||||||
@Get(":userId") |
@Get(":userId") |
||||||
async getBalance(@Param("userId") userId: number): Promise<number> { |
async getBalance(@Param("userId") userId: number) { |
||||||
return this.walletService.getBalance(userId); |
return this.walletService.getBalance(userId); |
||||||
} |
} |
||||||
@Post(":userId/add") |
|
||||||
async addBalance(@Param("userId") userId: number, @Body("amount") amount: number): Promise<AddBalanceResponse> { |
|
||||||
return this.walletService.addBalance(userId, amount); |
|
||||||
} |
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue