(createObject: CreateObject<T>)
| 130 | } |
| 131 | |
| 132 | async create(createObject: CreateObject<T>): Promise<T> { |
| 133 | const callId = uuid(); |
| 134 | |
| 135 | this.log.info({ callId, createObject }, '.create(createObject) called'); |
| 136 | |
| 137 | let object; |
| 138 | |
| 139 | try { |
| 140 | const document = await this.Model.create(createObject); |
| 141 | |
| 142 | object = this.parse(document.toObject() as RawObject<T>); |
| 143 | } catch (error) { |
| 144 | this.log.error( |
| 145 | { callId, createObject, error }, |
| 146 | '.create(createObject) thrown error!' |
| 147 | ); |
| 148 | throw error; |
| 149 | } |
| 150 | |
| 151 | this.existence.next({ |
| 152 | id: object.id, |
| 153 | value: object, |
| 154 | lastValue: null, |
| 155 | type: ExistenceEventType.Created, |
| 156 | }); |
| 157 | |
| 158 | this.log.info( |
| 159 | { callId, createObject, object }, |
| 160 | '.create(createObject) created object' |
| 161 | ); |
| 162 | |
| 163 | return object; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Removes all records from the DB |
no test coverage detected