Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue fixes of 71,72,73,57 #74

Merged
merged 17 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion api-server-nestjs/.env.example

This file was deleted.

1 change: 1 addition & 0 deletions api-server-nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"dotenv": "^16.0.3",
"joi": "^17.11.0",
"jsonwebtoken": "^9.0.0",
"moment": "^2.29.4",
"mongoose": "^7.2.1",
Expand Down
2 changes: 1 addition & 1 deletion api-server-nestjs/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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";
import 'dotenv/config';

@Module({
imports: [
Expand Down
10 changes: 3 additions & 7 deletions api-server-nestjs/src/category/category.controller.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { Controller, Get, Req, Res } from '@nestjs/common';
import { Controller, Get, Req } from '@nestjs/common';
import { CategoryService } from './category.service';
import { CustomRequest } from '../middleware/Auth.middleware';
import { Response } from 'express';

@Controller('category')
export class CategoryController {
constructor(private readonly categoryService: CategoryService) {}
@Get()
async getAllCategory(@Req() req: CustomRequest, @Res() res: Response) {
async getAllCategory(@Req() req: CustomRequest) {
try {
return await this.categoryService.getAllCategory();
} catch (e) {
res.json({
status: 500,
message: e.message,
});
throw e;
}
}
}
1 change: 0 additions & 1 deletion api-server-nestjs/src/income/dtos/create-income.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
IsArray,
IsDateString,
IsEmpty,
IsNotEmpty,
IsNumber,
IsString,
} from 'class-validator';
Expand Down
14 changes: 3 additions & 11 deletions api-server-nestjs/src/wallet/wallet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,11 @@ export class WalletController {
}

@Get()
async getAllBudget(@Req() req: CustomRequest, @Res() res: Response) {
async getAllWallet(@Req() req: CustomRequest) {
try {
const wallets = await this.walletService.getAllWallets();

res.json({
status: 200,
data: wallets,
});
return await this.walletService.getAllWallets();
} catch (e) {
res.json({
status: 500,
message: e.message,
});
throw e;
}
}

Expand Down
2 changes: 1 addition & 1 deletion api-server-nestjs/src/wallet/wallet.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class Wallet extends Document {
@Prop()
balance: number;

@Prop()
@Prop({ type: Types.ObjectId, ref: 'User' })
user_id: Types.ObjectId;
}

Expand Down
10 changes: 6 additions & 4 deletions api-server-nestjs/src/wallet/wallet.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { BadRequestException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model, Types } from 'mongoose';
import { Model } from 'mongoose';
import { CustomRequest } from '../middleware/Auth.middleware';
import { CreateWalletDto } from './dtos/create-wallet.dto';
import { UpdateWalletDto } from './dtos/update-wallet.dto';
import { Wallet } from './wallet.schema';
import { Response } from 'express';

@Injectable()
export class WalletService {
constructor(@InjectModel(Wallet.name) private walletModel: Model<Wallet>) {}
Expand All @@ -16,15 +17,16 @@ export class WalletService {
body: CreateWalletDto,
): Promise<Wallet> {
try {
return await this.walletModel.create({ ...body, user_id: 1 });
return await this.walletModel.create({ ...body, user_id: '3' });
} catch (e) {
throw new Error(e.message);
}
}

async getAllWallets() {
try {
return await this.walletModel.find({});
const wallets = await this.walletModel.find();
return { data: wallets, status: HttpStatus.OK };
} catch (e) {
throw new Error(e.message);
}
Expand Down
40 changes: 40 additions & 0 deletions api-server-nestjs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,18 @@
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.51.0.tgz#6d419c240cfb2b66da37df230f7e7eef801c32fa"
integrity sha512-HxjQ8Qn+4SI3/AFv6sOrDB+g6PpUTDwSJiQqOrnneEk8L71161srI9gjzzZvYVbzHiVg/BvcH95+cK/zfIt4pg==

"@hapi/hoek@^9.0.0":
version "9.3.0"
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb"
integrity sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==

"@hapi/topo@^5.0.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.1.0.tgz#dc448e332c6c6e37a4dc02fd84ba8d44b9afb012"
integrity sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==
dependencies:
"@hapi/hoek" "^9.0.0"

"@humanwhocodes/config-array@^0.11.11":
version "0.11.11"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.11.tgz#88a04c570dbbc7dd943e4712429c3df09bc32844"
Expand Down Expand Up @@ -779,6 +791,23 @@
consola "^2.15.0"
node-fetch "^2.6.1"

"@sideway/address@^4.1.3":
version "4.1.4"
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.4.tgz#03dccebc6ea47fdc226f7d3d1ad512955d4783f0"
integrity sha512-7vwq+rOHVWjyXxVlR76Agnvhy8I9rpzjosTESvmhNeXOXdZZB15Fl+TI9x1SiHZH5Jv2wTGduSxFDIaq0m3DUw==
dependencies:
"@hapi/hoek" "^9.0.0"

"@sideway/formula@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@sideway/formula/-/formula-3.0.1.tgz#80fcbcbaf7ce031e0ef2dd29b1bfc7c3f583611f"
integrity sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg==

"@sideway/pinpoint@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@sideway/pinpoint/-/pinpoint-2.0.0.tgz#cff8ffadc372ad29fd3f78277aeb29e632cc70df"
integrity sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==

"@sinclair/typebox@^0.27.8":
version "0.27.8"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
Expand Down Expand Up @@ -3295,6 +3324,17 @@ [email protected]:
import-local "^3.0.2"
jest-cli "^29.5.0"

joi@^17.11.0:
version "17.11.0"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.11.0.tgz#aa9da753578ec7720e6f0ca2c7046996ed04fc1a"
integrity sha512-NgB+lZLNoqISVy1rZocE9PZI36bL/77ie924Ri43yEvi9GUUMPeyVIr8KdFTMUlby1p0PBYMk9spIxEUQYqrJQ==
dependencies:
"@hapi/hoek" "^9.0.0"
"@hapi/topo" "^5.0.0"
"@sideway/address" "^4.1.3"
"@sideway/formula" "^3.0.1"
"@sideway/pinpoint" "^2.0.0"

js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down
47 changes: 26 additions & 21 deletions frontend/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
'use client';
import './globals.css';
import {Inter} from 'next/font/google';
import {SnackbarProvider} from 'notistack';
import {ThemeProvider} from '@mui/material';
import defaultTheme from '@/core/layouts/DefaultTheme/defaultTheme';
import Head from 'next/head';

import './globals.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
const inter = Inter({subsets: ['latin']});

const inter = Inter({ subsets: ['latin'] })

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
export default function RootLayout({children}: {children: React.ReactNode}) {
return (
<html lang="en">
<body className={inter.className}>
{children}
</body>
</html>
)
<ThemeProvider theme={defaultTheme}>
<html lang='en'>
<Head>
<title>Budget pro</title>
<meta property='og:title' content='My page title' key='title' />
</Head>
<body className={inter.className}>
<SnackbarProvider
maxSnack={3}
anchorOrigin={{vertical: 'top', horizontal: 'right'}}>
{children}
</SnackbarProvider>
{/*{children}*/}
</body>
</html>
</ThemeProvider>
);
}
37 changes: 25 additions & 12 deletions frontend/component/AddNewBudget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ import {yupResolver} from '@hookform/resolvers/yup';
import * as yup from 'yup';
import axios from 'axios';
import {headers} from '@/utilities/helper';
import useNotiStack from '@/hooks/NotiStack';

const schema = yup.object().shape({
budget_title: yup.string().required('Require budget name'),
budget_title: yup
.string()
.required('Require budget name')
.max(30, 'Title must be less than or equal to 30 words'),
amount: yup
.number()
.transform((value) => (isNaN(value) ? undefined : value))
.nullable()
.min(100, 'minimun amount is greater than or equal to 100')
.max(2000000, 'maximum amount is less than or equal to 2000000')

.required('Require amount'),

category_id: yup
.array(yup.string().required())
.required('Category is required'),
Expand All @@ -43,6 +50,7 @@ interface walletData {
}

const AddNewBudget = () => {
const {successStack, errorStack} = useNotiStack();
const {
control,
register,
Expand Down Expand Up @@ -71,17 +79,22 @@ const AddNewBudget = () => {
}, []);

console.log('wallets', wallets);
console.log('Categories', wallets);

const handleSubmitData = (data: any) => {
axios.post('http://localhost:5000/budget/create', data, {headers}).then(
(response) => {
axios
.post('http://localhost:5000/budget/create', data, {headers})
.then(function (response) {
//handle success
successStack('Budget created successfully');

console.log('response', response);
})
.catch(function (response) {
errorStack('Failed to create budget');
//handle error
console.log(response);
},
(error) => {
console.log(error);
},
);
console.log('from data', data);
});
};
return (
<Container
Expand Down Expand Up @@ -152,8 +165,8 @@ const AddNewBudget = () => {
},
}}
type='number'
error={!!errors.budget_amount}
helperText={errors.budget_amount?.message?.toString()}
error={!!errors.amount}
helperText={errors.amount?.message?.toString()}
/>
</Grid>

Expand Down
27 changes: 19 additions & 8 deletions frontend/component/AddNewWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import {headers, wallets} from '@/utilities/helper';
import * as yup from 'yup';
import {yupResolver} from '@hookform/resolvers/yup';
import axios from 'axios';
import useNotiStack from '@/hooks/NotiStack';

const schema = yup.object().shape({
wallet_title: yup.string().required('Require wallet name'),
wallet_title: yup
.string()
.required('Require wallet name')
.max(30, 'Title must be less than or equal to 30 words'),
type_id: yup.number().required('Require currency type'),
balance: yup.number().required('Require amount'),
});
Expand All @@ -22,6 +26,7 @@ interface IWallet {
balance: number;
}
const AddNewWallet = () => {
const {successStack, errorStack} = useNotiStack();
const {
control,
register,
Expand All @@ -33,15 +38,21 @@ const AddNewWallet = () => {
});

console.log('errors->', errors);

const onSubmit = (data: IWallet) => {
axios.post('http://localhost:5000/wallet/create', data, {headers}).then(
(response) => {
axios
.post('http://localhost:5000/wallet/create', data, {headers})
.then(function (response) {
//handle success
successStack('Wallet created successfully');

console.log('response', response);
})
.catch(function (response) {
errorStack('Failed to create wallet');
//handle error
console.log(response);
},
(error) => {
console.log(error);
},
);
});
};

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/component/AddTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const AddTransaction = () => {
</Grid>
</Grid>
</Grid>
{selectedIndex === 0 && <ExpenseForm selectedIndex={selectedIndex} />}
{selectedIndex === 0 && <ExpenseForm />}

{selectedIndex === 1 && <IncomeForm selectedIndex={selectedIndex} />}
{selectedIndex === 1 && <IncomeForm />}
</Grid>
</Container>
);
Expand Down
Loading