Compare commits
3 Commits
ee10b49cf8
...
3110dc9645
Author | SHA1 | Date |
---|---|---|
|
3110dc9645 | 2 months ago |
|
871fda173b | 2 months ago |
|
d0cb571c40 | 2 months ago |
21 changed files with 268 additions and 102 deletions
@ -0,0 +1,43 @@ |
||||
'use strict'; |
||||
|
||||
module.exports = { |
||||
up: async (queryInterface, Sequelize) => { |
||||
await queryInterface.dropTable("Wallets", { cascade: true }); |
||||
await queryInterface.createTable('Wallets', { |
||||
id: { |
||||
type: Sequelize.INTEGER, |
||||
autoIncrement: true, |
||||
primaryKey: true, |
||||
allowNull: false, |
||||
}, |
||||
userId: { |
||||
type: Sequelize.INTEGER, |
||||
allowNull: false, |
||||
references: { |
||||
model: 'Users', |
||||
key: 'id', |
||||
}, |
||||
onDelete: 'CASCADE',
|
||||
}, |
||||
balance: { |
||||
type: Sequelize.INTEGER, |
||||
allowNull: false, |
||||
defaultValue: 0,
|
||||
}, |
||||
createdAt: { |
||||
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('Wallets'); |
||||
}, |
||||
}; |
@ -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 { WalletService } from "./wallet.service"; |
||||
import { AddBalanceResponse } from "./add-balance-response.interface"; |
||||
|
||||
@Controller("wallet") |
||||
export class WalletController { |
||||
constructor(private readonly walletService: WalletService) {} |
||||
@Get(":userId") |
||||
async getBalance(@Param("userId") userId: number): Promise<number> { |
||||
async getBalance(@Param("userId") userId: number) { |
||||
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