Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop' into feat/seed-account
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovic authored Jan 21, 2022
2 parents 3651c3a + 64286e6 commit ea2cc97
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 115 deletions.
65 changes: 31 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@nestjs/passport": "^8.0.1",
"@nestjs/platform-express": "^8.2.4",
"@nestjs/swagger": "^5.1.5",
"@prisma/client": "^3.6.0",
"@prisma/client": "^3.8.1",
"@types/faker": "^5.5.9",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
Expand Down Expand Up @@ -83,7 +83,7 @@
"husky": "^7.0.4",
"jest": "^27.2.5",
"prettier": "^2.3.2",
"prisma": "^3.6.0",
"prisma": "^3.8.1",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
Expand Down
18 changes: 13 additions & 5 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ model City {
name String
postalCode String
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
users User[]
users User[]
}

model User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
firstName String
lastName String
avatar String
username String @unique
birthDate DateTime? @db.Timestamptz(6)
email String @unique
sex Int @default(0)
latitude Float?
latitude Float?
longitude Float?
cityId String @db.Uuid()
avatarId String? @db.Uuid
cityId String @db.Uuid
File File? @relation(fields: [avatarId], references: [id])
city City @relation(fields: [cityId], references: [id])
animals Animal[]
}
Expand All @@ -55,3 +56,10 @@ model Animal {
user User @relation(fields: [userId], references: [id])
breeds Breed[]
}

model File {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
fileName String
data Bytes
User User[]
}
2 changes: 1 addition & 1 deletion prisma/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const prisma = new PrismaClient();

export const seedUsers = async (): Promise<void> => {
const cities = await prisma.city.findMany();
const avatars = await prisma.city.findMany();
const promises: Promise<User>[] = [];

for (let index = 0; index < 10; index++) {
Expand All @@ -19,7 +20,6 @@ export const seedUsers = async (): Promise<void> => {
sex: 1,
latitude: 44.837789 + generateRandomFloatInRange(-0.5, 0.5),
longitude: -0.57918 + generateRandomFloatInRange(-0.5, 0.5),
avatar: '',
};
promises.push(prisma.user.create({ data: items }));
}
Expand Down
13 changes: 9 additions & 4 deletions src/animal/animal.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Delete,
} from '@nestjs/common';
import { Animal } from '@prisma/client';
import { CreateAnimalDto, Id, AnimalDto, FilterDto } from 'src/dtos';
import { CreateAnimalDto, FilterDto } from 'src/dtos';

import { AnimalService } from './animal.service';

Expand All @@ -18,8 +18,13 @@ export class AnimalController {
constructor(private readonly animalService: AnimalService) {}

@Get('/')
async list(@Query() query: FilterDto | undefined): Promise<Animal[]> {
return await this.animalService.list({ where: { name: query.search } });
async list(@Query() query: FilterDto<Animal> | undefined): Promise<Animal[]> {
return await this.animalService.list({
skip: parseInt(query.skip) || 0,
take: parseInt(query.take) || 20,
orderBy: { name: query.order },
where: { name: query.search },
});
}

@Get('/:id')
Expand Down Expand Up @@ -47,7 +52,7 @@ export class AnimalController {
): Promise<Animal> {
return await this.animalService.update({
where: { id: id },
data: animal,
data: { ...animal, user: { connect: animal.user.connect } },
});
}

Expand Down
11 changes: 8 additions & 3 deletions src/animal/breed.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Delete,
} from '@nestjs/common';
import { Breed } from '@prisma/client';
import { CreateBreedDto, Id, BreedDto, FilterDto } from 'src/dtos';
import { CreateBreedDto, FilterDto } from 'src/dtos';

import { BreedService } from './breed.service';

Expand All @@ -18,8 +18,13 @@ export class BreedController {
constructor(private readonly breedService: BreedService) {}

@Get('/')
async list(@Query() query: FilterDto | undefined): Promise<Breed[]> {
return await this.breedService.list({ where: { name: query.search } });
async list(@Query() query: FilterDto<Breed> | undefined): Promise<Breed[]> {
return await this.breedService.list({
skip: parseInt(query.skip) || 0,
take: parseInt(query.take) || 20,
orderBy: { name: query.order },
where: { name: query.search },
});
}

@Get('/:id')
Expand Down
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { UserModule } from './user/user.module';
PrismaService,
AuthModule,
ConfigModule,
UserModule,
CityModule,
UserModule,
AnimalModule,
BreedModule,
],
Expand Down
4 changes: 2 additions & 2 deletions src/dtos/animals/animal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export class CreateAnimalDto {
}

export class AnimalDto extends CreateAnimalDto {
@ApiProperty()
@ApiProperty({ type: () => BreedDto })
public breeds?: RelationsInput<BreedDto>;

@ApiProperty()
@ApiProperty({ type: () => UserDto })
public user: RelationInput<UserDto>;

@ApiProperty()
Expand Down
Empty file removed src/dtos/image/.gitkeep
Empty file.
32 changes: 32 additions & 0 deletions src/dtos/image/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';

import { IsNotEmpty, IsString, IsUUID } from 'class-validator';
import { UserDto } from '..';
import { RelationInput } from '../utils';

export class CreateFileDto {
@ApiProperty()
@IsString()
@IsNotEmpty()
public fileName!: string;

@ApiProperty()
@IsNotEmpty()
public data!: any;

@ApiProperty({ type: () => UserDto })
@IsNotEmpty()
@Type(() => UserDto)
public user!: RelationInput<UserDto>;
}

export class FileDto extends CreateFileDto {
@ApiProperty({ type: () => UserDto })
public user!: RelationInput<UserDto>;

@ApiProperty()
@IsNotEmpty()
@IsUUID(4)
public id!: string;
}
10 changes: 5 additions & 5 deletions src/dtos/users/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from 'class-validator';
import { CityDto } from '.';
import { AnimalDto } from '..';
import { FileDto } from '../image/file';
import { Id, RelationInput, RelationsInput } from '../utils';

export class CreateUserDto {
Expand All @@ -29,10 +30,6 @@ export class CreateUserDto {
@IsNotEmpty()
public username: string;

@ApiProperty()
@IsString()
public avatar: string;

@ApiProperty()
@IsISO8601()
@IsOptional()
Expand Down Expand Up @@ -65,12 +62,15 @@ export class CreateUserDto {
}

export class UserDto extends CreateUserDto {
@ApiProperty()
@ApiProperty({ type: () => CityDto })
public city: RelationInput<CityDto>;

@ApiProperty({ type: () => AnimalDto })
public animals: RelationsInput<UserDto>;

@ApiProperty({ type: () => FileDto })
public avatar?: RelationInput<FileDto>;

@ApiProperty()
@IsNotEmpty()
@IsUUID(4)
Expand Down
Loading

0 comments on commit ea2cc97

Please sign in to comment.