Skip to content

Commit

Permalink
Merge branch 'develop' into feat/virus-scanner-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
LinHuiqing committed Sep 13, 2023
2 parents 6e4be7e + 4237848 commit ebe2ef2
Show file tree
Hide file tree
Showing 37 changed files with 8,594 additions and 1,075 deletions.
4 changes: 2 additions & 2 deletions .ebextensions/efs-mount.config
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ files:

mountpoint -q ${EFS_MOUNT_DIR}
if [ $? -ne 0 ]; then
echo "mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 ${EFS_FILE_SYSTEM_ID}.efs.${EFS_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR}"
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 ${EFS_FILE_SYSTEM_ID}.efs.${EFS_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR}
echo "mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport ${EFS_FILE_SYSTEM_ID}.efs.${EFS_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR}"
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport ${EFS_FILE_SYSTEM_ID}.efs.${EFS_REGION}.amazonaws.com:/ ${EFS_MOUNT_DIR}
if [ $? -ne 0 ] ; then
echo 'ERROR: Mount command failed!'
exit 1
Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
},
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"markdown.extension.toc.omittedFromToc": {
"README.md": [
"## Table of Contents"
]
}
}
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,52 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v6.77.0](https://github.com/opengovsg/FormSG/compare/v6.76.0...v6.77.0)

- build: merge v6.76.1 into develop [`#6708`](https://github.com/opengovsg/FormSG/pull/6708)
- feat: soften and fix storage submission validation [`#6696`](https://github.com/opengovsg/FormSG/pull/6696)
- build: release v6.76.1 [`#6702`](https://github.com/opengovsg/FormSG/pull/6702)
- fix: invalid mixed digit input [`#6701`](https://github.com/opengovsg/FormSG/pull/6701)
- build: merge v6.76.0 into develop [`#6700`](https://github.com/opengovsg/FormSG/pull/6700)
- build: release v6.76.0 [`#6698`](https://github.com/opengovsg/FormSG/pull/6698)
- chore: bump version to 6.76.1 [`9e88567`](https://github.com/opengovsg/FormSG/commit/9e8856721af4e3a99b6c6fe0e31ac96414a46149)

#### [v6.76.0](https://github.com/opengovsg/FormSG/compare/v6.75.1...v6.76.0)

> 7 September 2023

- fix: remove index from myinfo child question name [`#6697`](https://github.com/opengovsg/FormSG/pull/6697)
- feat: update config for efs uninterrupted availability [`#6691`](https://github.com/opengovsg/FormSG/pull/6691)
- docs(undp): add steps to migrate from mongodb in README [`#6695`](https://github.com/opengovsg/FormSG/pull/6695)
- fix: update Myinfo occupation list [`#6684`](https://github.com/opengovsg/FormSG/pull/6684)
- build: merge v6.75.1 into develop [`#6690`](https://github.com/opengovsg/FormSG/pull/6690)
- * feat: % rollout of new storage submission endpoint (#6665) [`#6688`](https://github.com/opengovsg/FormSG/pull/6688)
- chore: bump version to v6.76.0 [`389d2aa`](https://github.com/opengovsg/FormSG/commit/389d2aa0814798b4b44ff17a373e6c59ca4292dc)

#### [v6.75.1](https://github.com/opengovsg/FormSG/compare/v6.75.0...v6.75.1)

> 4 September 2023

- fix: payments params in new storage submission endpoint [`#6689`](https://github.com/opengovsg/FormSG/pull/6689)
- chore: bump version to 6.75.1 [`af06ba3`](https://github.com/opengovsg/FormSG/commit/af06ba371fee38a26f1b27125e382521a0748dbe)

#### [v6.75.0](https://github.com/opengovsg/FormSG/compare/v6.74.1...v6.75.0)

> 4 September 2023

- fix: Find latest successful payment query to sort by completed payment date and constraint query to last 30 days [`#6615`](https://github.com/opengovsg/FormSG/pull/6615)
- feat: payment security account email check [`#6604`](https://github.com/opengovsg/FormSG/pull/6604)
- feat: % rollout of new storage submission endpoint [`#6665`](https://github.com/opengovsg/FormSG/pull/6665)
- build: merge v6.74.1 into develop [`#6683`](https://github.com/opengovsg/FormSG/pull/6683)
- build: release v6.74.1 [`#6682`](https://github.com/opengovsg/FormSG/pull/6682)
- chore: bump version to v6.75.0 [`6ba6155`](https://github.com/opengovsg/FormSG/commit/6ba61554e3f9c83b27eb1aea8df5ddd241afe852)

#### [v6.74.1](https://github.com/opengovsg/FormSG/compare/v6.74.0...v6.74.1)

> 31 August 2023

- fix: payment quantity modal input inconsistencies [`#6681`](https://github.com/opengovsg/FormSG/pull/6681)
- chore: bump version to 6.74.1 [`1c96e9e`](https://github.com/opengovsg/FormSG/commit/1c96e9ea74c772e8cd45bc6877dfc8b1e41e4832)

#### [v6.74.0](https://github.com/opengovsg/FormSG/compare/v6.73.0...v6.74.0)

Expand Down
92 changes: 71 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@
[![Coverage Status](https://coveralls.io/repos/github/opengovsg/FormSG/badge.svg?branch=develop)](https://coveralls.io/github/opengovsg/FormSG?branch=develop)

## Table of Contents

- [FormSG](#formsg)
- [Table of Contents](#table-of-contents)
- [Contributing](#contributing)
- [Features](#features)
- [Local Development (Docker)](#local-development-docker)
- [Prerequisites](#prerequisites)
- [First Setup](#first-setup)
- [Running Locally](#running-locally)
- [Accessing email locally](#accessing-email-locally)
- [Environment variables](#environment-variables)
- [Trouble-shooting](#trouble-shooting)
- [Testing](#testing)
- [Testing Prerequisites](#testing-prerequisites)
- [Running tests](#running-tests)
- [Unit tests](#unit-tests)
- [End-to-end tests](#end-to-end-tests)
- [Architecture](#architecture)
- [MongoDB Scripts](#mongodb-scripts)
- [Support](#support)
- [Acknowledgements](#acknowledgements)
- [Contributing](#contributing)
- [IMPORTANT NOTE TO ALL CONTRIBUTORS](#important-note-to-all-contributors)
- [Features](#features)
- [Local Development (Docker)](#local-development-docker)
- [Prerequisites](#prerequisites)
- [First Setup](#first-setup)
- [Running Locally](#running-locally)
- [Adding dependencies](#adding-dependencies)
- [Accessing email locally](#accessing-email-locally)
- [Environment variables](#environment-variables)
- [Trouble-shooting](#trouble-shooting)
- [Testing](#testing)
- [Testing Prerequisites](#testing-prerequisites)
- [Running tests](#running-tests)
- [Unit tests](#unit-tests)
- [End-to-end tests](#end-to-end-tests)
- [Cross-browser testing](#cross-browser-testing)
- [Architecture](#architecture)
- [MongoDB Scripts](#mongodb-scripts)
- [Support](#support)
- [Database Alternatives](#database-alternatives)
- [Migrating from Mongoose ODM to Prisma ORM](#migrating-from-mongoose-odm-to-prisma-orm)
- [Replacing MongoDB with CockroachDB](#replacing-mongodb-with-cockroachdb)
- [Other Prisma supported DBs](#other-prisma-supported-dbs)
- [Other potential DB migrations](#other-potential-db-migrations)
- [Acknowledgements](#acknowledgements)

## Contributing

Expand Down Expand Up @@ -217,6 +222,51 @@ Scripts for common tasks in MongoDB can be found [here](docs/MONGODB.md).

Please contact FormSG ([email protected]) for any details.

## Database Alternatives

### Migrating from Mongoose ODM to Prisma ORM

FormSG uses Mongoose as the Object-Document Mapping (ODM) to MongoDB. This means that our code is strongly coupled with MongoDB as Mongoose solely supports it.

In order to use a different database with FormSG you will have to first migrate from Mongoose to other object modelling libraries. One of which is Prisma.

Prisma is an Object-Relational Mapping (ORM) library that can also be used as the object model for MongoDB. Prisma is compatible with various other relational databases like Cockroach DB.

Follow this [guide](https://www.prisma.io/docs/guides/migrate-to-prisma/migrate-from-mongoose#overview-of-the-migration-process) by Prisma to migrate from Mongoose.

The guide has 4 primary steps:
1. Install Prisma CLI
2. Introspect the current MongoDB for the data model
1. For this section, Prisma’s introspection should be able to create prisma models that will replace your `server.model.ts` for each collection
2. Additionally, as Prisma is relational, you could add relations between the various documents. One good relation to add will be `form` many to one `user` on the `[form.email](http://form.email)` field.
3. Install Prisma Client
4. Replace Mongoose Queries with Prisma Client
1. This step will likely take the most refactoring efforts
2. This will include most files in `formsg/src` ending with `service.ts`
3. Including test files ending with `service.spec.ts`

#### Replacing MongoDB with CockroachDB

Thereafter, you could set up CockroachDB which is a distributed SQL DB. Follow the quick start guide by [CockroachDB](https://www.cockroachlabs.com/docs/cockroachcloud/quickstart) to create a CockroachDB Serverless cluster.

To replace the local development instance, you can follow this [guide](https://www.cockroachlabs.com/docs/stable/start-a-local-cluster-in-docker-mac). As FormSG uses Docker for local development, you will have to replace the `mongoDB` container from `docker-compose.yml` to the `cockroachDB` version.

Then connect to [CockroachDB](https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/connect-your-database-typescript-postgresql) by changing the DB url in `.env` to the one from your CockroachDB `DATABASE_URL="YOUR_COCKROACH_DB_URL"`.

For local development, if the DB is replaced as above, you should not need to modify the ports as it will still be hosted on `localhost:27017`.

#### Other Prisma supported DBs

MongoDB can be replaced with other various relational databases supported by Prisma in this [list](https://www.prisma.io/docs/reference/database-reference/supported-databases).

### Other potential DB migrations

It is also possible to migrate from Mongoose to [Ottoman](https://ottomanjs.com/), which is another ODM.

The process will be simpler than migrating to Prisma, but Ottoman is more restrictive and can only be used together with Couchbase, which is also a noSQL DB like MongoDB.

Refer to this [guide](https://www.couchbase.com/blog/migrate-mongodb-mongoose-couchbase-ottoman/) to migrate from Mongoose to Ottoman and then replace MongoDB with Couchbase.

## Acknowledgements

FormSG acknowledges the work done by [Arielle Baldwynn](https://github.com/whitef0x0) to build and maintain [TellForm](https://github.com/tellform), on which FormSG is based.
Expand Down
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-frontend",
"version": "6.74.0",
"version": "6.77.0",
"homepage": ".",
"private": true,
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const MIN_QTY_KEY = `min_qty`
const MAX_QTY_KEY = `max_qty`
const DISPLAY_AMOUNT_KEY = 'display_amount'
const MULTI_QTY_KEY = 'multi_qty'

const parseIntElseNull = (val: string) => {
const parsedInt = parseInt(val, 10)
return Number.isNaN(parsedInt) ? null : parsedInt
}

export const ProductModal = ({
onClose,
onSaveProduct,
Expand Down Expand Up @@ -125,28 +131,37 @@ export const ProductModal = ({
onClose()
})

const minQtyValidation: RegisterOptions<ProductInput, typeof MIN_QTY_KEY> = {
validate: (val) => {
const minQtyValidation: RegisterOptions = {
validate: (valStr: string) => {
if (!getValues(MULTI_QTY_KEY)) return true
if (val <= 0) {

const valNumber = parseIntElseNull(valStr)
if (!valNumber || valNumber <= 0) {
return 'Enter a value greater than 0'
}
if (val > getValues(MAX_QTY_KEY)) {

const maxNumber =
parseIntElseNull(getValues(MAX_QTY_KEY) as unknown as string) ||
Number.MAX_SAFE_INTEGER

if (valNumber > maxNumber) {
return 'Enter a value smaller than the maximum quantity'
}
return true
},
}
const maxQtyValidation: RegisterOptions<ProductInput, typeof MAX_QTY_KEY> = {
validate: (val) => {
const maxQtyValidation: RegisterOptions = {
validate: (valStr: string) => {
if (!getValues(MULTI_QTY_KEY)) return true
if (val <= 0) {

const valNumber = parseIntElseNull(valStr)
if (!valNumber || valNumber <= 0) {
return 'Enter a value greater than 0'
}

const amount = dollarsToCents(getValues(DISPLAY_AMOUNT_KEY) ?? '')

if (val * amount > maxPaymentAmountCents) {
if (valNumber * amount > maxPaymentAmountCents) {
const maxQty = Math.floor(maxPaymentAmountCents / amount)
if (maxQty <= 0) {
return `Quantity limit could not be set because amount is above S${formatCurrency(
Expand All @@ -155,7 +170,11 @@ export const ProductModal = ({
}
return `The maximum quantity for this amount is ${maxQty}`
}
if (val < getValues(MIN_QTY_KEY)) {
const minNumber =
parseIntElseNull(getValues(MIN_QTY_KEY) as unknown as string) ||
Number.MIN_SAFE_INTEGER

if (valNumber < minNumber) {
return 'Enter a value greater than the minimum quantity'
}
return true
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "FormSG",
"description": "Form Manager for Government",
"version": "6.74.1",
"version": "6.77.0",
"homepage": "https://form.gov.sg",
"authors": [
"FormSG <[email protected]>"
Expand Down
2 changes: 2 additions & 0 deletions shared/constants/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export const featureFlags = {
turnstile: 'turnstile' as const,
validateStripeEmailDomain: 'validateStripeEmailDomain' as const,
encryptionBoundaryShift: 'encryption-boundary-shift' as const,
encryptionBoundaryShiftHardValidation:
'encryption-boundary-shift-hard-validation' as const,
}
Loading

0 comments on commit ebe2ef2

Please sign in to comment.