How to use the warthog.Model function in warthog

To help you get started, we’ve selected a few warthog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github goldcaddy77 / warthog-starter / src / project / project.model.ts View on Github external
import { BaseModel, Model, OneToMany, StringField } from 'warthog';

import { Environment } from '../environment/environment.model';
import { FeatureFlagSegment } from '../feature-flag-segment/feature-flag-segment.model';
import { FeatureFlagUser } from '../feature-flag-user/feature-flag-user.model';
import { FeatureFlag } from '../feature-flag/feature-flag.model';
import { Segment } from '../segment/segment.model';
import { UserSegment } from '../user-segment/user-segment.model';

import { Matches } from 'class-validator';

@Model()
export class Project extends BaseModel {
  @StringField({ maxLength: 50, minLength: 3, nullable: false })
  name!: string;

  @Matches(/^[a-z0-9]+(-[a-z0-9]+)*$/) // Lowercase sluggified string
  @StringField({ maxLength: 20, minLength: 3, nullable: false, unique: true })
  key!: string;

  @OneToMany(() => Environment, (environment: Environment) => environment.project)
  environments?: Environment[];

  @OneToMany(() => Segment, (segment: Segment) => segment.project)
  segments?: Segment[];

  @OneToMany(() => FeatureFlag, (featureFlag: FeatureFlag) => featureFlag.project)
  featureFlags?: FeatureFlag[];
github goldcaddy77 / warthog-starter / src / user.model.ts View on Github external
import { BaseModel, EmailField, EnumField, Model, OneToMany, StringField } from 'warthog';

import { Post } from './post.model';

// Note: this must be exported and in the same file where it's attached with @EnumField
// Also - must use string enums
export enum UserStatus {
  ACTIVE = 'ACTIVE',
  INACTIVE = 'INACTIVE'
}

@Model()
export class User extends BaseModel {
  @StringField({ maxLength: 30 })
  firstName?: string;

  @StringField({ maxLength: 50, minLength: 2, nullable: true })
  lastName?: string;

  @EnumField('UserStatus', UserStatus)
  status?: UserStatus;

  @EmailField() email?: string;

  @OneToMany(() => Post, (post: Post) => post.user)
  posts?: Post[];
}
github goldcaddy77 / warthog-starter / src / modules / post / post.model.ts View on Github external
import { BaseModel, ManyToOne, Model, StringField } from 'warthog';

import { User } from '../user/user.model';

@Model()
export class Post extends BaseModel {
  @StringField({ maxLength: 256 })
  title?: string;

  @ManyToOne(() => User, (user: User) => user.posts, { nullable: false })
  user?: User;
}

warthog

Opinionated set of tools for setting up GraphQL backed by TypeORM

MIT
Latest version published 3 years ago

Package Health Score

42 / 100
Full package analysis