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

[SRT-20]: add basic models and CRUD #13

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from 'typeorm';
import { User } from '../../user/entities/user.entity';
import { Area } from 'src/area/entities/area.entity';
import { ValidateIf } from 'class-validator';

export enum Gender {
man = 'man',
Expand Down Expand Up @@ -51,11 +52,15 @@ export class NeighbourProfile {
@Column()
petsDescription: string;

@Column({ nullable: true })
@OneToOne(() => Area)
@JoinColumn()
@ValidateIf((u) => u.city)
Copy link
Contributor

Choose a reason for hiding this comment

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

@ValidateIf((u) => !u.city)

Проверяем, что страна не нулл в том случае, когда город не указан

Copy link
Contributor

Choose a reason for hiding this comment

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

Типа у нас должна быть указана или страна или город, обязательно что-то одно

country: Area;

@Column({ nullable: true })
@OneToOne(() => Area)
@ValidateIf((u) => u.country)
Copy link
Contributor

Choose a reason for hiding this comment

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

А город нужно проверять, если страна не указана

Copy link
Contributor Author

Choose a reason for hiding this comment

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

вроде понял что хочешь

@JoinColumn()
city: Area;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ export class NeighbourProfileService {
return (await this.neighbourProfileRepository.delete({ user })).affected;
}

async getNeighbourProfile(id: number): Promise<NeighbourProfile | never> {
async getNeighbourProfileByUserId(
id: number,
): Promise<NeighbourProfile | never> {
try {
return await this.neighbourProfileRepository.findOneOrFail({
where: { id },
relations: { user: true },
});
} catch (error) {
if (error instanceof EntityNotFoundError) {
Expand Down