diff --git a/src/mirage/factories/balance.js b/src/mirage/factories/balance.js index 9be7f27..41d6882 100644 --- a/src/mirage/factories/balance.js +++ b/src/mirage/factories/balance.js @@ -1,6 +1,6 @@ -import { Factory } from "miragejs" +import { Factory } from 'miragejs'; import faker from 'faker'; export default Factory.extend({ - amount: () => faker.finance.amount(), + amount: () => parseFloat(faker.finance.amount()) }); diff --git a/src/mirage/routes/index.js b/src/mirage/routes/index.js index b1a28a8..d33eafa 100644 --- a/src/mirage/routes/index.js +++ b/src/mirage/routes/index.js @@ -33,7 +33,7 @@ export const setupRoutes = (server) => { // Transaction routes server.get('/last-transactions', (schema) => { let allTransactions = schema.transactions.all(); - // Sort by newest first TODO: verify + // Sort by newest first allTransactions = allTransactions.sort((a, b) => { return a.createdAt > b.createdAt ? -1 : 1; }); @@ -44,8 +44,10 @@ export const setupRoutes = (server) => { server.post('/transactions', (schema, { requestBody }) => { const model = schema.transactions.create(requestBody); - // Reconvert amount to negative value, as it is an outgoing transaction - model.update({ amount: model.amount * -1 }); + model.update({ + createdAt: new Date(), + isReceiving: false + }); // TODO: Change serializer to singularize rootKey return { transaction: model.toJSON() }; @@ -63,6 +65,13 @@ export const setupRoutes = (server) => { }); server.get('/transactions', (schema) => { - return schema.transactions.all(); + let allTransactions = schema.transactions.all(); + + // Sort by newest first + allTransactions = allTransactions.sort((a, b) => { + return a.createdAt > b.createdAt ? -1 : 1; + }); + + return allTransactions; }); };