- project description: https://www.notion.so/wecode/65e388949475423385bec18e9ceec8d1
- git clone:
$ git clone http://github.com/jieunkxx/project-assignment-class.git
- Install dependencies:
$ npm install
- build:
$ npm run build
- start the server
$ npm run start
-
add credits
- require user id through req.params
- require credit value ( value: integer) and created date (date: Date) as an object through req.body
- if credit created on the same date exists, add up the credit value to the existing value
- if credit does not exist on the same date, create new data row
-
use credits
- require user id through req.params
- require credit value ( value: integer) and date (date: Date) of the day to be used as an object through req.body
- check if there is valid credit left.
- condition1: credit has not been passed 90 days since it was created
- condition2: credit has not been used
- if so, use them from oldest dated credit. mark as used and move to the next oldest date available credit. Update credit value.
- if not, throws a custom error.
-
get available credits
- require user id through req.params
- require target date (date: Date) as an object through req.body
- check target date and created date of each credit data row
- Returns all credit data with (target date - creatd date < 90) && (used === false)
-
refund credits
- require user id through req.params
- require credit value ( value: integer) and created date (date: Date) as an object through req.body
- if there is no credit exist that was created at on the given created date, throws a custom error
- if there is credit exist that was created at on the given created date, but not enough credit left, throws a custom error
- if there is credit exist that was created at on the given created data and has enough credit left,
-
- update credit value if (value - current value > 0)
-
- delete credit data raw if (value - current value === 0)
-
-
Create Queue Class using Node and Linked List
- constructor queue with head: Node, tail: Node, length: number
-
Methods:
enqueue(item)
,dequeue()
,pop(index)
,get_length()
- enqueue(item)
- insert item at the end of the queue
- update head, tail in accordance with the number of items left
- update length (length++)
- Time complexity: O(1)
- dequeue()
- get item at the beginning of the queue and remove it
- update head, tail in accordance with the number of items left
- if queue is empty, throw a custom error
- update length (length--)
- Time complexity: O(1)
- pop(index)
- returns item at the indexed position and removes it
- traverse queue until indexed position returned.
- update head, tail in accordance with the number of items left
- if queue is empty or item does not exist at the postion, throw a custom error
- update length (length--)
- return queue
- Time complexity: O(n)
- get_length()
- returns this.length
- Time complexity: O(1)
- enqueue(item)
- Run tests
$npm run test
- Unit Tests for credit system is being updated.
- Unit Tests for Queue has been completed.