members.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // import { Connection } from 'typeorm'
  2. import { DatabaseManager } from '@dzlzv/hydra-db-utils'
  3. import { logger } from '../src/common'
  4. import { MembershipEntryMethod, Membership } from 'query-node'
  5. export interface IBootstrapMember {
  6. member_id: number
  7. root_account: string
  8. controller_account: string
  9. handle: string
  10. avatar_uri: string
  11. about: string
  12. registered_at_time: number
  13. }
  14. // export async function bootMembers(members: IBootstrapMember[], db: Connection): Promise<void> {
  15. export async function bootMembers(db: DatabaseManager, members: IBootstrapMember[]): Promise<void> {
  16. for (const rawMember of members) {
  17. // create new membership
  18. const member = new Membership({
  19. // main data
  20. id: rawMember.member_id.toString(),
  21. rootAccount: rawMember.root_account,
  22. controllerAccount: rawMember.controller_account,
  23. handle: rawMember.handle,
  24. about: rawMember.about,
  25. avatarUri: rawMember.avatar_uri,
  26. createdInBlock: 0,
  27. entry: MembershipEntryMethod.GENESIS,
  28. // fill in auto-generated fields
  29. createdAt: new Date(rawMember.registered_at_time),
  30. updatedAt: new Date(rawMember.registered_at_time),
  31. })
  32. // save membership
  33. await db.save<Membership>(member)
  34. // emit log event
  35. logger.info('Member has been bootstrapped', { id: rawMember.member_id })
  36. }
  37. }