-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const Record = require("../models/Record"); | ||
|
||
const RecordController = { | ||
whereAll: async (request, h) => { | ||
const { query } = request; | ||
// need id of user | ||
|
||
const records = await Record.getAllByUserId(query.id); | ||
const savings = await Saving.getAllByUserId(query.id); | ||
const bills = await Bill.getAllByUserId(query.id); | ||
const saving_records = await SavingRecord.getAllByUserId(query.id); | ||
|
||
// decode json saving save | ||
const saving_records_decode = saving_records.map(saving_record => { | ||
return JSON.parse(saving_record.save); | ||
}); | ||
|
||
return h.response({ | ||
error: false, | ||
statusCode: 200, | ||
message: 'Success', | ||
data: { | ||
records: records, | ||
savings: savings, | ||
saving_record: saving_records_decode, | ||
bills: bills | ||
} | ||
}).code(200); | ||
}, | ||
|
||
whereIncome: async (request, h) => { | ||
const { query } = request; | ||
// need id of user | ||
|
||
const records = await Record.getIncome(query.id); | ||
|
||
return h.response({ | ||
error: false, | ||
statusCode: 200, | ||
message: 'Success', | ||
data: { | ||
records: records | ||
} | ||
}).code(200); | ||
}, | ||
|
||
whereExpense: async (request, h) => { | ||
const { query } = request; | ||
// need id of user | ||
|
||
const records = await Record.getExpense(query.id); | ||
|
||
return h.response({ | ||
error: false, | ||
statusCode: 200, | ||
message: 'Success', | ||
data: { | ||
records: records | ||
} | ||
}).code(200); | ||
} | ||
}; | ||
|
||
module.exports = RecordController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
const connection = require('../config/database'); | ||
|
||
class Record{ | ||
static async getAllById(id){ | ||
static async getAllByUserId(user_id){ | ||
const records = await connection.promise().query( | ||
'SELECT * FROM records WHERE user_id = ?', | ||
[id] | ||
[user_id] | ||
); | ||
return records[0]; | ||
} | ||
|
||
static async getIncome(user_id) { | ||
const incomes = await connection.promise().query( | ||
'SELECT * FROM records WHERE type = ? AND user_id = ?', ['income', user_id] | ||
).catch(err => console.log(err)); | ||
return incomes[0]; | ||
} | ||
|
||
static async getExpense(user_id) { | ||
const expenses = await connection.promise().query( | ||
'SELECT * FROM records WHERE type = ? AND user_id = ?', ['expense', user_id] | ||
); | ||
return expenses[0]; | ||
} | ||
|
||
static async storeIncome({user_id, amount, note, category}){ | ||
const record = await connection.promise().query( | ||
'INSERT INTO records (user_id, amount, note, category, type) VALUES (?, ?, ?, ?, ?)', | ||
[user_id, amount, note, category, 'income'] | ||
); | ||
return record; | ||
} | ||
|
||
static async storeExpense({user_id, amount, note, category}){ | ||
const record = await connection.promise().query( | ||
'INSERT INTO records (user_id, amount, note, category, type) VALUES (?, ?, ?, ?, ?)', | ||
[user_id, amount, note, category, 'expense'] | ||
); | ||
return record; | ||
} | ||
} | ||
|
||
module.exports = Record; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters