fix: managed user timeZone, timeFormat and weekStart during creation (#14955)
* refactor: create, update user inputs use types instead of custom validators * fix: save weekStart, timeFormat, timeZone when creating user * fix: save weekStart, timeFormat, timeZone when creating user * e2e: fix env variables and test weekStart, timeZone and timeFormat during user create
This commit is contained in:
1 parent
2f5768b74f
commit
b8890c841c
10 files changed
+80
-64
No files matched your search
+5
@@ -139,6 +139,8 @@ describe("OAuth Client Users Endpoints", () => {
|
||||
const requestBody: CreateManagedUserInput = {
|
||||
email: userEmail,
|
||||
timeZone: userTimeZone,
|
||||
weekStart: "Monday",
|
||||
timeFormat: 24,
|
||||
};
|
||||
|
||||
const response = await request(app.getHttpServer())
|
||||
@@ -158,6 +160,9 @@ describe("OAuth Client Users Endpoints", () => {
|
||||
expect(responseBody.status).toEqual(SUCCESS_STATUS);
|
||||
expect(responseBody.data).toBeDefined();
|
||||
expect(responseBody.data.user.email).toEqual(getOAuthUserEmail(oAuthClient.id, requestBody.email));
|
||||
expect(responseBody.data.user.timeZone).toEqual(requestBody.timeZone);
|
||||
expect(responseBody.data.user.weekStart).toEqual(requestBody.weekStart);
|
||||
expect(responseBody.data.user.timeFormat).toEqual(requestBody.timeFormat);
|
||||
expect(responseBody.data.accessToken).toBeDefined();
|
||||
expect(responseBody.data.refreshToken).toBeDefined();
|
||||
|
||||
|
||||
@@ -53,6 +53,9 @@ export class OAuthClientUsersService {
|
||||
},
|
||||
},
|
||||
isPlatformManaged,
|
||||
timeFormat: body.timeFormat,
|
||||
weekStart: body.weekStart,
|
||||
timeZone: body.timeZone,
|
||||
})
|
||||
)[0];
|
||||
await this.userRepository.addToOAuthClient(user.id, oAuthClientId);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { IsTimeFormat } from "@/modules/users/inputs/validators/is-time-format";
|
||||
import { IsWeekStart } from "@/modules/users/inputs/validators/is-week-start";
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsNumber, IsOptional, IsTimeZone, IsString, Validate } from "class-validator";
|
||||
import { IsOptional, IsTimeZone, IsString } from "class-validator";
|
||||
|
||||
export type WeekDay = "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday";
|
||||
export type TimeFormat = 12 | 24;
|
||||
export class CreateManagedUserInput {
|
||||
@IsString()
|
||||
@ApiProperty({ example: "[email protected]" })
|
||||
@@ -12,17 +12,17 @@ export class CreateManagedUserInput {
|
||||
@IsOptional()
|
||||
name?: string;
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
@Validate(IsTimeFormat)
|
||||
@ApiProperty({ example: 12 })
|
||||
timeFormat?: number;
|
||||
@ApiProperty({ example: 12, enum: [12, 24], description: "Must be 12 or 24" })
|
||||
timeFormat?: TimeFormat;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Validate(IsWeekStart)
|
||||
@ApiProperty({ example: "Sunday" })
|
||||
weekStart?: string;
|
||||
@IsString()
|
||||
@ApiProperty({
|
||||
example: "Monday",
|
||||
enum: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
||||
})
|
||||
weekStart?: WeekDay;
|
||||
|
||||
@IsTimeZone()
|
||||
@IsOptional()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IsTimeFormat } from "@/modules/users/inputs/validators/is-time-format";
|
||||
import { IsWeekStart } from "@/modules/users/inputs/validators/is-week-start";
|
||||
import { IsNumber, IsOptional, IsString, IsTimeZone, Validate } from "class-validator";
|
||||
import { TimeFormat, WeekDay } from "@/modules/users/inputs/create-managed-user.input";
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsNumber, IsOptional, IsString, IsTimeZone } from "class-validator";
|
||||
|
||||
export class UpdateManagedUserInput {
|
||||
@IsString()
|
||||
@@ -11,19 +11,21 @@ export class UpdateManagedUserInput {
|
||||
@IsOptional()
|
||||
name?: string;
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
@Validate(IsTimeFormat)
|
||||
timeFormat?: number;
|
||||
@ApiProperty({ example: 12, enum: [12, 24], description: "Must be 12 or 24" })
|
||||
timeFormat?: TimeFormat;
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
defaultScheduleId?: number;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Validate(IsWeekStart)
|
||||
weekStart?: string;
|
||||
@IsString()
|
||||
@ApiProperty({
|
||||
example: "Monday",
|
||||
enum: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
||||
})
|
||||
weekStart?: WeekDay;
|
||||
|
||||
@IsTimeZone()
|
||||
@IsOptional()
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { ValidatorConstraint, ValidatorConstraintInterface } from "class-validator";
|
||||
|
||||
@ValidatorConstraint({ name: "isTimeFormat", async: false })
|
||||
export class IsTimeFormat implements ValidatorConstraintInterface {
|
||||
validate(timeFormat: number) {
|
||||
return timeFormat === 12 || timeFormat === 24;
|
||||
}
|
||||
|
||||
defaultMessage() {
|
||||
return "timeFormat must be a number either 12 or 24";
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { ValidatorConstraint, ValidatorConstraintInterface } from "class-validator";
|
||||
|
||||
@ValidatorConstraint({ name: "isWeekStart", async: false })
|
||||
export class IsWeekStart implements ValidatorConstraintInterface {
|
||||
validate(weekStart: string) {
|
||||
if (!weekStart) return false;
|
||||
|
||||
const lowerCaseWeekStart = weekStart.toLowerCase();
|
||||
return (
|
||||
lowerCaseWeekStart === "monday" ||
|
||||
lowerCaseWeekStart === "tuesday" ||
|
||||
lowerCaseWeekStart === "wednesday" ||
|
||||
lowerCaseWeekStart === "thursday" ||
|
||||
lowerCaseWeekStart === "friday" ||
|
||||
lowerCaseWeekStart === "saturday" ||
|
||||
lowerCaseWeekStart === "sunday"
|
||||
);
|
||||
}
|
||||
|
||||
defaultMessage() {
|
||||
return "weekStart must be a string either Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, or Sunday";
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ export class UsersRepository {
|
||||
|
||||
formatInput(userInput: CreateManagedUserInput | UpdateManagedUserInput) {
|
||||
if (userInput.weekStart) {
|
||||
userInput.weekStart = capitalize(userInput.weekStart);
|
||||
userInput.weekStart = userInput.weekStart;
|
||||
}
|
||||
|
||||
if (userInput.timeZone) {
|
||||
|
||||
Reference in new issue
Block a user