Skip to content

Commit

Permalink
issue fixes: budet date (#82)
Browse files Browse the repository at this point in the history
* new design login,signup,dashboard,startup page is done

* page design has done for 1st phase and need refactorization

* unused import removed

* routing almost done

* Main container margin padding. cart border,color resolve almost

* re arranged

* form submitting going on

* form submission ndone

* # api created for budget, category, wallet.
# in frontend cin budget and wallet page ids type has changed

* # api created for budget, category, wallet.
# in frontend cin budget and wallet page ids type has changed

* Added notify stack, added title and amount range in all forms, income model frontend backend completed for get and post,

* added joi validation

* Joi validation pending task

* Joi validation pending task

* Joi validation pending task

* budget date issue dix

* budget date issue dix

* budget date issue dix

* auto comepele addted

* auto comepele added

* auto comepele added

* auto comepele issue fix, base url set
  • Loading branch information
sp-rahul authored Nov 1, 2023
1 parent 0b6ee2c commit 392e8c9
Show file tree
Hide file tree
Showing 21 changed files with 467 additions and 290 deletions.
18 changes: 18 additions & 0 deletions api-server-nestjs/src/budget/budget.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class BudgetController {
createBudgetDto: CreateBudgetDto,
) {
try {
/**TODO: valid wallet_id check */
const budget = await this.budgetService.createBudget(
req,
createBudgetDto,
Expand Down Expand Up @@ -63,6 +64,23 @@ export class BudgetController {
}
}

@Get('total')
async getTotalBudget(@Req() req: CustomRequest, @Res() res: Response) {
try {
const budget = await this.budgetService.getTotalBudgets();

res.json({
status: 200,
budget,
});
} catch (e) {
res.json({
status: 500,
message: e.message,
});
}
}

@Get('month')
async getBudgetsByMonth(@Req() req: CustomRequest, @Res() res: Response) {
try {
Expand Down
8 changes: 8 additions & 0 deletions api-server-nestjs/src/budget/budget.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export class BudgetService {
}
}

async getTotalBudgets() {
try {
return await this.budgetModel.find({});
} catch (e) {
throw new Error(e.message);
}
}

async getBudgetsByMonth(req) {
try {
const { month } = req.query;
Expand Down
18 changes: 15 additions & 3 deletions api-server-nestjs/src/budget/dtos/create-budget.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { ArrayMinSize, IsEmpty, IsNumber, IsString } from 'class-validator';
import {
ArrayMinSize,
IsDate,
IsEmpty,
IsNotEmpty,
IsNumber,
IsString,
MinDate,
} from 'class-validator';
import { Transform } from 'class-transformer';

export class CreateBudgetDto {
@IsString()
Expand All @@ -14,8 +23,11 @@ export class CreateBudgetDto {
@ArrayMinSize(1)
category_ids: string[];

@IsString()
month: string;
@IsNotEmpty()
@Transform(({ value }) => new Date(value))
@IsDate()
@MinDate(new Date())
month: Date;

@IsEmpty()
user_id: string;
Expand Down
8 changes: 6 additions & 2 deletions api-server-nestjs/src/budget/dtos/update-budget.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNumber, IsOptional, IsString } from 'class-validator';
import { IsDateString, IsNumber, IsOptional, IsString } from 'class-validator';

export class UpdateBudgetDto {
@IsOptional()
Expand All @@ -15,5 +15,9 @@ export class UpdateBudgetDto {

@IsOptional()
@IsString()
category_id?: string;
category_ids?: string;

@IsOptional()
@IsDateString()
month?: Date;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as joi from 'joi';
export const createBudgetSchema = joi.object({
budget_title: joi.string().required(),
amount: joi.number().required(),
budget_title: joi.string().max(30).required(),
amount: joi.number().min(100).max(2000000).required(),
wallet_id: joi.string().required(),
category_ids: joi.array().items(joi.string()),
month: joi.string().required(),
month: joi.date().required(),
});
23 changes: 16 additions & 7 deletions api-server-nestjs/src/expense/dtos/update-expense.dto.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import { IsOptional, IsString, IsNumber, IsDate } from "class-validator";
import {
IsOptional,
IsString,
IsNumber,
IsDate,
IsArray,
IsDateString,
} from 'class-validator';

export class UpdateExpenseDto {
@IsOptional()
@IsString()
expenseItem?: string;
title?: string;

@IsOptional()
@IsNumber()
expenseAmount?: number;
balance?: number;

@IsOptional()
@IsString()
expenseMonth?: string;
wallet_id?: number;

@IsOptional()
@IsDate()
expenseTime?: Date;

@IsArray()
category_ids: string[];

@IsOptional()
@IsDateString()
date: string;
}
42 changes: 21 additions & 21 deletions api-server-nestjs/src/expense/expense.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,25 @@ export class ExpenseController {
}
}

@Delete(':id')
async deleteExpense(@Req() req: CustomRequest, @Res() res: Response) {
try {
const expense = await this.expenseService.deleteExpense(req);
if (!expense) {
return res.json({
status: 200,
message: 'No expense found',
});
}
res.json({
status: 200,
expense: null,
});
} catch (e) {
res.json({
status: 500,
message: e.message,
});
}
}
// @Delete(':id')
// async deleteExpense(@Req() req: CustomRequest, @Res() res: Response) {
// try {
// const expense = await this.expenseService.deleteExpense(req);
// if (!expense) {
// return res.json({
// status: 200,
// message: 'No expense found',
// });
// }
// res.json({
// status: 200,
// expense: null,
// });
// } catch (e) {
// res.json({
// status: 500,
// message: e.message,
// });
// }
// }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as joi from 'joi';
export const createExpenseSchema = joi.object({
title: joi.string().required(),
balance: joi.number().required(),
title: joi.string().max(30).required(),
balance: joi.number().min(100).max(2000000).required(),
wallet_id: joi.string().required(),
category_ids: joi.array().items(joi.string()),
date: joi.string().required(),
Expand Down
23 changes: 16 additions & 7 deletions api-server-nestjs/src/income/dtos/update-income.dto.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import { IsOptional, IsString, IsNumber, IsDate } from "class-validator";
import {
IsOptional,
IsString,
IsNumber,
IsDate,
IsArray,
IsDateString,
} from 'class-validator';

export class UpdateIncomeDto {
@IsOptional()
@IsString()
income_source?: string;
title?: string;

@IsOptional()
@IsNumber()
income_amount?: number;
balance?: number;

@IsOptional()
@IsString()
income_month?: string;
wallet_id?: number;

@IsOptional()
@IsDate()
income_time?: Date;

@IsArray()
category_ids: string[];

@IsOptional()
@IsDateString()
date: string;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as joi from 'joi';
export const createIncomeSchema = joi.object({
title: joi.string().required(),
balance: joi.number().required(),
title: joi.string().max(30).required(),
balance: joi.number().min(100).max(2000000).required(),
wallet_id: joi.string().required(),
category_ids: joi.array().items(joi.string()),
date: joi.string().required(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as joi from 'joi';
export const createWalletValidationSchema = joi.object({
wallet_title: joi.string().required(),

type_id: joi.number().required(),

balance: joi.number().min(100).max(2000000).required(),
});
5 changes: 3 additions & 2 deletions api-server-nestjs/src/wallet/wallet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { WalletService } from './wallet.service';
import { CreateWalletDto } from './dtos/create-wallet.dto';
import { UpdateWalletDto } from './dtos/update-wallet.dto';
import { JoiValidationPipe } from '../validation-pipe/validation.pipe';
import { createWalletSchema } from './validation-schema/create-wallet.schema';
import { createWalletValidationSchema } from './validation-schema/create-wallet.validation.schema';

@Controller('wallet')
export class WalletController {
Expand All @@ -24,7 +24,8 @@ export class WalletController {
async createWallet(
@Req() req: CustomRequest,
@Res() res: Response,
@Body(new JoiValidationPipe(createWalletSchema)) body: CreateWalletDto,
@Body(new JoiValidationPipe(createWalletValidationSchema))
body: CreateWalletDto,
) {
try {
const wallet = await this.walletService.createWallet(req, res, body);
Expand Down
Loading

0 comments on commit 392e8c9

Please sign in to comment.