Compare commits
No commits in common. '7d8998b2f19889b20c78938c0bc260a781761516' and '3591ae91397347e53a449b00c390aa63d3264e68' have entirely different histories.
7d8998b2f1
...
3591ae9139
21 changed files with 122 additions and 525 deletions
@ -1,69 +1,63 @@ |
|||||||
'use strict'; |
'use strict'; |
||||||
|
|
||||||
|
/** @type {import('sequelize-cli').Migration} */ |
||||||
module.exports = { |
module.exports = { |
||||||
up: async (queryInterface, Sequelize) => { |
async up(queryInterface, Sequelize) { |
||||||
await queryInterface.dropTable('Users', { cascade: true }); |
await queryInterface.dropTable('Users',{cascade:true}) |
||||||
await queryInterface.createTable('Users', { |
await queryInterface.createTable('Users', { |
||||||
id: { |
id: { |
||||||
type: Sequelize.INTEGER, |
allowNull: false, |
||||||
autoIncrement: true, |
autoIncrement: true, |
||||||
primaryKey: true, |
primaryKey: true, |
||||||
allowNull: false, |
type: Sequelize.INTEGER |
||||||
}, |
}, |
||||||
email: { |
email: { |
||||||
type: Sequelize.STRING, |
type: Sequelize.STRING, |
||||||
unique: true, |
unique: true, |
||||||
allowNull: false, |
allowNull: false |
||||||
}, |
}, |
||||||
password: { |
password: { |
||||||
type: Sequelize.STRING, |
type: Sequelize.STRING, |
||||||
allowNull: false, |
allowNull: false |
||||||
}, |
}, |
||||||
role: { |
role: { |
||||||
type: Sequelize.STRING, |
type: Sequelize.STRING, |
||||||
allowNull: false, |
defaultValue: 'user' |
||||||
defaultValue: 'user', |
|
||||||
}, |
}, |
||||||
firstName: { |
firstName: { |
||||||
type: Sequelize.STRING, |
type: Sequelize.STRING, |
||||||
allowNull: true, |
allowNull: false |
||||||
}, |
}, |
||||||
lastName: { |
lastName: { |
||||||
type: Sequelize.STRING, |
type: Sequelize.STRING, |
||||||
allowNull: true, |
allowNull: false |
||||||
}, |
}, |
||||||
username: { |
username: { |
||||||
type: Sequelize.STRING, |
type: Sequelize.STRING, |
||||||
unique: true, |
unique: true, |
||||||
allowNull: false, |
allowNull: false |
||||||
}, |
}, |
||||||
phoneNumber: { |
phoneNumber: { |
||||||
type: Sequelize.STRING, |
type: Sequelize.STRING, |
||||||
unique: true, |
unique: true, |
||||||
allowNull: false, |
allowNull: false |
||||||
}, |
}, |
||||||
gender: { |
gender: { |
||||||
type: Sequelize.ENUM('male', 'female'), |
type: Sequelize.ENUM("male", "female"), |
||||||
allowNull: false, |
allowNull: false |
||||||
}, |
|
||||||
refreshToken: { |
|
||||||
type: Sequelize.STRING, |
|
||||||
allowNull: true, |
|
||||||
}, |
}, |
||||||
createdAt: { |
createdAt: { |
||||||
type: Sequelize.DATE, |
|
||||||
allowNull: false, |
allowNull: false, |
||||||
defaultValue: Sequelize.fn('NOW'), |
type: Sequelize.DATE |
||||||
}, |
}, |
||||||
updatedAt: { |
updatedAt: { |
||||||
type: Sequelize.DATE, |
|
||||||
allowNull: false, |
allowNull: false, |
||||||
defaultValue: Sequelize.fn('NOW'), |
type: Sequelize.DATE |
||||||
}, |
} |
||||||
}); |
}); |
||||||
}, |
}, |
||||||
|
|
||||||
down: async (queryInterface, Sequelize) => { |
async down(queryInterface, Sequelize) { |
||||||
await queryInterface.dropTable('Users'); |
await queryInterface.dropTable('Users'); |
||||||
}, |
} |
||||||
}; |
}; |
||||||
|
@ -1,43 +0,0 @@ |
|||||||
'use strict'; |
|
||||||
|
|
||||||
module.exports = { |
|
||||||
up: async (queryInterface, Sequelize) => { |
|
||||||
await queryInterface.dropTable("Transactions", { cascade: true }); |
|
||||||
await queryInterface.createTable('Transactions', { |
|
||||||
id: { |
|
||||||
type: Sequelize.INTEGER, |
|
||||||
autoIncrement: true, |
|
||||||
primaryKey: true, |
|
||||||
allowNull: false, |
|
||||||
}, |
|
||||||
walletId: { |
|
||||||
type: Sequelize.INTEGER, |
|
||||||
allowNull: false, |
|
||||||
references: { |
|
||||||
model: 'Wallets',
|
|
||||||
key: 'id', |
|
||||||
}, |
|
||||||
onDelete: 'CASCADE', |
|
||||||
}, |
|
||||||
amount: { |
|
||||||
type: Sequelize.STRING, |
|
||||||
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('Transactions'); |
|
||||||
}, |
|
||||||
}; |
|
@ -1,26 +1,11 @@ |
|||||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Request } from "@nestjs/common"; |
import { Controller, Get, Post, Body, Patch, Param, Delete } from "@nestjs/common"; |
||||||
import { InvoiceService } from "./invoice.service"; |
import { InvoiceService } from "./invoice.service"; |
||||||
import { JwtAuthGuard } from "src/guard/auth.guard"; |
|
||||||
import { RoleGuard } from "src/guard/role.guard"; |
|
||||||
|
|
||||||
@Controller("invoice") |
@Controller("invoice") |
||||||
export class InvoiceController { |
export class InvoiceController { |
||||||
constructor(private readonly invoiceService: InvoiceService) {} |
constructor(private readonly invoiceService: InvoiceService) {} |
||||||
@UseGuards(JwtAuthGuard) |
@Get(":userId") |
||||||
@Get() |
async getInvoices(@Param("userId") userId: number): Promise<any> { |
||||||
async getInvoiceByUser(@Request() req) { |
|
||||||
const userId = req.user.id; |
|
||||||
return this.invoiceService.getInvoiceByUser(userId); |
return this.invoiceService.getInvoiceByUser(userId); |
||||||
} |
} |
||||||
@UseGuards(RoleGuard) |
|
||||||
@Get('list') |
|
||||||
async getInvoices() { |
|
||||||
return this.invoiceService.getInvoices(); |
|
||||||
} |
|
||||||
@UseGuards(RoleGuard) |
|
||||||
@Get(':id') |
|
||||||
async getUserInvoice(@Param('id') id:number) { |
|
||||||
return this.invoiceService.getUserInvoices(id); |
|
||||||
} |
|
||||||
|
|
||||||
} |
} |
||||||
|
@ -1,19 +0,0 @@ |
|||||||
import { Model, Table, Column, ForeignKey, BelongsTo, DataType } from 'sequelize-typescript'; |
|
||||||
import { Wallet } from './wallet.entity'; |
|
||||||
|
|
||||||
@Table |
|
||||||
export class Transaction extends Model<Transaction> { |
|
||||||
@ForeignKey(() => Wallet) |
|
||||||
@Column |
|
||||||
walletId: number; |
|
||||||
|
|
||||||
@BelongsTo(() => Wallet, { onDelete: 'CASCADE' })
|
|
||||||
wallet: Wallet; |
|
||||||
|
|
||||||
@Column({ |
|
||||||
type: DataType.STRING, |
|
||||||
allowNull: false, |
|
||||||
defaultValue: "0",
|
|
||||||
}) |
|
||||||
amount: string; |
|
||||||
} |
|
@ -1,37 +1,12 @@ |
|||||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Request, forwardRef, Inject } 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 { JwtAuthGuard } from "src/guard/auth.guard"; |
|
||||||
import { PaymentService } from "src/payment/payment.service"; |
|
||||||
|
|
||||||
@Controller("wallet") |
@Controller("wallet") |
||||||
export class WalletController { |
export class WalletController { |
||||||
constructor( |
constructor(private readonly walletService: WalletService) {} |
||||||
private readonly walletService: WalletService, |
@Get(":userId") |
||||||
@Inject(forwardRef(() => PaymentService)) |
async getBalance(@Param("userId") userId: number) { |
||||||
private paymentService: PaymentService, |
|
||||||
) {} |
|
||||||
|
|
||||||
//getting wallet balance by user
|
|
||||||
@UseGuards(JwtAuthGuard) |
|
||||||
@Get() |
|
||||||
async getBalance(@Request() req) { |
|
||||||
const userId = req.user.id; |
|
||||||
return this.walletService.getBalance(userId); |
return this.walletService.getBalance(userId); |
||||||
} |
} |
||||||
|
|
||||||
@UseGuards(JwtAuthGuard) |
|
||||||
@Post("charge") |
|
||||||
async addBalance(@Body("amount") amount: number, @Request() req) { |
|
||||||
const userId = req.user.id; |
|
||||||
const callbackUrl = `http://localhost:3000/payment/verify?userId=${userId}&amount=${amount}`; |
|
||||||
const paymentUrl = this.paymentService.requestPayment(amount, "Wallet Charge", callbackUrl); |
|
||||||
return paymentUrl; |
|
||||||
} |
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard) |
|
||||||
@Get("transaction") |
|
||||||
async getTransactionById(@Request() req){ |
|
||||||
const userId = req.user.id |
|
||||||
return this.walletService.getTransactionById(userId) |
|
||||||
} |
|
||||||
} |
} |
||||||
|
@ -1,24 +1,13 @@ |
|||||||
import { Module } from "@nestjs/common"; |
import { Module } from '@nestjs/common'; |
||||||
import { WalletService } from "./wallet.service"; |
import { WalletService } from './wallet.service'; |
||||||
import { WalletController } from "./wallet.controller"; |
import { WalletController } from './wallet.controller'; |
||||||
import { Wallet } from "./entities/wallet.entity"; |
import { Wallet } from './entities/wallet.entity'; |
||||||
import { SequelizeModule } from "@nestjs/sequelize"; |
import { SequelizeModule } from '@nestjs/sequelize'; |
||||||
import { JwtModule } from "@nestjs/jwt"; |
|
||||||
import { RoleGuard } from "src/guard/role.guard"; |
|
||||||
import { JwtAuthGuard } from "src/guard/auth.guard"; |
|
||||||
import { PaymentService } from "src/payment/payment.service"; |
|
||||||
import { Transaction } from "./entities/transaction.entity"; |
|
||||||
|
|
||||||
@Module({ |
@Module({ |
||||||
imports: [ |
imports: [SequelizeModule.forFeature([Wallet])], |
||||||
SequelizeModule.forFeature([Wallet,Transaction]), |
|
||||||
JwtModule.register({ |
|
||||||
secret: process.env.JWT_SECRET, |
|
||||||
signOptions: { expiresIn: "1h" }, |
|
||||||
}), |
|
||||||
], |
|
||||||
controllers: [WalletController], |
controllers: [WalletController], |
||||||
providers: [WalletService, JwtAuthGuard, RoleGuard,PaymentService], |
providers: [WalletService], |
||||||
exports: [WalletService], |
exports: [WalletService],
|
||||||
}) |
}) |
||||||
export class WalletModule {} |
export class WalletModule {} |
||||||
|
Loading…
Reference in new issue