mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-03-10 19:51:46 +00:00
- Introduced optional timezone fields in User and Device entities to store user preferences and device timezones. - Updated request DTOs for login and user updates to include timezone information. - Enhanced AuthService to handle timezone during device registration and updates. - Added migration to incorporate timezone fields in the database schema.
128 lines
4.8 KiB
TypeScript
128 lines
4.8 KiB
TypeScript
import { ApiProperty } from '@nestjs/swagger';
|
|
import {
|
|
IsEnum,
|
|
IsNotEmpty,
|
|
IsNumberString,
|
|
IsOptional,
|
|
IsString,
|
|
Matches,
|
|
MaxLength,
|
|
MinLength,
|
|
} from 'class-validator';
|
|
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
|
import { COUNTRY_CODE_REGEX, PASSWORD_REGEX } from '~/auth/constants';
|
|
import { CountryIso } from '~/common/enums';
|
|
import { DEFAULT_OTP_LENGTH } from '~/common/modules/otp/constants';
|
|
import { IsValidPhoneNumber } from '~/core/decorators/validations';
|
|
|
|
export class VerifyUserRequestDto {
|
|
@ApiProperty({ example: '+962' })
|
|
@Matches(COUNTRY_CODE_REGEX, {
|
|
message: i18n('validation.Matches', { path: 'general', property: 'auth.countryCode' }),
|
|
})
|
|
countryCode!: string;
|
|
|
|
@ApiProperty({ example: '787259134' })
|
|
@IsValidPhoneNumber({
|
|
message: i18n('validation.IsValidPhoneNumber', { path: 'general', property: 'auth.phoneNumber' }),
|
|
})
|
|
phoneNumber!: string;
|
|
@ApiProperty({ example: 'John' })
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'customer.firstName' }) })
|
|
@IsNotEmpty({ message: i18n('validation.IsNotEmpty', { path: 'general', property: 'customer.firstName' }) })
|
|
firstName!: string;
|
|
|
|
@ApiProperty({ example: 'Doe' })
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'customer.lastName' }) })
|
|
@IsNotEmpty({ message: i18n('validation.IsNotEmpty', { path: 'general', property: 'customer.lastName' }) })
|
|
lastName!: string;
|
|
|
|
@ApiProperty({ example: 'JO' })
|
|
@IsEnum(CountryIso, {
|
|
message: i18n('validation.IsEnum', { path: 'general', property: 'customer.countryOfResidence' }),
|
|
})
|
|
@IsOptional()
|
|
countryOfResidence: CountryIso = CountryIso.SAUDI_ARABIA;
|
|
|
|
// Address fields (optional during registration, required for card creation)
|
|
@ApiProperty({ example: 'SA', description: 'Country code', required: false })
|
|
@IsEnum(CountryIso, {
|
|
message: i18n('validation.IsEnum', { path: 'general', property: 'customer.country' }),
|
|
})
|
|
@IsOptional()
|
|
country?: CountryIso;
|
|
|
|
@ApiProperty({ example: 'Riyadh', description: 'Region/Province', required: false })
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'customer.region' }) })
|
|
@IsOptional()
|
|
region?: string;
|
|
|
|
@ApiProperty({ example: 'Riyadh', description: 'City', required: false })
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'customer.city' }) })
|
|
@IsOptional()
|
|
city?: string;
|
|
|
|
@ApiProperty({ example: 'Al Olaya', description: 'Neighborhood/District', required: false })
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'customer.neighborhood' }) })
|
|
@IsOptional()
|
|
neighborhood?: string;
|
|
|
|
@ApiProperty({ example: 'King Fahd Road', description: 'Street name', required: false })
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'customer.street' }) })
|
|
@IsOptional()
|
|
street?: string;
|
|
|
|
@ApiProperty({ example: '123', description: 'Building number', required: false })
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'customer.building' }) })
|
|
@IsOptional()
|
|
building?: string;
|
|
|
|
@ApiProperty({ example: 'Abcd1234@' })
|
|
@Matches(PASSWORD_REGEX, {
|
|
message: i18n('validation.Matches', { path: 'general', property: 'auth.password' }),
|
|
})
|
|
password!: string;
|
|
|
|
@ApiProperty({ example: 'Abcd1234@' })
|
|
@Matches(PASSWORD_REGEX, {
|
|
message: i18n('validation.Matches', { path: 'general', property: 'auth.confirmPassword' }),
|
|
})
|
|
confirmPassword!: string;
|
|
|
|
@ApiProperty({ example: '111111' })
|
|
@IsNumberString(
|
|
{ no_symbols: true },
|
|
{ message: i18n('validation.IsNumberString', { path: 'general', property: 'auth.otp' }) },
|
|
)
|
|
@MaxLength(DEFAULT_OTP_LENGTH, {
|
|
message: i18n('validation.MaxLength', { path: 'general', property: 'auth.otp', length: DEFAULT_OTP_LENGTH }),
|
|
})
|
|
@MinLength(DEFAULT_OTP_LENGTH, {
|
|
message: i18n('validation.MinLength', { path: 'general', property: 'auth.otp', length: DEFAULT_OTP_LENGTH }),
|
|
})
|
|
otp!: string;
|
|
|
|
@ApiProperty({ example: 'device-123', description: 'Unique device identifier', required: false })
|
|
@IsOptional()
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'auth.deviceId' }) })
|
|
deviceId?: string;
|
|
|
|
@ApiProperty({
|
|
example: 'cXYzABC:APA91bHunvwY7rKpn8N7y6vDxS0qmQ5RZx2C8K...',
|
|
description: 'Firebase Cloud Messaging token for push notifications',
|
|
required: false,
|
|
})
|
|
@IsOptional()
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'auth.fcmToken' }) })
|
|
fcmToken?: string;
|
|
|
|
@ApiProperty({
|
|
example: 'Asia/Riyadh',
|
|
description: 'Device timezone (auto-detected from device OS)',
|
|
required: false,
|
|
})
|
|
@IsOptional()
|
|
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'auth.timezone' }) })
|
|
timezone?: string;
|
|
}
|