Skip to content

Instantly share code, notes, and snippets.

@sushruth
Last active March 10, 2019 08:30
Show Gist options
  • Save sushruth/d91bc2ec8bf76c1f01205118e270735c to your computer and use it in GitHub Desktop.
Save sushruth/d91bc2ec8bf76c1f01205118e270735c to your computer and use it in GitHub Desktop.

Rules to add users

  1. Generate a new GUID somehow
  2. Add the user as a new member to store.users with GUID as the key

Rules to add source

  1. Generate a new GUID somehow
  2. Add the source as a new member to store.sources with GUID as the key
  3. Add this GUID to respective user's sources member
  4. If this is a card,
    • Use final: false and
    • Add source member equal to the key of the source which this card will be paid from
    • Update cumulativeBalance from website
  5. If this is a bank,
    • Use final: true and
    • Ignore source and cumulativeBalance

Rules to add transactions

  1. Generate a new GUID somehow
  2. Add the source as a new member to store.transactions with GUID as the key
  3. Add this GUID to respective user's transactions member
  4. Add this GUID to respective source's transactions member

Deleting a source or transaction should involve cleaning up all the references to it everywhere (in respective user and source)

type GUID = string; // Universal ID of this format -> 729efebf-6916-4092-bb26-f5736be32db0
type Amount = number; // positive -> incoming money, negative -> expenditure
type Status = 'PENDING' | 'DONE';
interface IFinanceEntity {
// Common props
name: string;
}
export interface IUser extends IFinanceEntity {
transactions: GUID[];
sources: GUID[];
}
export interface ISource extends IFinanceEntity {
final?: boolean; // true -> bank, false -> credit-card
previousBalance: Amount; // previous balance as of start of month
cumulativeBalance?: Amount | null; // bank -> null, card -> total balance shown in card website + any pending transaction amounts
source?: null | GUID; // bank -> null, card -> GUID
user: GUID;
transactions: GUID[]; // list of transactions under this source
}
export interface ITransaction extends IFinanceEntity {
description: string;
amount: Amount;
source: GUID;
status: Status;
}
export interface IStore {
users: {
[key: string]: IUser;
};
sources: {
[key: string]: ISource;
};
transactions: {
[key: string]: ITransaction;
};
}
export const initialStore: IStore = {
users: {
'7d7dfa73-6266-4111-9c98-bafcd06492b9': {
name: 'Sushruth S',
transactions: [
'f7095d09-1ca5-477a-95d7-360cb5eba57b',
'2e1725d2-7120-4ee0-9aa9-c870455a3848',
'6a043310-4ac5-495f-b66f-90f1e458d207',
],
sources: [
'ed03c260-8cd7-4d25-a9cb-a78219cad54c',
'19df55b3-775c-4a19-9fe4-b6289e5f5356',
'6567b22d-76fd-40c3-8a51-8f9d22fcf14c',
'8e2931d8-6d6a-4c35-bbce-31b63ef9038c',
'54ff50b2-4f6a-4ec3-83ed-0baa3de7698d',
'b345c7da-8275-4cd0-ac2e-d59d99556feb',
],
},
'27a79a01-7122-406f-9cb5-0535e01d562d': {
name: 'Keerthana P',
transactions: [
'a46cc8a7-8174-401f-82a1-c9d9e68d3eda',
'a4377aae-7f35-461b-809e-82f7634df20a',
'970bc6a2-f555-4d09-9494-ba567e56c1ed',
'954341dc-2f8b-4877-a3fb-bfb78719b6be',
],
sources: [
'18d4d11b-b833-4e1f-9653-23c63889450f',
'6cdf05ab-d212-4c80-a6e5-56cc2fd40694',
'9c90f39b-ed0d-43e1-90a7-784d98a6a2b5',
'dd70891d-01c2-4eb8-937f-c22505fa3847',
],
},
},
sources: {
'ed03c260-8cd7-4d25-a9cb-a78219cad54c': {
name: 'USBANK-4366',
final: true,
previousBalance: 200.13,
user: '7d7dfa73-6266-4111-9c98-bafcd06492b9',
transactions: ['6a043310-4ac5-495f-b66f-90f1e458d207'],
},
'19df55b3-775c-4a19-9fe4-b6289e5f5356': {
name: 'CHASE-3939',
final: true,
previousBalance: 350.49,
user: '7d7dfa73-6266-4111-9c98-bafcd06492b9',
transactions: [
'f7095d09-1ca5-477a-95d7-360cb5eba57b',
'2e1725d2-7120-4ee0-9aa9-c870455a3848',
],
},
'6567b22d-76fd-40c3-8a51-8f9d22fcf14c': {
name: 'DISCOVER-9580',
final: false,
source: '19df55b3-775c-4a19-9fe4-b6289e5f5356',
previousBalance: 0,
user: '7d7dfa73-6266-4111-9c98-bafcd06492b9',
transactions: [],
},
'8e2931d8-6d6a-4c35-bbce-31b63ef9038c': {
name: 'AMEX-2004',
final: false,
previousBalance: 0,
source: 'ed03c260-8cd7-4d25-a9cb-a78219cad54c',
user: '7d7dfa73-6266-4111-9c98-bafcd06492b9',
transactions: [],
},
'54ff50b2-4f6a-4ec3-83ed-0baa3de7698d': {
name: 'CHASE-2331',
final: false,
previousBalance: -35.43,
source: '19df55b3-775c-4a19-9fe4-b6289e5f5356',
user: '7d7dfa73-6266-4111-9c98-bafcd06492b9',
transactions: [],
},
'b345c7da-8275-4cd0-ac2e-d59d99556feb': {
name: 'CITI-3454',
final: false,
previousBalance: -1664.34,
source: '19df55b3-775c-4a19-9fe4-b6289e5f5356',
user: '7d7dfa73-6266-4111-9c98-bafcd06492b9',
transactions: [],
},
'18d4d11b-b833-4e1f-9653-23c63889450f': {
name: 'USBANK-9880',
final: true,
previousBalance: 10540.54,
user: '27a79a01-7122-406f-9cb5-0535e01d562d',
transactions: ['954341dc-2f8b-4877-a3fb-bfb78719b6be'],
},
'6cdf05ab-d212-4c80-a6e5-56cc2fd40694': {
name: 'CHASE-5435',
final: true,
previousBalance: 340.64,
user: '27a79a01-7122-406f-9cb5-0535e01d562d',
transactions: [],
},
'9c90f39b-ed0d-43e1-90a7-784d98a6a2b5': {
name: 'DISCOVER-3470',
final: false,
previousBalance: 0,
source: '18d4d11b-b833-4e1f-9653-23c63889450f',
user: '27a79a01-7122-406f-9cb5-0535e01d562d',
transactions: [],
},
'dd70891d-01c2-4eb8-937f-c22505fa3847': {
name: 'CHASE-2581',
final: false,
previousBalance: 0,
user: '27a79a01-7122-406f-9cb5-0535e01d562d',
cumulativeBalance: 1905.34,
transactions: [
'a46cc8a7-8174-401f-82a1-c9d9e68d3eda',
'a4377aae-7f35-461b-809e-82f7634df20a',
'970bc6a2-f555-4d09-9494-ba567e56c1ed',
],
},
},
transactions: {
'f7095d09-1ca5-477a-95d7-360cb5eba57b': {
name: 'Zelle transaction*Kym',
description: '13014 Rent',
amount: 2050.0,
source: '19df55b3-775c-4a19-9fe4-b6289e5f5356',
status: 'PENDING',
},
'a46cc8a7-8174-401f-82a1-c9d9e68d3eda': {
name: 'Puget sound energy',
description: 'Gas + Electricity',
amount: 200.4,
source: 'dd70891d-01c2-4eb8-937f-c22505fa3847',
status: 'DONE',
},
'a4377aae-7f35-461b-809e-82f7634df20a': {
name: 'Tmobile',
description: 'Tmobile',
amount: 217.65,
source: 'dd70891d-01c2-4eb8-937f-c22505fa3847',
status: 'PENDING',
},
'970bc6a2-f555-4d09-9494-ba567e56c1ed': {
name: 'Xfinity',
description: 'Internet',
amount: 67.8,
source: 'dd70891d-01c2-4eb8-937f-c22505fa3847',
status: 'DONE',
},
'2e1725d2-7120-4ee0-9aa9-c870455a3848': {
name: 'DCU Financial',
description: 'Mustang Car payment',
amount: 473.09,
source: '19df55b3-775c-4a19-9fe4-b6289e5f5356',
status: 'DONE',
},
'6a043310-4ac5-495f-b66f-90f1e458d207': {
name: 'Remitly Send 033304099',
description: 'Appa money',
amount: 400.0,
source: 'ed03c260-8cd7-4d25-a9cb-a78219cad54c',
status: 'DONE',
},
'954341dc-2f8b-4877-a3fb-bfb78719b6be': {
name: 'GMFINANCE',
description: 'Malibu Car Payment',
amount: 362.95,
source: '18d4d11b-b833-4e1f-9653-23c63889450f',
status: 'DONE',
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment