Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.

Commit 10e865b

Browse files
committed
fix(infra): fix repository submission
1 parent c6a959d commit 10e865b

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

packages/server/src/config/cache/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function getConfiguration() {
6767
password: url.password,
6868
port: url.port,
6969
username: url.username,
70-
tls: url.protocol === "rediss:",
70+
tls: url.protocol === "rediss:" ? {rejectUnauthorized: false} : false,
7171
db: process.env.REDIS_DB_INDEX || 0,
7272
...redisOptions()
7373
};

packages/server/src/services/FormioRepository.spec.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ describe("FormioRepository", () => {
2020
})
2121
},
2222
submissionModel: class {
23-
static updateOne = jest.fn().mockResolvedValue({});
24-
public _id: string;
25-
constructor(o: any) {
26-
Object.assign(this, o);
27-
this._id = o._id || "newid";
28-
}
23+
static findOneAndUpdate = jest.fn().mockImplementation(({_id}, instance) => {
24+
return {
25+
_id: _id || "newid",
26+
...instance
27+
};
28+
});
2929
}
3030
};
3131

@@ -49,10 +49,10 @@ describe("FormioRepository", () => {
4949
},
5050
form: "id"
5151
});
52-
expect(database.submissionModel.updateOne).toHaveBeenCalledWith(
53-
{_id: "newid"},
54-
{$set: {_id: "newid", data: {label: "label"}, form: "id"}},
55-
{upsert: true}
52+
expect(database.submissionModel.findOneAndUpdate).toHaveBeenCalledWith(
53+
{_id: undefined},
54+
{data: {label: "label"}, form: "id"},
55+
{upsert: true, new: true}
5656
);
5757
});
5858
it("should save submission", async () => {
@@ -63,12 +63,12 @@ describe("FormioRepository", () => {
6363
})
6464
},
6565
submissionModel: class {
66-
static updateOne = jest.fn().mockResolvedValue({});
67-
public _id: string;
68-
constructor(o: any) {
69-
Object.assign(this, o);
70-
this._id = o._id || "newid";
71-
}
66+
static findOneAndUpdate = jest.fn().mockImplementation(({_id}, instance) => {
67+
return {
68+
_id: _id || "newid",
69+
...instance
70+
};
71+
});
7272
}
7373
};
7474

@@ -93,10 +93,10 @@ describe("FormioRepository", () => {
9393
},
9494
form: "id"
9595
});
96-
expect(database.submissionModel.updateOne).toHaveBeenCalledWith(
96+
expect(database.submissionModel.findOneAndUpdate).toHaveBeenCalledWith(
9797
{_id: "id"},
98-
{$set: {_id: "id", data: {label: "label"}, form: "id"}},
99-
{upsert: true}
98+
{_id: "id", data: {label: "label"}, form: "id"},
99+
{upsert: true, new: true}
100100
);
101101
});
102102
});

packages/server/src/services/FormioRepository.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,18 @@ export abstract class FormioRepository<SubmissionData = any> {
2424
}
2525

2626
async saveSubmission(submission: Omit<Partial<FormioSubmission<SubmissionData>>, "form"> & {form?: any}) {
27-
const instance = new this.formioDatabase.submissionModel({
28-
...submission,
27+
submission = {
28+
...omit(submission, ["__v"]),
2929
form: submission.form || (await this.getFormId())
30-
});
30+
};
3131

32-
await this.formioDatabase.submissionModel.updateOne(
32+
return this.formioDatabase.submissionModel.findOneAndUpdate(
3333
{
34-
_id: instance._id
34+
_id: submission._id
3535
},
36-
{$set: omit(instance, ["__v"])},
37-
{upsert: true}
36+
submission,
37+
{new: true, upsert: true}
3838
);
39-
40-
return instance;
4139
}
4240

4341
async getSubmissions(): Promise<MongooseDocument<FormioSubmission<SubmissionData>>[]> {

0 commit comments

Comments
 (0)