Compare commits
No commits in common. '3110dc9645c523aaf73927187283ab1781b25198' and 'ee10b49cf8a36a34bd0c44b722b9406f5b65f1d1' have entirely different histories.
3110dc9645
...
ee10b49cf8
21 changed files with 102 additions and 268 deletions
@ -1,43 +0,0 @@ |
|||||||
'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'); |
|
||||||
}, |
|
||||||
}; |
|
@ -1,56 +0,0 @@ |
|||||||
'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'); |
|
||||||
}, |
|
||||||
}; |
|
@ -1,41 +0,0 @@ |
|||||||
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,12 +1,16 @@ |
|||||||
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) { |
async getBalance(@Param("userId") userId: number): Promise<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