Commit 822a6710 authored by Choi Ga Young's avatar Choi Ga Young
Browse files

코드정리

parent d513a4bd
...@@ -7,12 +7,11 @@ enablePromise(true); ...@@ -7,12 +7,11 @@ enablePromise(true);
const insertDept = async (deptData) => { const insertDept = async (deptData) => {
const db = await getDb(); const db = await getDb();
const { date, loan, message, money, remained_money } = deptData //객체의 value값들을 가져옴 const { date, loan, message, money, remained_money } = deptData
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 삽입하기");
tx.executeSql('INSERT INTO dept (repayment_date, loan, loan_name, principal, repayment) VALUES (?,?,?,?,?);', tx.executeSql('INSERT INTO dept (repayment_date, loan, loan_name, principal, repayment) VALUES (?,?,?,?,?);',
[date, loan, message, money, remained_money], //가져온 value값들을 배열형식으로 [date, loan, message, money, remained_money],
(error) => console.log(error)) (error) => console.log(error))
resolve('데이터 삽입 완료'); resolve('데이터 삽입 완료');
}) })
...@@ -25,12 +24,9 @@ const insertDept = async (deptData) => { ...@@ -25,12 +24,9 @@ const insertDept = async (deptData) => {
const selectLoan = async (title) => { const selectLoan = async (title) => {
const db = await getDb(); const db = await getDb();
console.log(title, "123")
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction(async (tx) => { db.transaction(async (tx) => {
console.log("내용 부르기");
const [txn, results] = await tx.executeSql(`SELECT * FROM dept WHERE loan ="${title}"`); const [txn, results] = await tx.executeSql(`SELECT * FROM dept WHERE loan ="${title}"`);
console.log('item length', results.rows.length);
const temp = []; const temp = [];
for (let i = 0; i < results.rows.length; i++) { for (let i = 0; i < results.rows.length; i++) {
const tempId = results.rows.item(i).dept_id; const tempId = results.rows.item(i).dept_id;
...@@ -47,14 +43,10 @@ const selectLoan = async (title) => { ...@@ -47,14 +43,10 @@ const selectLoan = async (title) => {
}) })
} }
const deleteDept = async (id) => { const deleteDept = async (id) => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 삭제하기");
tx.executeSql(`DELETE FROM dept WHERE dept_id = ${id}`) tx.executeSql(`DELETE FROM dept WHERE dept_id = ${id}`)
resolve('삭제완료'); resolve('삭제완료');
}) })
...@@ -68,7 +60,6 @@ const updateDept = async (deptData, id) => { ...@@ -68,7 +60,6 @@ const updateDept = async (deptData, id) => {
console.log(date, message, id) console.log(date, message, id)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 수정하기");
tx.executeSql(`UPDATE dept set repayment_date =?, loan_name=?, principal=?, repayment=? where dept_id =${id};`, tx.executeSql(`UPDATE dept set repayment_date =?, loan_name=?, principal=?, repayment=? where dept_id =${id};`,
[date, message, money, remained_money], [date, message, money, remained_money],
(error) => console.log(error)) (error) => console.log(error))
...@@ -77,7 +68,6 @@ const updateDept = async (deptData, id) => { ...@@ -77,7 +68,6 @@ const updateDept = async (deptData, id) => {
}) })
}; };
const deptApi = { const deptApi = {
insertDept, insertDept,
selectLoan, selectLoan,
......
...@@ -11,7 +11,6 @@ const selectCategories = async (type_id) => { ...@@ -11,7 +11,6 @@ const selectCategories = async (type_id) => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction(async (tx) => { db.transaction(async (tx) => {
console.log("카테고리 부르기");
const [txn, results] = await tx.executeSql( const [txn, results] = await tx.executeSql(
`select cat.category_id, category_name, subcat_id, subcat_name from categories as cat `select cat.category_id, category_name, subcat_id, subcat_name from categories as cat
left join ( left join (
...@@ -23,7 +22,6 @@ const selectCategories = async (type_id) => { ...@@ -23,7 +22,6 @@ const selectCategories = async (type_id) => {
on cat.category_id=subcat.category_id on cat.category_id=subcat.category_id
where cat.type_id='${type_id}'` where cat.type_id='${type_id}'`
); );
console.log('item length', results.rows.length);
const temp = []; const temp = [];
for (let i = 0; i < results.rows.length; i++) { for (let i = 0; i < results.rows.length; i++) {
const tempId = results.rows.item(i).category_id; const tempId = results.rows.item(i).category_id;
...@@ -39,23 +37,7 @@ const selectCategories = async (type_id) => { ...@@ -39,23 +37,7 @@ const selectCategories = async (type_id) => {
} }
temp.push({ id: tempId, value: tempName, deletable: deletable, subOptions: tempSubOptions }); temp.push({ id: tempId, value: tempName, deletable: deletable, subOptions: tempSubOptions });
} }
console.log(temp)
resolve(temp); resolve(temp);
// console.log("카테고리 부르기");
// const [txn, results] = await tx.executeSql(`SELECT * FROM categories WHERE type_id=${type_id}`);
// console.log('item length', results.rows.length);
// const temp = [];
// for (let i = 0; i < results.rows.length; i++) {
// const tempId = results.rows.item(i).category_id;
// const tempName = results.rows.item(i).category_name;
// if (tempId < CAT_LIMIT_ID) {
// temp.push({ id: tempId, value: tempName, deletable: false });
// } else {
// temp.push({ id: tempId, value: tempName, deletable: true });
// }
// }
// console.log(temp)
// resolve(temp);
}) })
}) })
} }
...@@ -64,9 +46,7 @@ const selectAssetsType = async () => { ...@@ -64,9 +46,7 @@ const selectAssetsType = async () => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction(async (tx) => { db.transaction(async (tx) => {
console.log("자산 유형 부르기");
const [txn, results] = await tx.executeSql('SELECT * FROM assets_type'); const [txn, results] = await tx.executeSql('SELECT * FROM assets_type');
console.log('item length', results.rows.length);
const temp = []; const temp = [];
for (let i = 0; i < results.rows.length; i++) { for (let i = 0; i < results.rows.length; i++) {
const tempId = results.rows.item(i).assets_id; const tempId = results.rows.item(i).assets_id;
...@@ -77,7 +57,6 @@ const selectAssetsType = async () => { ...@@ -77,7 +57,6 @@ const selectAssetsType = async () => {
temp.push({ id: tempId, value: tempName, deletable: true }); temp.push({ id: tempId, value: tempName, deletable: true });
} }
} }
console.log(temp)
resolve(temp); resolve(temp);
}) })
}) })
...@@ -88,7 +67,6 @@ const deleteOption = async (table, data) => { ...@@ -88,7 +67,6 @@ const deleteOption = async (table, data) => {
const { id, name } = data const { id, name } = data
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 삭제하기");
tx.executeSql(`DELETE FROM ${table} WHERE ${name}_id = ${id};`) tx.executeSql(`DELETE FROM ${table} WHERE ${name}_id = ${id};`)
resolve(`${name} 데이터 삭제 완료`); resolve(`${name} 데이터 삭제 완료`);
}) })
...@@ -101,7 +79,6 @@ const updateOption = async (table, data) => { ...@@ -101,7 +79,6 @@ const updateOption = async (table, data) => {
console.log(table, id, value) console.log(table, id, value)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 수정하기");
tx.executeSql(`UPDATE ${table} set ${name}_name =? where ${name}_id =${id};`, tx.executeSql(`UPDATE ${table} set ${name}_name =? where ${name}_id =${id};`,
[value], [value],
(error) => console.log(error)) (error) => console.log(error))
...@@ -122,10 +99,8 @@ const addOption = async (table, data) => { ...@@ -122,10 +99,8 @@ const addOption = async (table, data) => {
insertQeury = `INSERT INTO ${table} (${name}_name, ${foreign_name}_id) VALUES (?,?);` insertQeury = `INSERT INTO ${table} (${name}_name, ${foreign_name}_id) VALUES (?,?);`
queryData = [value, foreign_id] queryData = [value, foreign_id]
} }
// console.log(insertQuery, queryData)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 삽입하기");
tx.executeSql(insertQeury, tx.executeSql(insertQeury,
queryData, queryData,
(error) => console.log(error)) (error) => console.log(error))
......
...@@ -8,7 +8,6 @@ const insertMemo = async (memoData) => { ...@@ -8,7 +8,6 @@ const insertMemo = async (memoData) => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 삽입하기");
tx.executeSql('INSERT INTO memo (memo_date, message) VALUES (?,?);', tx.executeSql('INSERT INTO memo (memo_date, message) VALUES (?,?);',
[memoData.date, memoData.message], [memoData.date, memoData.message],
(error) => console.log(error)) (error) => console.log(error))
...@@ -21,7 +20,6 @@ const selectMemo = async () => { ...@@ -21,7 +20,6 @@ const selectMemo = async () => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction(async (tx) => { db.transaction(async (tx) => {
console.log("내용 부르기");
const [txn, results] = await tx.executeSql('SELECT * FROM memo'); const [txn, results] = await tx.executeSql('SELECT * FROM memo');
console.log('item length', results.rows.length); console.log('item length', results.rows.length);
const temp = []; const temp = [];
...@@ -31,7 +29,6 @@ const selectMemo = async () => { ...@@ -31,7 +29,6 @@ const selectMemo = async () => {
const tempMsg = results.rows.item(i).message; const tempMsg = results.rows.item(i).message;
temp.push({ id: tempId, date: tempDate, message: tempMsg }); temp.push({ id: tempId, date: tempDate, message: tempMsg });
} }
console.log(temp)
resolve(temp); resolve(temp);
}) })
}) })
...@@ -41,7 +38,6 @@ const deleteMemo = async (id) => { ...@@ -41,7 +38,6 @@ const deleteMemo = async (id) => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 삭제하기");
tx.executeSql(`DELETE FROM memo WHERE memo_id = ${id}`) tx.executeSql(`DELETE FROM memo WHERE memo_id = ${id}`)
resolve('삭제완료'); resolve('삭제완료');
}) })
...@@ -54,7 +50,6 @@ const updateMemo = async (memoData, id) => { ...@@ -54,7 +50,6 @@ const updateMemo = async (memoData, id) => {
console.log(date, message, id) console.log(date, message, id)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 수정하기");
tx.executeSql(`UPDATE memo set memo_date =?, message =? where memo_id =${id};`, tx.executeSql(`UPDATE memo set memo_date =?, message =? where memo_id =${id};`,
[date, message], [date, message],
(error) => console.log(error)) (error) => console.log(error))
...@@ -63,20 +58,6 @@ const updateMemo = async (memoData, id) => { ...@@ -63,20 +58,6 @@ const updateMemo = async (memoData, id) => {
}) })
}; };
// const insertDept = async (deptData) => {
// const db = await getDb();
// const { date, loan, message, money, remained_money } = deptData //객체의 value값들을 가져옴
// return new Promise((resolve, reject) => {
// db.transaction((tx) => {
// console.log("데이터 삽입하기");
// tx.executeSql('INSERT INTO dept (repayment_date, loan, loan_name, principal, repayment) VALUES (?,?,?,?,?);',
// [date, loan, message, money, remained_money], //가져온 value값들을 배열형식으로
// (error) => console.log(error))
// resolve('데이터 삽입 완료');
// })
// })
// };
const memoApi = { const memoApi = {
insertMemo, insertMemo,
selectMemo, selectMemo,
......
...@@ -8,7 +8,6 @@ const insertMoney = async (moneyData) => { ...@@ -8,7 +8,6 @@ const insertMoney = async (moneyData) => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction((tx) => { db.transaction((tx) => {
console.log("데이터 삽입하기");
tx.executeSql('INSERT INTO Money (type_id, date, contents, price, assets_id, category_id, subcategory_id) VALUES (?,?,?,?,?,?,?);', tx.executeSql('INSERT INTO Money (type_id, date, contents, price, assets_id, category_id, subcategory_id) VALUES (?,?,?,?,?,?,?);',
moneyData, moneyData,
(error) => console.log(error)) (error) => console.log(error))
...@@ -21,9 +20,7 @@ const selectCategories = async (type_id) => { ...@@ -21,9 +20,7 @@ const selectCategories = async (type_id) => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction(async (tx) => { db.transaction(async (tx) => {
console.log("카테고리 부르기");
const [txn, results] = await tx.executeSql(`SELECT * FROM categories WHERE type_id=${type_id}`); const [txn, results] = await tx.executeSql(`SELECT * FROM categories WHERE type_id=${type_id}`);
console.log('item length', results.rows.length);
const temp = []; const temp = [];
temp.push({id: 1, value:'기타'}); temp.push({id: 1, value:'기타'});
for (let i = 0; i < 3*(Math.ceil((results.rows.length+1)/3))-1; i++) { for (let i = 0; i < 3*(Math.ceil((results.rows.length+1)/3))-1; i++) {
...@@ -35,7 +32,6 @@ const selectCategories = async (type_id) => { ...@@ -35,7 +32,6 @@ const selectCategories = async (type_id) => {
temp.push({ id: 0, value: '' }); temp.push({ id: 0, value: '' });
} }
} }
console.log(temp)
resolve(temp); resolve(temp);
}) })
}) })
...@@ -45,9 +41,7 @@ const selectSubCategories = async () => { ...@@ -45,9 +41,7 @@ const selectSubCategories = async () => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction(async (tx) => { db.transaction(async (tx) => {
console.log("서브 카테고리 부르기");
const [txn, results] = await tx.executeSql('SELECT * FROM subcategories'); const [txn, results] = await tx.executeSql('SELECT * FROM subcategories');
console.log('item length', results.rows.length);
const temp = []; const temp = [];
for (let i = 0; i < results.rows.length; i++) { for (let i = 0; i < results.rows.length; i++) {
const tempId = results.rows.item(i).subcategory_id; const tempId = results.rows.item(i).subcategory_id;
...@@ -55,7 +49,6 @@ const selectSubCategories = async () => { ...@@ -55,7 +49,6 @@ const selectSubCategories = async () => {
const tempCatId = results.rows.item(i).category_id; const tempCatId = results.rows.item(i).category_id;
temp.push({ id: tempId, value: tempName, foreign_id: tempCatId }); temp.push({ id: tempId, value: tempName, foreign_id: tempCatId });
} }
console.log(temp)
resolve(temp); resolve(temp);
}) })
}) })
...@@ -65,9 +58,7 @@ const selectAssetsType = async () => { ...@@ -65,9 +58,7 @@ const selectAssetsType = async () => {
const db = await getDb(); const db = await getDb();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.transaction(async (tx) => { db.transaction(async (tx) => {
console.log("자산 유형 부르기");
const [txn, results] = await tx.executeSql('SELECT * FROM assets_type'); const [txn, results] = await tx.executeSql('SELECT * FROM assets_type');
console.log('item length', results.rows.length);
const temp = []; const temp = [];
for (let i = 0; i < 3*(Math.ceil((results.rows.length)/3)); i++) { for (let i = 0; i < 3*(Math.ceil((results.rows.length)/3)); i++) {
if (i<results.rows.length){ if (i<results.rows.length){
...@@ -78,7 +69,6 @@ const selectAssetsType = async () => { ...@@ -78,7 +69,6 @@ const selectAssetsType = async () => {
temp.push({ id: 0, value: '' }); temp.push({ id: 0, value: '' });
} }
} }
console.log(temp)
resolve(temp); resolve(temp);
}) })
}) })
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment