Skip to content

Commit e93dd65

Browse files
committed
fix: save createdBy and updatedBy
Signed-off-by: Rakib Ansary <rakibansary@gmail.com>
1 parent b0d540e commit e93dd65

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/common/CoreOperations.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ abstract class CoreOperations<
151151
}
152152

153153
protected async create(entity: I & T, metadata?: Metadata): Promise<T> {
154-
let handle = null;
155-
if (metadata?.get("handle") != null) {
156-
handle = metadata?.get("handle")?.toString();
157-
}
158-
159154
const queryRequest: QueryRequest = {
160155
kind: {
161156
$case: "query",
@@ -164,11 +159,7 @@ abstract class CoreOperations<
164159
$case: "insert",
165160
insert: {
166161
table: this.entityName,
167-
attributes: {
168-
...entity,
169-
createdBy: handle != null ? handle : undefined,
170-
updatedBy: handle != null ? handle : undefined,
171-
},
162+
attributes: entity,
172163
},
173164
},
174165
},

src/domain/Challenge.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,13 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {
153153

154154
public async create(
155155
input: CreateChallengeInput,
156-
metadata: Metadata | undefined
156+
metadata: Metadata
157157
): Promise<Challenge> {
158158
input.name = xss(input.name);
159159

160+
// prettier-ignore
161+
const handle = metadata?.get("handle").length > 0 ? metadata?.get("handle")?.[0].toString() : "tcwebservice";
162+
160163
if (Array.isArray(input.discussions)) {
161164
for (const discussion of input.discussions) {
162165
discussion.id = IdGenerator.generateUUID();
@@ -217,7 +220,7 @@ class ChallengeDomain extends CoreOperations<Challenge, CreateChallengeInput> {
217220
const challenge: Challenge = {
218221
id: IdGenerator.generateUUID(),
219222
created: now,
220-
createdBy: "tcwebservice", // TODO: extract from JWT
223+
createdBy: handle, // TODO: extract from JWT
221224
updated: now,
222225
updatedBy: "tcwebservice", // TODO: extract from JWT
223226
winners: [],

0 commit comments

Comments
 (0)