2022-09-06 14:32:16 +00:00
|
|
|
import { ArgumentMetadata, Injectable, PipeTransform } from '@nestjs/common';
|
2022-07-19 12:54:02 +00:00
|
|
|
import { Fail, FT } from 'picsur-shared/dist/types';
|
2022-04-16 15:22:50 +00:00
|
|
|
import { UUIDRegex } from 'picsur-shared/dist/util/common-regex';
|
2022-03-28 13:43:52 +00:00
|
|
|
|
|
|
|
@Injectable()
|
2022-04-18 12:34:53 +00:00
|
|
|
export class ImageIdPipe implements PipeTransform<string, string> {
|
2022-03-28 13:43:52 +00:00
|
|
|
transform(value: string, metadata: ArgumentMetadata): string {
|
2022-04-16 15:22:50 +00:00
|
|
|
if (UUIDRegex.test(value)) return value;
|
2022-07-19 12:54:02 +00:00
|
|
|
throw Fail(FT.UsrValidation, 'Invalid image id');
|
2022-03-28 13:43:52 +00:00
|
|
|
}
|
|
|
|
}
|