Some checks failed
Music Collection CI Workflow / test (./frontend) (push) Has been cancelled
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/music-collection-backend, ./backend) (push) Has been cancelled
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Has been cancelled
Music Collection CI Workflow / deploy (push) Has been cancelled
Music Collection CI Workflow / test (./backend) (push) Has been cancelled
33 lines
1019 B
TypeScript
33 lines
1019 B
TypeScript
import { registerDecorator, ValidationOptions, ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
|
|
@ValidatorConstraint({ async: true })
|
|
export class UniqueAlbumTitle implements ValidatorConstraintInterface {
|
|
constructor(@InjectRepository(Album)
|
|
private albumRepository: Repository<Album>
|
|
) {}
|
|
|
|
validate(albumTitle: string) {
|
|
return this.albumRepository.findOneBy({
|
|
where: {
|
|
id: title
|
|
}).then((albumTitle) => {
|
|
return albumTitle === undefined;
|
|
});
|
|
}
|
|
}
|
|
|
|
export function AlbumTitleUnique(validationOptions?: ValidationOptions) {
|
|
return function (object: object, propertyName: string) {
|
|
registerDecorator({
|
|
target: object.constructor,
|
|
propertyName: propertyName,
|
|
options: validationOptions,
|
|
constraints: [],
|
|
validator: AlbumTitleUnique,
|
|
});
|
|
};
|
|
}
|