Zahra Mumtaz
08/23/2022, 12:09 PMNurul
08/23/2022, 12:12 PMZahra Mumtaz
08/23/2022, 12:15 PMNurul
08/23/2022, 12:20 PMZahra Mumtaz
08/23/2022, 3:11 PMimport { ObjectType, Field, Int, registerEnumType } from '@nestjs/graphql';
import { WeekStart } from '@prisma/client';
import { CompanySetting } from './company-setting.entity';
registerEnumType (WeekStart,{
name: 'WeekStart',
description: 'week start',
})
@ObjectType()
export class Company {
id: string;
name: string;
@Field({nullable: true})
avatar?: string;
@Field({nullable: true})
ownerId: string;
phone?: string;
users: string[];
@Field(() => WeekStart)
startOfWeek?: WeekStart;
@Field({nullable: true, defaultValue: "Asia/Karachi"})
defaultTimezone: string;
isArchived?: boolean;
@Field(() => CompanySetting)
settings?: CompanySetting
createdAt: Date;
updatedAt: Date;
}
Company Settings Entity
import { Field, ObjectType } from "@nestjs/graphql";
@ObjectType()
export class CompanySetting {
@Field({ nullable: true, defaultValue: 10 })
captureDuration?: number;
@Field(type => [String], { nullable: true })
alerts?: string[];
}
Create Company DTO
import { InputType, Int, Field } from '@nestjs/graphql';
import { Setting, WeekStart } from '@prisma/client';
import { IsNotEmpty, Matches, MinLength, Validate} from 'class-validator';
import { CompanySetting } from '../entities/company-setting.entity';
import { CompanyExistsValidator } from '../validators/company-exists.validator';
@InputType()
export class CreateCompanyInput {
@Field()
@IsNotEmpty()
@MinLength(3)
@Matches(/^[ A-Za-z0-9_ -]*$/)
@Validate(CompanyExistsValidator)
name: string;
@Field({ nullable: true})
avatar: string;
@Field({ nullable: true })
phone: string;
@Field(() => WeekStart, {defaultValue: WeekStart.MONDAY})
startOfWeek: WeekStart;
@Field({ nullable: true })
ownerId: string;
@Field({ nullable: true })
defaultTimezone: string;
@Field(type => [CompanySetting])
settings: Setting
@Field()
isArchived: boolean;
}
Nurul
08/24/2022, 7:16 AMZahra Mumtaz
08/24/2022, 8:09 AMNurul
08/24/2022, 8:15 AM