Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create transactions resource #92

Merged
merged 61 commits into from
Jan 30, 2022
Merged

Create transactions resource #92

merged 61 commits into from
Jan 30, 2022

Conversation

DXRovang
Copy link
Contributor

@DXRovang DXRovang commented Dec 6, 2021

Dev Summary

adding the transactions resource here. this is a key part of our data model. this is how users will claim/give assets.
this includes the standard parts of a new resource (controller, service, module, entity, dtos, etc.)

Test Plan

repro steps:

  1. npm run start:dev
  2. seed some data if you need
curl -X POST localhost:3001/api/users \
-H "Content-Type: application/json" \
-d '{ "first_name": "test", "last_name": "user", "password": "password", "email": "[email protected]" }'

curl -X POST localhost:3001/api/users \
-H "Content-Type: application/json" \
-d '{ "first_name": "test", "last_name": "user2", "password": "password", "email": "[email protected]" }'

# except below should have the id that one of the user create requests returned
curl -X POST localhost:3001/api/assets \
-H "Content-Type: application/json" \
-d '{ "title": "thing 1", "description": "its a thing", "type": "donation", "quantity": "1",
"poster": { "first_name":"test", "last_name":"user", "email":"[email protected]", "id": "18" } }'

curl -X POST localhost:3001/api/organizations \
-H "Content-Type: application/json" -d '{
  "name": "name",
  "description": "description",
  "website": "website.com",
  "address": "address",
  "phone": "phone",
  "city": "seattle",
  "state": "wa",
  "ein": "1",
  "tax_exempt_id": "1"
}'
  1. create transaction
# below should use the other created user's id
jamesrogers@jamesrogpremiseMBP-2 web-app % curl -X POST localhost:3001/api/transactions \
-H "Content-Type: application/json" -d '{ "donater_user": "19", "asset": "1" }'
{"donater_user":"19","asset":"1","id":3,"status":"IN_PROGRESS","created_date":"2022-01-22"}%      
jamesrogers@jamesrogpremiseMBP-2 web-app % 
  1. update transaction status and with recipient org
jamesrogers@jamesrogpremiseMBP-2 web-app % curl -X PATCH localhost:3001/api/transactions/3 \
-H "Content-Type: application/json" -d '{ "status": "COMPLETED", "recipient": "1"}' 
{"id":3,"status":"COMPLETED","created_date":"2022-01-22","asset":{"id":1,"title":"thing 1","description":"its a thing","type":"donation","condition":"","quantity":1},"recipient":"1"}%             
jamesrogers@jamesrogpremiseMBP-2 web-app % 
  1. get all transactions
    expect there to be one
jamesrogers@jamesrogpremiseMBP-2 web-app % curl localhost:3001/api/transactions 
[{"id":3,"status":"COMPLETED","created_date":"2022-01-22","asset":{"id":1,"title":"thing 1","description":"its a thing","type":"donation","condition":"","
  1. delete the transaction
    then get all transactions again and expect it to be empty
jamesrogers@jamesrogpremiseMBP-2 web-app % curl -X DELETE localhost:3001/api/transactions/3
jamesrogers@jamesrogpremiseMBP-2 web-app % curl localhost:3001/api/transactions            
[]%       

Resources

@DXRovang DXRovang requested a review from jd2rogers2 December 6, 2021 17:11
@jd2rogers2 jd2rogers2 marked this pull request as ready for review January 23, 2022 01:41
@jd2rogers2 jd2rogers2 modified the milestone: test Jan 26, 2022

export class CreateTransactionDto {
@IsNotEmpty()
donater_user: User;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix:

Should be:

 @IsNotEmpty()
  donater_user_id: number;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, are you sure?
would nest know to add a .donater attr or function to the transation model then? now that i think about it, idk how to control the model in nest, like if i wanted to write a custom function like asset.close() (that updates the status to all the transactions related to that asset, how would i do that?

Copy link
Contributor

@esteban-gs esteban-gs Jan 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at your example,

This:

curl -X POST localhost:3001/api/assets \
-H "Content-Type: application/json" \
-d '{ "title": "thing 1", "description": "its a thing", "type": "donation", "quantity": "1",
"poster": { "first_name":"test", "last_name":"user", "email":"[email protected]", "id": "18" } }'

can be replaced by example below, if you change the createDto to use poster_id instead of a whole new poster object. The return type will be whatever the repository returns (transactionEntity):

curl -X POST localhost:3001/api/assets \
-H "Content-Type: application/json" \
-d '{ "title": "thing 1", "description": "its a thing", "type": "donation", "quantity": "1",
"poster_id": 18 }'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, you would have to implement something like: create-transactions-resource...sample/create-transactions-resource

Also, if you are going to stick with the getTransactionsDto as the get all filtering model, there is some funky formatting we have to do in the front end to send the nested object in the url query params. See this

Comment on lines +12 to +13
@IsOptional()
donater_organization: Organization;
Copy link
Contributor

@esteban-gs esteban-gs Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix:

Should be:

 @IsNotEmpty()
  donater_organization_id: number;

Comment on lines +15 to +17
@IsOptional()
recipient: Organization;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, only the foreign key is required

Comment on lines +19 to +20
@IsNotEmpty({ message: 'asset_id is required' })
asset: Asset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, only the foreign key is required

Copy link
Contributor

@esteban-gs esteban-gs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@jd2rogers2 jd2rogers2 requested a review from esteban-gs January 29, 2022 21:26
Comment on lines 26 to 28
@IsOptional()
@IsNotEmpty()
created_date: Date;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't these cancel each other?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally 😆
removed altogether because the default value should be used and so we don't need to pass anything in

@esteban-gs esteban-gs self-requested a review January 30, 2022 08:27
@jd2rogers2 jd2rogers2 merged commit 9639696 into main Jan 30, 2022
@jd2rogers2 jd2rogers2 deleted the create-transactions-resource branch January 30, 2022 19:19
@jd2rogers2 jd2rogers2 mentioned this pull request Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create Transactions resource
3 participants