Skip to content

Commit

Permalink
issue solved #57, #58, #56, #59, #55 (#70)
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

issue fixes #57, #58, #56, #59, #55 (#70)
  • Loading branch information
sp-rahul authored Oct 25, 2023
1 parent ab4efbe commit 5241721
Show file tree
Hide file tree
Showing 70 changed files with 7,611 additions and 984 deletions.
33 changes: 18 additions & 15 deletions api-server-nestjs/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {MiddlewareConsumer, Module, NestModule} from "@nestjs/common";
import {MongooseModule} from "@nestjs/mongoose";
import {AppController} from "./app.controller";
import {AppService} from "./app.service";
import {BudgetModule} from "./budget/budget.module";
import {CashbookModule} from "./cashbook/cashbook.module";
import {CategoryModule} from "./category/category.module";
import {ExpenseModule} from "./expense/expense.module";
import {IncomeModule} from "./income/income.module";
import {AuthMiddleware} from "./middleware/Auth.middleware";
import {UserModule} from "./user/user.module";
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MongooseModule } from '@nestjs/mongoose';
import { UserModule } from './user/user.module';
import { AuthMiddleware } from './middleware/Auth.middleware';
import { IncomeModule } from './income/income.module';
import { ExpenseModule } from './expense/expense.module';
import { CashbookModule } from './cashbook/cashbook.module';
import { BudgetModule } from './budget/budget.module';
import { CategoryModule } from './category/category.module';
import { WalletModule } from './wallet/wallet.module';
import "dotenv/config";

@Module({
Expand All @@ -19,14 +20,16 @@ import "dotenv/config";
ExpenseModule,
CashbookModule,
BudgetModule,
CategoryModule

CategoryModule,
WalletModule,
],
controllers: [AppController],
providers: [AppService]
providers: [AppService],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(AuthMiddleware).forRoutes("income/*", "cashbook", "expense/*", "budget/*");
consumer
.apply(AuthMiddleware)
.forRoutes('income/*', 'cashbook', 'expense/*', 'budget/*');
}
}
29 changes: 10 additions & 19 deletions api-server-nestjs/src/budget/budget.schema.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Document, Types } from "mongoose";
import * as moment from "moment";


const month = moment().format("MMMM");
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';

@Schema()
export class Budget extends Document {
@Prop()
budget_item: string;
budget_title: string;

@Prop()
budget_amount: number;

amount: number;

@Prop({ type: String, default: month })
budget_month: string;
@Prop({ type: Types.ObjectId, ref: 'Wallet' })
wallet_id: Types.ObjectId;

@Prop({ type: Date, default: Date.now() })
budget_time: Date;
@Prop({ type: Types.ObjectId, ref: 'Category' })
category_id: Types.ObjectId;

@Prop({ type: Types.ObjectId, ref: "User" })
userId: Types.ObjectId;

@Prop({ type: Types.ObjectId, ref: "Category" })
categoryId: Types.ObjectId;
@Prop()
user_id: string;
}


export const BudgetSchema = SchemaFactory.createForClass(Budget);
61 changes: 21 additions & 40 deletions api-server-nestjs/src/budget/budget.service.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,30 @@
import {BadRequestException, Injectable} from "@nestjs/common";
import {InjectModel} from "@nestjs/mongoose";
import {Model, Types} from "mongoose";
import {Cashbook} from "../cashbook/cashbook.schema";
import {Category} from "../category/category.schema";
import {CustomRequest} from "../middleware/Auth.middleware";
import {Budget} from "./budget.schema";
import {CreateBudgetDto} from "./dtos/create-budget.dto";
import {UpdateBudgetDto} from "./dtos/update-budget.dto";
import { BadRequestException, Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model, Types } from 'mongoose';
import { Cashbook } from '../cashbook/cashbook.schema';
import { Category } from '../category/category.schema';
import { Budget } from './budget.schema';
import { CustomRequest } from '../middleware/Auth.middleware';
import { CreateBudgetDto } from './dtos/create-budget.dto';
import { UpdateBudgetDto } from './dtos/update-budget.dto';

@Injectable()
export class BudgetService {
constructor(
@InjectModel(Budget.name) private budgetModel: Model<Budget>,
@InjectModel(Cashbook.name) private cashbookModel: Model<Cashbook>,
@InjectModel(Category.name) private categoryModel: Model<Category>
) {
}
@InjectModel(Category.name) private categoryModel: Model<Category>,
) {}

async createBudget(
req: CustomRequest,
body: CreateBudgetDto
body: CreateBudgetDto,
): Promise<Budget> {
try {


body.userId = new Types.ObjectId(req.userId);

const categoryName = body.category;
const category = await this.categoryModel.create({
name: categoryName,
type: "budget"
});

body.categoryId = category._id;

// body.user_id = new Types.ObjectId(req.userId);
body.user_id = '2';

return await this.budgetModel.create(body);


} catch (e) {
throw new Error(e.message);
}
Expand All @@ -56,8 +43,6 @@ export class BudgetService {
const { month } = req.query;
const userId = new Types.ObjectId(req.userId);
return await this.budgetModel.find({ budget_amount: month, userId });


} catch (e) {
throw new Error(e.message);
}
Expand All @@ -66,37 +51,33 @@ export class BudgetService {
async getBudgetById(req) {
try {
return await this.budgetModel.findOne({ _id: req.params.id });

} catch (e) {
throw new Error(e.message);
}

}

async updateBudget(req, body: UpdateBudgetDto) {
try {
return await this.budgetModel.findByIdAndUpdate(req.params.id, body,
{
new: true
});
return await this.budgetModel.findByIdAndUpdate(req.params.id, body, {
new: true,
});
} catch (e) {
console.log(e.message);
throw new Error(e.message);
}

}

async deleteBudget(req) {
try {

const budget = await this.budgetModel.findById(req.params.id);

if (!budget) throw new BadRequestException("No Budget found");
if (!budget) {
throw new BadRequestException('No Budget found');
}

return await this.budgetModel.deleteOne({ _id: req.params.id });
} catch (e) {
throw new Error(e.message);
}
}


}
27 changes: 7 additions & 20 deletions api-server-nestjs/src/budget/dtos/create-budget.dto.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import {
IsDateString,
IsEmpty,
IsNotEmpty,
IsNumber,
IsString
} from "class-validator";
import { IsArray, IsEmpty, IsNumber, IsString } from 'class-validator';

export class CreateBudgetDto {
@IsString()
budget_item: string;
budget_title: string;

@IsNumber()
budget_amount: number;
amount: number;

@IsString()
budget_month: string;
wallet_id;

@IsDateString()
budget_time: Date;
@IsArray()
category_id: string;

@IsEmpty()
userId: any;

@IsEmpty()
categoryId: string;

@IsNotEmpty()
@IsString()
category: string;
user_id: string;
}
14 changes: 6 additions & 8 deletions api-server-nestjs/src/budget/dtos/update-budget.dto.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { IsOptional, IsString, IsNumber, IsDate } from "class-validator";
import { IsNumber, IsOptional, IsString } from 'class-validator';

export class UpdateBudgetDto {
@IsOptional()
@IsString()
budget_item?: string;
budget_title?: string;

@IsOptional()
@IsNumber()
budget_amount?: number;
amount?: number;

@IsOptional()
@IsString()
budget_month?: string;
wallet_id?: string;

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


@IsString()
category_id?: string;
}
20 changes: 18 additions & 2 deletions api-server-nestjs/src/category/category.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import { Controller } from '@nestjs/common';
import { Controller, Get, Req, Res } from '@nestjs/common';
import { CategoryService } from './category.service';
import { CustomRequest } from '../middleware/Auth.middleware';
import { Response } from 'express';

@Controller('category')
export class CategoryController {}
export class CategoryController {
constructor(private readonly categoryService: CategoryService) {}
@Get()
async getAllCategory(@Req() req: CustomRequest, @Res() res: Response) {
try {
return await this.categoryService.getAllCategory();
} catch (e) {
res.json({
status: 500,
message: e.message,
});
}
}
}
9 changes: 8 additions & 1 deletion api-server-nestjs/src/category/category.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Module } from '@nestjs/common';
import { CategoryService } from './category.service';
import { CategoryController } from './category.controller';
import { MongooseModule } from '@nestjs/mongoose';
import { CategorySchema } from './category.schema';

@Module({
providers: [CategoryService]
imports: [
MongooseModule.forFeature([{ name: 'Category', schema: CategorySchema }]),
],
controllers: [CategoryController],
providers: [CategoryService],
})
export class CategoryModule {}
5 changes: 1 addition & 4 deletions api-server-nestjs/src/category/category.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { Document } from 'mongoose';
@Schema({ timestamps: true })
export class Category extends Document {
@Prop()
name: string;

@Prop({ enum: ['income', 'expense', 'budget'] })
type: string;
label: string;
}

export const CategorySchema = SchemaFactory.createForClass(Category);
20 changes: 18 additions & 2 deletions api-server-nestjs/src/category/category.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import { Injectable } from '@nestjs/common';
import { HttpStatus, Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Category } from './category.schema';

@Injectable()
export class CategoryService {}
export class CategoryService {
constructor(
@InjectModel(Category.name) private categoryModel: Model<Category>,
) {}

async getAllCategory() {
try {
const categories = await this.categoryModel.find();
return { data: categories, status: HttpStatus.OK };
} catch (e) {
throw new Error(e.message);
}
}
}
26 changes: 26 additions & 0 deletions api-server-nestjs/src/dammy data/dammy_data_dashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const result = [
{
_id: 1,
income_source: 'Social bank',
income_amount: 5000,
income_month: 'January',
},
{
_id: 2,
income_source: 'Islamic bank',
income_amount: 8000,
income_month: 'January',
},
{
_id: 3,
income_source: 'Bangladesh',
income_amount: 25000,
income_month: 'January',
},
{
_id: 4,
income_source: 'Business',
income_amount: 15000,
income_month: 'January',
},
];
Loading

0 comments on commit 5241721

Please sign in to comment.