members.ts 1.3 KB

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