Skip to content

Commit

Permalink
fix: restore typings to some model static methods (#2067)
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui authored Jun 7, 2021
1 parent 6f03d5f commit f8f235a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/app/models/form_feedback.server.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mongoose, Schema } from 'mongoose'
import { Mongoose, QueryCursor, Schema } from 'mongoose'

import { IFormFeedbackModel, IFormFeedbackSchema } from '../../types'

Expand Down Expand Up @@ -39,7 +39,9 @@ const FormFeedbackSchema = new Schema<IFormFeedbackSchema, IFormFeedbackModel>(
* @param formId the form id to return the submissions cursor for
* @returns a cursor to the feedback retrieved
*/
FormFeedbackSchema.statics.getFeedbackCursorByFormId = function (formId) {
FormFeedbackSchema.statics.getFeedbackCursorByFormId = function (
formId: string,
): QueryCursor<IFormFeedbackSchema> {
return this.find({ formId }).batchSize(2000).read('secondary').lean().cursor()
}

Expand Down
12 changes: 8 additions & 4 deletions src/app/models/submission.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
IWebhookResponseSchema,
MyInfoAttribute,
SubmissionCursorData,
SubmissionData,
SubmissionMetadata,
SubmissionType,
WebhookData,
Expand Down Expand Up @@ -314,9 +315,12 @@ EncryptSubmissionSchema.statics.findAllMetadataByFormId = function (
}

EncryptSubmissionSchema.statics.getSubmissionCursorByFormId = function (
formId,
dateRange = {},
) {
formId: string,
dateRange: {
startDate?: string
endDate?: string
} = {},
): QueryCursor<SubmissionCursorData> {
const streamQuery = {
form: formId,
...createQueryWithDateParam(dateRange?.startDate, dateRange?.endDate),
Expand All @@ -341,7 +345,7 @@ EncryptSubmissionSchema.statics.getSubmissionCursorByFormId = function (
EncryptSubmissionSchema.statics.findEncryptedSubmissionById = function (
formId: string,
submissionId: string,
) {
): Promise<SubmissionData | null> {
return this.findOne({
_id: submissionId,
form: formId,
Expand Down
8 changes: 6 additions & 2 deletions src/types/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ export type SubmissionCursorData = Pick<
'encryptedContent' | 'verifiedContent' | 'created' | 'id'
> & { attachmentMetadata?: Record<string, string> } & Document

export type SubmissionData = Omit<
export type SubmissionData = Pick<
IEncryptedSubmissionSchema,
'version' | 'webhookResponses'
| 'encryptedContent'
| 'verifiedContent'
| 'attachmentMetadata'
| 'created'
| '_id'
>

export type IEmailSubmissionModel = Model<IEmailSubmissionSchema> &
Expand Down

0 comments on commit f8f235a

Please sign in to comment.