Skip to content

Commit

Permalink
feat(DTFS2-7052): moving uk postcode regex to constants and doc impro…
Browse files Browse the repository at this point in the history
…vements
  • Loading branch information
avaitonis committed Apr 25, 2024
1 parent f68ac66 commit 75b34ac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/constants/geospatial.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ export const GEOSPATIAL = {
EXAMPLES: {
POSTCODE: 'SW1A 2AQ',
},
REGEX: {
// UK postcode regex is from DTFS project and slightly optimised by lint.
UK_POSTCODE: /^[A-Za-z]{1,2}[\dRr][\dA-Za-z]?\s?\d[ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}$/,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { ApiProperty } from '@nestjs/swagger';
import { GEOSPATIAL } from '@ukef/constants';
import { Matches, MaxLength, MinLength } from 'class-validator';

const UK_POSTCODE = /^[A-Za-z]{1,2}[\dRr][\dA-Za-z]?\s?\d[ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}$/;

export class GetAddressesByPostcodeQueryDto {
@ApiProperty({
example: GEOSPATIAL.EXAMPLES.POSTCODE,
description: 'Postcode to search for',
minLength: 5,
maxLength: 8,
pattern: GEOSPATIAL.REGEX.UK_POSTCODE.source,
})
@MinLength(5)
@MaxLength(8)
@Matches(UK_POSTCODE)
@Matches(GEOSPATIAL.REGEX.UK_POSTCODE)
public postcode: string;
}
4 changes: 4 additions & 0 deletions test/docs/__snapshots__/get-docs-yaml.api-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ paths:
example: SW1A 2AQ
description: Postcode to search for
schema:
minLength: 5
maxLength: 8
pattern: >-
^[A-Za-z]{1,2}[\\dRr][\\dA-Za-z]?\\s?\\d[ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}$
type: string
responses:
'200':
Expand Down

0 comments on commit 75b34ac

Please sign in to comment.