Adding support with class validator
sagi-arbroknot opened this issue · 1 comments
sagi-arbroknot commented
Just want to help you guys :)
Keep up the good work.
From yours truly Sagi Carmel from Arbor Knot.
import { IsArray, IsBoolean, IsNumber, IsString, ValidateNested } from "class-validator";
class App {
@IsString()
name?: string;
@IsString()
version?: string;
@IsString()
build?: string;
@IsString()
namespace?: string;
}
class Integrations {
@IsBoolean()
All?: boolean;
@IsBoolean()
Mixpanel?: boolean;
@IsBoolean()
Salesforce?: boolean;
}
class Campaign {
@IsString()
name?: string;
@IsString()
source?: string;
@IsString()
medium?: string;
@IsString()
term?: string;
@IsString()
content?: string;
}
class Device {
@IsString()
id?: string;
@IsString()
advertisingId?: string;
@IsBoolean()
adTrackingEnabled?: boolean;
@IsString()
manufacturer?: string;
@IsString()
model?: string;
@IsString()
name?: string;
@IsString()
type?: string;
@IsString()
token?: string;
}
class Library {
@IsString()
name?: string;
@IsString()
version?: string;
}
class Location {
@IsString()
city?: string;
@IsString()
country?: string;
@IsNumber()
latitude?: number;
@IsNumber()
longitude?: number;
@IsNumber()
speed?: number;
}
class Network {
@IsBoolean()
bluetooth?: boolean;
@IsString()
carrier?: string;
@IsBoolean()
cellular?: boolean;
@IsBoolean()
wifi?: boolean;
}
class OS {
@IsString()
name?: string;
@IsString()
version?: string;
}
class Page {
@IsString()
path?: string;
@IsString()
referrer?: string;
@IsString()
search?: string;
@IsString()
title?: string;
@IsString()
url?: string;
}
class Referrer {
@IsString()
id?: string;
@IsString()
type?: string;
}
class Screen {
@IsNumber()
width?: number;
@IsNumber()
height?: number;
@IsNumber()
density?: number;
}
class Context {
@IsBoolean()
active?: boolean;
@ValidateNested()
app?: App;
@ValidateNested()
campaign?: Campaign;
@ValidateNested()
device?: Device;
@IsString()
ip?: string;
@ValidateNested()
library?: Library;
@IsString()
locale?: string;
@ValidateNested()
location?: Location;
@ValidateNested()
network?: Network;
@ValidateNested()
os?: OS;
@ValidateNested()
page?: Page;
@ValidateNested()
referrer?: Referrer;
@ValidateNested()
screen?: Screen;
@IsString()
groupId?: string;
@IsString()
timezone?: string;
@IsString()
userAgent?: string;
}
class CommonFields {
@IsString()
anonymousId?: string;
@IsString()
userId?: string;
@ValidateNested()
context?: Context;
@ValidateNested()
integrations?: Integrations;
@IsString()
messageId?: string;
@IsString()
receivedAt?: string;
@IsString()
sentAt?: string;
@IsString()
timestamp?: string;
@IsString()
type?: string;
@IsString()
version?: number;
}
class IdentificationForm extends CommonFields {
@IsArray()
traits?: Record<string, any>[];
}
class TrackingForm extends CommonFields {
@IsString()
event: string;
@IsArray()
properties: Record<string, any>[];
}
pbassut commented
Interesting. That does data validation, then? Never used class-validator myself