credential-issue-request.entity.ts 1.2 KB
Newer Older
Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  Generated,
  ManyToOne,
} from 'typeorm';
import { CredentialRequest } from './credential-request.interface';
import { Organization } from '../organizations/organization.entity';

interface CredentialData {
  [key: string]: string | number | boolean | null;
}

export interface CredentialIssueRequestData {
  iss: string;
  type: string;
  data: CredentialData;
  callbackUrl: string; // the REST api of the verifier where to deliver the credential data
}

@Entity()
export class CredentialIssueRequest implements CredentialRequest {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  callbackUrl: string;

  @Column()
  type: string;

  @Column()
  @Generated('uuid')
  uuid: string;

  @Column('simple-json')
  data: CredentialData;

  @ManyToOne(
    () => Organization,
    organization => organization.issueRequests,
  )
  requestor: Organization;

46 47
  static requestType: 'credential-issue-request';

Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
48
  get requestId() {
49 50 51 52 53
    return `${CredentialIssueRequest.requestType}:${this.uuid}`;
  }

  get iss() {
    return this.requestor?.uuid;
Hidde-Jan Jongsma's avatar
Hidde-Jan Jongsma committed
54 55 56 57 58 59 60 61 62 63
  }

  get issuer() {
    return this.requestor;
  }

  set issuer(issuer: Organization) {
    this.requestor = issuer;
  }
}