class-validator#IsUUID TypeScript Examples

The following examples show how to use class-validator#IsUUID. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: vulnerabilities.ts    From crossfeed with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
get = wrapHandler(async (event) => {
  await connectToDatabase();
  const id = event.pathParameters?.vulnerabilityId;
  if (!isUUID(id)) {
    return NotFound;
  }

  // Need to use QueryBuilder because typeorm doesn't support nested
  // relations filtering -- see https://github.com/typeorm/typeorm/issues/3890
  const search = new VulnerabilitySearch();
  search.filters = new VulnerabilityFilters();
  search.filters.id = id;
  const [result] = await search.getResults(event);

  return {
    statusCode: result.length ? 200 : 404,
    body: result.length ? JSON.stringify(result[0]) : ''
  };
})
Example #2
Source File: EditPostAdapter.ts    From typescript-clean-architecture with MIT License 5 votes vote down vote up
@Expose()
  @IsUUID()
  public executorId: string;
Example #3
Source File: domains.ts    From crossfeed with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@IsUUID()
  @IsOptional()
  organization?: string;
Example #4
Source File: EditPostAdapter.ts    From typescript-clean-architecture with MIT License 5 votes vote down vote up
@Expose()
  @IsUUID()
  public postId: string;
Example #5
Source File: relate-backup.model.ts    From relate with GNU General Public License v3.0 5 votes vote down vote up
@IsUUID()
    public entityId!: string;
Example #6
Source File: EditPostAdapter.ts    From typescript-clean-architecture with MIT License 5 votes vote down vote up
@Expose()
  @IsOptional()
  @IsUUID()
  public imageId?: string;
Example #7
Source File: User.ts    From bulwark with MIT License 5 votes vote down vote up
@Column({
    nullable: true,
  })
  @IsOptional()
  @IsUUID()
  uuid: string;
Example #8
Source File: organizations.ts    From crossfeed with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
update = wrapHandler(async (event) => {
  const id = event.pathParameters?.organizationId;

  if (!id || !isUUID(id)) {
    return NotFound;
  }

  if (!isOrgAdmin(event, id)) return Unauthorized;
  const body = await validateBody<
    NewOrganization | NewOrganizationNonGlobalAdmins
  >(
    isGlobalWriteAdmin(event)
      ? NewOrganization
      : NewOrganizationNonGlobalAdmins,
    event.body
  );

  await connectToDatabase();
  const org = await Organization.findOne(
    {
      id
    },
    {
      relations: ['userRoles', 'granularScans']
    }
  );
  if (org) {
    if ('tags' in body) {
      body.tags = await findOrCreateTags(body.tags);
    }

    Organization.merge(org, { ...body, parent: undefined });
    await Organization.save(org);
    return {
      statusCode: 200,
      body: JSON.stringify(org)
    };
  }
  return NotFound;
})
Example #9
Source File: domain-validator.ts    From ddd-cqrs-es-aws-sam with MIT License 5 votes vote down vote up
@IsUUID()
  id!: Uuid;
Example #10
Source File: vulnerabilities.ts    From crossfeed with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@IsUUID()
  @IsOptional()
  tag?: string;
Example #11
Source File: gremlin_export_impl.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsUUID()
    relationship_pair_id?: string;
Example #12
Source File: manifest.model.ts    From relate with GNU General Public License v3.0 5 votes vote down vote up
@IsUUID()
    public id!: string;
Example #13
Source File: gremlin_export_impl.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsUUID()
    container_id?: string;
Example #14
Source File: relate-backup.model.ts    From relate with GNU General Public License v3.0 5 votes vote down vote up
@IsUUID()
    public id!: string;
Example #15
Source File: gremlin_export_impl.ts    From Deep-Lynx with MIT License 5 votes vote down vote up
@IsOptional()
    @IsUUID()
    id?: string;
Example #16
Source File: user.validator.ts    From ddd-cqrs-es-aws-sam with MIT License 5 votes vote down vote up
@IsUUID(undefined, { each: true })
  roles!: Set<Uuid>;
Example #17
Source File: RevisionRecordController.ts    From IBM-HyperProtectMBaaS with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static listAll = async (req: Request, res: Response) => {
    console.log(util.inspect(req.query.knowledgeVector, false, null, true /* enable colors */));

    if (isEmpty(req.query.knowledgeVector)) {
      res
        .status(400)
        .send(
          'Must send an array of knowledge vectors as query param. An empty knowledge vector would be { processes: [{ id : "validUUIDv4" , clock : 0 } ]}'
        );
      return;
    }

    // Thorough JSON validation using JSON Schema, TypedJSON and class-validator
    const ajv = new Ajv();
    const valid = ajv.validate(kvSchema, req.query.knowledgeVector);
    if (!valid) {
      console.log(ajv.errors);
      res.status(400).send(ajv.errors);
      return;
    }

    let incomingKV: KnowledgeVector;
    try {
      incomingKV = new TypedJSON(KnowledgeVector).parse(req.query.knowledgeVector);
    } catch (error) {
      res.status(400).send("JSON schema error");
      return;
    }

    console.log(util.inspect(incomingKV, false, null, true /* enable colors */));

    const errors = await validate(incomingKV);
    if (errors.length > 0) {
      res.status(400).send(errors);
      return;
    }

    //console.log(util.inspect(incomingKV, false, null, true /* enable colors */));

    let returnRevRecord = new OCKRevisionRecord();
    returnRevRecord.entities = [];

    // Case 1 : iOS device is syncing for the first time, it has no knowledge of the servers clock
    if (isEmpty(incomingKV.processes.find((process) => process.id === uuid))) {
      // store incoming clock locally
      let clockRepo = getMongoRepository(Process);

      for (const process of incomingKV.processes) {
        assert(isUUID(process.id));
        const processExists = await clockRepo.findOne({ id: process.id });
        if (isEmpty(processExists)) {
          assert(isNotEmpty(process.id));
          await clockRepo.save(process);
        }
      }

      // send all outcomes and tasks
      const taskRepository = getMongoRepository(OCKTask);
      const tasks = await taskRepository.find({});

      const outcomeRepository = getMongoRepository(OCKOutcome);
      const outcomes = await outcomeRepository.find({});

      tasks.map((entity) => {
        delete entity.kv;
        returnRevRecord.entities.push({ type: "task", object: entity });
      });
      outcomes.map((entity) => {
        delete entity.kv;
        returnRevRecord.entities.push({ type: "outcome", object: entity });
      });

      // set kv for revisionRecord
      returnRevRecord.knowledgeVector = await getLatestKnowledgeVector();

      //console.log(util.inspect(returnRevRecord, false, null, true /* enable colors */));
      res.status(201).send(returnRevRecord);
      return;
    }

    // Case 2 : It has synced before but its clock might be older than local, send entities newer than clock
    const clock = incomingKV.processes.find((process) => process.id === uuid).clock;
    assert(!isEmpty(clock), "clock cannot be undefined at this point");

    const taskRepository = getMongoRepository(OCKTask);
    const tasks = await taskRepository.find({
      $and: [{ "kv.processes.clock": { $gt: clock } }, { "kv.processes.id": { $eq: uuid } }],
    });

    const outcomeRepository = getMongoRepository(OCKOutcome);
    const outcomes = await outcomeRepository.find({
      $and: [{ "kv.processes.clock": { $gt: clock } }, { "kv.processes.id": { $eq: uuid } }],
    });

    tasks.map((entity) => {
      delete entity.kv;
      returnRevRecord.entities.push({ type: "task", object: entity });
    });
    outcomes.map((entity) => {
      delete entity.kv;
      returnRevRecord.entities.push({ type: "outcome", object: entity });
    });

    // set kv for revisionRecord
    returnRevRecord.knowledgeVector = await getLatestKnowledgeVector();

    //console.log(util.inspect(returnRevRecord, false, null, true /* enable colors */));
    res.status(201).send(returnRevRecord);
  };