Skip to content

Commit

Permalink
improve DTOs with helpers, and other clean up (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
jd2rogers2 authored Mar 22, 2022
1 parent fc08972 commit 7656338
Show file tree
Hide file tree
Showing 16 changed files with 2,240 additions and 36,661 deletions.
21,577 changes: 49 additions & 21,528 deletions client/package-lock.json

Large diffs are not rendered by default.

17,194 changes: 2,102 additions & 15,092 deletions server/package-lock.json

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions server/src/assets/dto/create-asset.dto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { PartialType } from '@nestjs/mapped-types';
import { Asset } from '../entities/asset.entity';
import { User } from 'src/users/entities/user.entity';
import { IsNotEmpty, IsEnum, IsOptional } from 'class-validator';

import { User } from '../../users/entities/user.entity';
import { AssetType, Condition } from '../constants';

export class CreateAssetDto extends PartialType(Asset) {
export class CreateAssetDto {
@IsNotEmpty()
title: string;

@IsNotEmpty()
description: string;
poster_id: User;

@IsNotEmpty()
poster: User;

@IsOptional()
@IsEnum(AssetType)
type: AssetType;

@IsOptional()
@IsEnum(Condition)
condition: Condition;
}
2 changes: 1 addition & 1 deletion server/src/assets/dto/update-asset.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PartialType } from '@nestjs/mapped-types';

import { CreateAssetDto } from './create-asset.dto';

//look at nest docs
export class UpdateAssetDto extends PartialType(CreateAssetDto) {}
3 changes: 2 additions & 1 deletion server/src/auth/get-user.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { User } from 'src/users/entities/user.entity';

import { User } from '../users/entities/user.entity';

export const GetUser = createParamDecorator((_data, ctx: ExecutionContext): User => {
const req = ctx.switchToHttp().getRequest();
Expand Down
4 changes: 2 additions & 2 deletions server/src/categories/categories.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
HttpStatus,
} from '@nestjs/common';
import { CategoriesService } from './categories.service';
import { CreateCategoryDto } from './dto/create-category';
import { UpdateCategoryDto } from './dto/update-category';
import { CreateCategoryDto } from './dto/create-category.dto';
import { UpdateCategoryDto } from './dto/update-category.dto';
import { Category } from './entities/category.entity';
import { DeleteResult } from 'typeorm';

Expand Down
4 changes: 2 additions & 2 deletions server/src/categories/categories.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { CreateCategoryDto } from './dto/create-category';
import { UpdateCategoryDto } from './dto/update-category';
import { CreateCategoryDto } from './dto/create-category.dto';
import { UpdateCategoryDto } from './dto/update-category.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { DeleteResult, Repository } from 'typeorm';
import { Category } from './entities/category.entity';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { IsNotEmpty, IsOptional } from 'class-validator';

export class CreateCategoryDto {
@IsNotEmpty()
name: string;

@IsOptional()
applies_to_assets: boolean;

@IsOptional()
applies_to_organizations: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateCategoryDto } from './create-category';
import { CreateCategoryDto } from './create-category.dto';

export class UpdateCategoryDto extends PartialType(CreateCategoryDto) {}
16 changes: 11 additions & 5 deletions server/src/messages/dto/create-message.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { PartialType } from '@nestjs/mapped-types';
import { User } from 'src/users/entities/user.entity';
import { Message } from '../entities/message.entity';
import { IsNotEmpty, IsEnum, IsOptional } from 'class-validator';

export class CreateMessageDto extends PartialType(Message) {
import { User } from '../../users/entities/user.entity';
import { Transaction } from '../../transactions/entities/transaction.entity';

export class CreateMessageDto {
@IsNotEmpty()
text: string;

@IsNotEmpty()
user: User;
transaction_id: number; // remove once Transaction is set up and a relationship is used in the entity

@IsNotEmpty()
transaction: Transaction;
}
14 changes: 4 additions & 10 deletions server/src/messages/entities/message.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
CreateDateColumn,
JoinColumn,
} from 'typeorm';

import { User } from '../../users/entities/user.entity';
// import { Transaction } from '../../transactions/entities/transaction.entity'
import { Transaction } from '../../transactions/entities/transaction.entity';

@Entity('messages')
export class Message {
Expand All @@ -27,13 +28,6 @@ export class Message {
@JoinColumn()
user: User;

// TODO: uncomment the code below when transactions are set up
// make sure to set up corresponding relationship in transactions
// and note the ramifications on MessageInboxView component before updating

// @ManyToOne(() => Transaction, transaction => transaction.messages)
// transaction: Transaction

@Column('int')
transaction_id: number;
@ManyToOne(() => Transaction, (transaction) => transaction.messages)
transaction: Transaction;
}
20 changes: 18 additions & 2 deletions server/src/organizations/dto/create-organization.dto.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { Organization } from '../entities/organization.entity';
import { PartialType } from '@nestjs/mapped-types';
import { IsNotEmpty } from 'class-validator';

export class CreateOrganizationDto {
@IsNotEmpty()
name: string;

@IsNotEmpty()
description: string;

@IsNotEmpty()
website: string;

@IsNotEmpty()
address: string;

@IsNotEmpty()
phone: string;

@IsNotEmpty()
city: string;

@IsNotEmpty()
state: string;

@IsNotEmpty()
ein: number;

@IsNotEmpty()
tax_exempt_id: number;
}
8 changes: 4 additions & 4 deletions server/src/transactions/dto/create-transaction.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { IsNotEmpty, IsEnum, IsOptional } from 'class-validator';

import { TransactionStatus } from '../transaction-status.enum';

import type { User } from 'src/users/entities/user.entity';
import type { Organization } from 'src/organizations/entities/organization.entity';
import type { Asset } from 'src/assets/entities/asset.entity';
import type { User } from '../../users/entities/user.entity';
import type { Organization } from '../../organizations/entities/organization.entity';
import type { Asset } from '../../assets/entities/asset.entity';

export class CreateTransactionDto {
@IsNotEmpty()
Expand All @@ -15,7 +16,6 @@ export class CreateTransactionDto {
@IsOptional()
recipient: Organization;

// custom message for example, not necessary to code
@IsNotEmpty({ message: 'asset_id is required' })
asset: Asset;

Expand Down
14 changes: 10 additions & 4 deletions server/src/transactions/entities/transaction.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {
Entity,
JoinColumn,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
} from 'typeorm';
import { TransactionStatus } from '../transaction-status.enum';
import { User } from '../../users/entities/user.entity';
import { Asset } from '../../assets/entities/asset.entity';
import { Organization } from '../../organizations/entities/organization.entity';
import { Message } from '../../messages/entities/message.entity';

@Entity('transactions')
export class Transaction {
Expand All @@ -26,19 +28,23 @@ export class Transaction {
@CreateDateColumn()
created_date: Date;

@ManyToOne((_type) => User, (user) => user.transactions)
@ManyToOne(() => User, (user) => user.transactions)
@JoinColumn()
donater_user: User;

@ManyToOne((_type) => Organization, (organization) => organization.transactions)
@ManyToOne(() => Organization, (organization) => organization.transactions)
@JoinColumn()
donater_organization?: Organization;

@ManyToOne((_type) => Asset, (asset) => asset.transactions, { eager: true })
@ManyToOne(() => Asset, (asset) => asset.transactions, { eager: true })
@JoinColumn()
asset: Asset;

@ManyToOne((_type) => Organization, (recipient) => recipient.transactions)
@ManyToOne(() => Organization, (recipient) => recipient.transactions)
@JoinColumn()
recipient: Organization;

@OneToMany(() => Message, (message) => message.transaction)
@JoinColumn()
messages: Message;
}
2 changes: 1 addition & 1 deletion server/src/user-org/entities/user-org.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ export class UserOrganization {
user!: User;

@CreateDateColumn()
created_at: Date;
created_date: Date;
}
13 changes: 10 additions & 3 deletions server/src/users/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { PartialType } from '@nestjs/mapped-types';
import { User } from '../entities/user.entity';
import { IsEmail, IsNotEmpty } from 'class-validator';

export class CreateUserDto extends PartialType(User) {
export class CreateUserDto {
@IsNotEmpty()
first_name: string;

@IsNotEmpty()
last_name: string;

@IsNotEmpty()
@IsEmail()
email: string;

@IsNotEmpty()
password: string;
}

0 comments on commit 7656338

Please sign in to comment.