Skip to content

Commit 75b34ac

Browse files
feat(DTFS2-7052): moving uk postcode regex to constants and doc improvements
1 parent f68ac66 commit 75b34ac

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/constants/geospatial.constant.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ export const GEOSPATIAL = {
66
EXAMPLES: {
77
POSTCODE: 'SW1A 2AQ',
88
},
9+
REGEX: {
10+
// UK postcode regex is from DTFS project and slightly optimised by lint.
11+
UK_POSTCODE: /^[A-Za-z]{1,2}[\dRr][\dA-Za-z]?\s?\d[ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}$/,
12+
},
913
};

src/modules/geospatial/dto/get-addresses-by-postcode-query.dto.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { ApiProperty } from '@nestjs/swagger';
22
import { GEOSPATIAL } from '@ukef/constants';
33
import { Matches, MaxLength, MinLength } from 'class-validator';
44

5-
const UK_POSTCODE = /^[A-Za-z]{1,2}[\dRr][\dA-Za-z]?\s?\d[ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}$/;
6-
75
export class GetAddressesByPostcodeQueryDto {
86
@ApiProperty({
97
example: GEOSPATIAL.EXAMPLES.POSTCODE,
108
description: 'Postcode to search for',
9+
minLength: 5,
10+
maxLength: 8,
11+
pattern: GEOSPATIAL.REGEX.UK_POSTCODE.source,
1112
})
1213
@MinLength(5)
1314
@MaxLength(8)
14-
@Matches(UK_POSTCODE)
15+
@Matches(GEOSPATIAL.REGEX.UK_POSTCODE)
1516
public postcode: string;
1617
}

test/docs/__snapshots__/get-docs-yaml.api-test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ paths:
500500
example: SW1A 2AQ
501501
description: Postcode to search for
502502
schema:
503+
minLength: 5
504+
maxLength: 8
505+
pattern: >-
506+
^[A-Za-z]{1,2}[\\dRr][\\dA-Za-z]?\\s?\\d[ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2}$
503507
type: string
504508
responses:
505509
'200':

0 commit comments

Comments
 (0)