Database - matai-2020/ABA GitHub Wiki

Database Functions:

Location:

server/db/users.js

getUser()

  • Returns a user object, e.g.:
{ 
    id: 9,
    userName: 'emily', 
    email: [email protected],
    password: 'myPassword'

}

getUserBudget(id)

  • Takes integer id as a parameter and returns a single budget object, e.g.:
{ 
    id: 9,
    userId: 9,
    incomes: [{amount: 40000, occurrence: annual}, {amount: 20000, occurrence: null}],
    expenses: [{name: 'rent', amount: 500, category: accommodation, occurrence: weekly, date: ???}, {name: 'food', amount: 150, category: 
              living, occurrence: weekly, date: ???}] 
}

addBudget(newBudget)

  • Takes object newBuget as a parameter (e.g. shown below), return value dependent on database.
{ 
    userId: 28,
    incomes: [{amount: 40000, occurrence: annual}, {amount: 20000, occurrence: null}],
    expenses: [{name: 'rent', amount: 500, category: accommodation, occurrence: weekly, date: ???}, {name: 'food', amount: 150, category: 
               living, occurrence: weekly, date: ???}]
   
}

editBudget(editedBudget)

  • Takes object editedBudget (representing the parts of the record that are being changed) as a parameter and returns an edited object:
{
    id: 28,
    incomes: [{amount: 45000, occurrence: annual}]
    expenses: [{name: 'rent', amount: 700, category: accommodation, occurrence: weekly, date: ???}]
    user_id: 2
}

deleteBudget(id)

  • Takes integer 'id' and deletes item with that id. Error handling covered by server-side route.
returns 1 if successful, 0 if not