Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/windate3411/ac_core_final_q3
https://github.com/windate3411/ac_core_final_q3
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/windate3411/ac_core_final_q3
- Owner: windate3411
- Created: 2019-08-14T08:20:57.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T01:55:21.000Z (almost 2 years ago)
- Last Synced: 2024-04-15T07:41:44.569Z (7 months ago)
- Language: JavaScript
- Size: 2.81 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# 家庭記帳本 Household Expense tracker-sequelize
基本上是利用https://github.com/windate3411/expense-tracker做修改完成的專案,基本功能完全一致。
## 專案預覽 Project preview
![image](https://github.com/windate3411/AC_core_final_Q3/blob/master/result1.PNG)
![image](https://github.com/windate3411/AC_core_final_Q3/blob/master/result2.PNG)
![image](https://github.com/windate3411/AC_core_final_Q3/blob/master/result3.PNG)
![image](https://github.com/windate3411/AC_core_final_Q3/blob/master/result4.PNG)## 專案需求 Prerequisites
為了確保程式順利運作,你需要安裝以下程式 You need to install following software
+ [Node.js v10.16.0(LTS)](https://nodejs.org/en/)
## 如何開始 Getting Started
```
# 下載專案 Clone the repository:
git clone https://github.com/windate3411/AC_core_final_Q3.git# 安裝NPM套件 Install NPM dependencies
npm install# 在根目錄下新增.env檔案並有著以下的格式 Create .env file which contains following info under project directory
FACEBOOK_ID=XXXXXXXX
FACEBOOK_SECRET=XXXXXXXX
FACEBOOK_CALLBACK=http://example.com/auth/facebook/callback# 執行程式 Start the app
npm run dev順利執行時會在終端機看到
you are now listening at port 3000
便可前往http://localhost:3000使用
```## 給助教的話
主要修改部分有以下
+ 連接資料庫的做法
```
const db = require('../models')
const User = db.User
const Record = db.Record
```
+ query的程式碼
```
// sequelize operators
const Op = Sequelize.Op;// setting filter pattern
let filter = {
UserId: req.user.id
}
if (req.query.category === '' || req.query.category === '所有') {
filter.date = {
[Op.between]: [new Date(2019, req.query.months - 1, 1), new Date(2019, req.query.months, 0)]
}
} else {
filter.date = {
[Op.between]: [new Date(2019, req.query.months - 1, 1), new Date(2019, req.query.months, 0)]
}
filter.category = category
}User.findByPk(req.user.id)
.then((user) => {
if (!user) throw new Error("user not found")
return Record.findAll({
where: filter
})
})
.then((records) => {
records.forEach(item => {
totalAmount += Number(item.amount)
})
return res.render('index', { records, months_array, category_array, totalAmount, months, category, category_image })
})
.catch((error) => { return res.status(422).json(error) })
})
```
## 作者 Author* **Danny Wang**