Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUB-2588 Add List Type For Court Subscription #1348

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3adbb37
Add List Type Court Subscription
junaidiqbalmoj Sep 20, 2024
34fb44e
Add List Type Court Subscription
junaidiqbalmoj Sep 20, 2024
210b670
Merge branch 'master' into PUB-2588-Add-List-Subscription
junaidiqbalmoj Sep 20, 2024
c436add
Merge master into PUB-2588-Add-List-Subscription
github-actions[bot] Sep 20, 2024
a10be37
Add missing welsh
junaidiqbalmoj Sep 20, 2024
71ded04
fix broken functionality
junaidiqbalmoj Sep 23, 2024
757b086
fix styling
junaidiqbalmoj Sep 23, 2024
557f851
fix typo
junaidiqbalmoj Sep 23, 2024
2e7e908
fix tests and bug
junaidiqbalmoj Sep 24, 2024
3f1c621
fix tests and bug
junaidiqbalmoj Sep 24, 2024
ceccc5c
fix typo
junaidiqbalmoj Sep 24, 2024
f0b81a6
Merge master into PUB-2588-Add-List-Subscription
github-actions[bot] Sep 24, 2024
67013e7
Merge master into PUB-2588-Add-List-Subscription
github-actions[bot] Sep 27, 2024
3e1fedf
Merge master into PUB-2588-Add-List-Subscription
github-actions[bot] Sep 30, 2024
e845da0
fix back button
junaidiqbalmoj Oct 1, 2024
6f6eaec
style fix
junaidiqbalmoj Oct 1, 2024
1115ed7
Fix code review comment about add list type sub
junaidiqbalmoj Oct 1, 2024
4bfb81d
style fix
junaidiqbalmoj Oct 1, 2024
621ffb6
remove comments
junaidiqbalmoj Oct 1, 2024
a31b391
fix bug
junaidiqbalmoj Oct 1, 2024
9d25e2f
fix code review comments
junaidiqbalmoj Oct 3, 2024
ca9fe3a
Merge master into PUB-2588-Add-List-Subscription
github-actions[bot] Oct 8, 2024
d8816e7
Merge master into PUB-2588-Add-List-Subscription
github-actions[bot] Oct 10, 2024
1377e35
Merge master into PUB-2588-Add-List-Subscription
github-actions[bot] Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/main/controllers/SubscriptionAddListController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Response } from 'express';
import { cloneDeep } from 'lodash';
import { PipRequest } from '../models/request/PipRequest';
import { SubscriptionService } from '../service/SubscriptionService';

const subscriptionService = new SubscriptionService();

export default class SubscriptionAddListController {
public async get(req: PipRequest, res: Response): Promise<void> {
const listTypes = await subscriptionService.generateListTypeForCourts(
req.user['userProvenance'],
req.lng,
req.user['userId']
);

if (req.query.error === 'true') {
res.render('subscription-add-list', {
...cloneDeep(req.i18n.getDataByLanguage(req.lng)['subscription-add-list']),
listTypes: listTypes,
noSelectionError: true,
});
} else {
res.render('subscription-add-list', {
...cloneDeep(req.i18n.getDataByLanguage(req.lng)['subscription-add-list']),
listTypes: listTypes,
noSelectionError: false,
});
}
}

public async post(req: PipRequest, res: Response): Promise<void> {
const result = await subscriptionService.createListTypeSubscriptionPayload(req.body['list-selections[]']);

if (Object.values(result).length == 0) {
const listTypes = await subscriptionService.generateListTypeForCourts(
req.user['userProvenance'],
req.lng,
req.user['userId']
);

res.render('subscription-add-list', {
...cloneDeep(req.i18n.getDataByLanguage(req.lng)['subscription-add-list']),
listTypes: listTypes,
noSelectionError: true,
});
} else {
await subscriptionService.handleNewSubscription(req.body, req.user);
res.redirect('subscription-add-list-language');
}
}
}
19 changes: 19 additions & 0 deletions src/main/controllers/SubscriptionAddListLanguageController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { PipRequest } from '../models/request/PipRequest';
import { Response } from 'express';
import { cloneDeep } from 'lodash';

export default class SubscriptionAddListLanguageController {
public async get(req: PipRequest, res: Response): Promise<void> {
if (req.query.error === 'true') {
res.render('subscription-add-list-language', {
...cloneDeep(req.i18n.getDataByLanguage(req.lng)['subscription-add-list-language']),
noSelectionError: true,
});
} else {
res.render('subscription-add-list-language', {
...cloneDeep(req.i18n.getDataByLanguage(req.lng)['subscription-add-list-language']),
noSelectionError: false,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default class SubscriptionConfigureListConfirmedController {
public async post(req: PipRequest, res: Response): Promise<void> {
const result = await subscriptionService.configureListTypeForLocationSubscriptions(
req.user['userId'],
req.body['list-selections[]']
req.body['list-selections[]'],
[]
);

if (result) {
Expand Down
12 changes: 11 additions & 1 deletion src/main/controllers/SubscriptionConfirmedController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ export default class SubscriptionConfirmedController {
const cacheService = new PendingSubscriptionsFromCache();
const cachedCourts = await cacheService.getPendingSubscriptions(userId, 'courts');
const cachedCases = await cacheService.getPendingSubscriptions(userId, 'cases');
if (cachedCourts?.length) {
if (req.body['list-language'] === undefined) {
res.redirect('/subscription-add-list-language?error=true');
return;
} else {
await subscriptionService.handleNewSubscription(req.body, req.user);
}
}

const cachedListTypes = await cacheService.getPendingSubscriptions(userId, 'listTypes');

if (cachedCases?.length || cachedCourts?.length) {
if (cachedCases?.length || (cachedCourts?.length && cachedListTypes?.length)) {
const subscribed = await subscriptionService.subscribe(userId);
subscribed
? res.render('subscription-confirmed', req.i18n.getDataByLanguage(req.lng)['subscription-confirmed'])
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/locales/cy/subscription-add-list-language.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "Pa fersiwn o'r rhestr ydych chi am ei derbyn?",
"radio1": "Saesneg",
"radio2": "Cymraeg",
"radio3": "Cymraeg a Saesneg",
"buttonText": "Cadarnhau tanysgrifiadau",
"backButton": "Yn ôl",
"error": {
"noSelection": "Dewiswch fersiwn math o restr i barhau",
"title": "Mae yna broblem"
}
}
11 changes: 11 additions & 0 deletions src/main/resources/locales/cy/subscription-add-list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "Dewis Mathau o Restri",
"descriptionText": "Dewiswch y rhestri y byddwch yn eu cael ar gyfer y llysoedd a’r tribiwnlysoedd yr ydych wedi’u dethol. Ni fydd hyn yn effeithio ar unrhyw achosion penodol yr ydych efallai wedi tanysgrifio iddynt. Hefyd, peidiwch ag anghofio dychwelyd yn rheolaidd i weld mathau newydd o restri wrth i ni ychwanegu mwy.",
"userSelections": "Cyfanswm a ddewiswyd",
"selected": "Wedi’i ddewis",
"backButton": "Yn ôl",
"error": {
"nothingSelected": "Dewiswch fath o restr i barhau",
"title": "Mae yna broblem"
}
}
3 changes: 2 additions & 1 deletion src/main/resources/locales/cy/subscription-confirmed.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"p2": " i:",
"addEmailSubscription": "ychwanegu tanysgrifiad e-bost newydd",
"manageYourCurrentSubscriptions": "rheoli eich tanysgrifiadau e-bost cyfredol",
"findCourt": "dod o hyd i lys neu dribiwnlys"
"findCourt": "dod o hyd i lys neu dribiwnlys",
"selectListType": "Dewiswch pa fath o restr i'w derbyn"
}
2 changes: 2 additions & 0 deletions src/main/resources/locales/en/pending-subscriptions.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"title": "Confirm your email subscriptions",
"title_court_subscription": "Your email subscriptions",
"removeText": "Remove",
"table": {
"header1": "Case name",
"header2": "Party name(s)",
"header3": "Reference number",
"header4": "Actions"
},
"buttonText_court_subscription": "Continue",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title_court_subscription and buttonText_court_subscription need to be added to the welsh language resource too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

"buttonText": "Confirm Subscriptions",
"addOther_link": "/subscription-add",
"addOther_text": "Add another email Subscription",
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/locales/en/subscription-add-list-language.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "What version of the list do you want to receive?",
"radio1": "English",
"radio2": "Welsh",
"radio3": "English and Welsh",
"buttonText": "Confirm Subscriptions",
"backButton": "Back",
"error": {
"noSelection": "Please select version of the list type to continue",
"title": "There is a problem"
}
}
11 changes: 11 additions & 0 deletions src/main/resources/locales/en/subscription-add-list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "Select List Types",
"descriptionText": "Choose the lists you will receive for your selected courts and tribunals. This will not affect any specific cases you may have subscribed to. Also don't forget to come back regularly to see new list types as we add more.",
"userSelections": "Total selected",
"selected": "selected",
"backButton": "Back",
"error": {
"nothingSelected": "Please select a list type to continue",
"title": "There is a problem"
}
}
3 changes: 2 additions & 1 deletion src/main/resources/locales/en/subscription-confirmed.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"p2": " in order to:",
"addEmailSubscription": "add a new email subscription",
"manageYourCurrentSubscriptions": "manage your current email subscriptions",
"findCourt": "find a court or tribunal"
"findCourt": "find a court or tribunal",
"selectListType": "select which list type to receive"
}
10 changes: 10 additions & 0 deletions src/main/resources/requests/SubscriptionRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ export class SubscriptionRequests {
return null;
}

public async addListTypeForLocationSubscriptions(userId, payload): Promise<boolean> {
try {
await subscriptionManagementApi.post(`/subscription/add-list-types/${userId}`, payload);
return true;
} catch (error) {
logHelper.logErrorResponse(error, `add subscription's list type for user with ID ${userId}`);
}
return false;
}

public async configureListTypeForLocationSubscriptions(userId, payload): Promise<boolean> {
try {
await subscriptionManagementApi.put(`/subscription/configure-list-types/${userId}`, payload);
Expand Down
11 changes: 11 additions & 0 deletions src/main/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ export default function (app: Application): void {
isPermittedMedia,
app.locals.container.cradle.subscriptionManagementController.get
);
app.get('/subscription-add-list', isPermittedMedia, app.locals.container.cradle.subscriptionAddListController.get);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add new a11y tests for the new routes too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

app.post(
'/subscription-add-list',
isPermittedMedia,
app.locals.container.cradle.subscriptionAddListController.post
);
app.get(
'/subscription-add-list-language',
isPermittedMedia,
app.locals.container.cradle.subscriptionAddListLanguageController.get
);
app.get(
'/subscription-configure-list',
isPermittedMedia,
Expand Down
10 changes: 10 additions & 0 deletions src/main/service/LocationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,14 @@ export class LocationService {
public async deleteLocationById(locationId: number, requester: string): Promise<object> {
return await locationRequest.deleteCourt(locationId, requester);
}

public async findCourtsJurisdiction(locations): Promise<object> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the returned type to Promise<string[]> and not object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks, good catch :)

const courtJurisdictions = [];
for (const location of locations) {
const returnedLocation = await this.getLocationById(location['locationId']);
returnedLocation.jurisdiction.forEach(jurisdiction => courtJurisdictions.push(jurisdiction));
}

return courtJurisdictions;
}
}
15 changes: 14 additions & 1 deletion src/main/service/PendingSubscriptionsFromCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ export class PendingSubscriptionsFromCache {
public async setPendingSubscriptions(subscriptions, subscriptionType, userId): Promise<void> {
if (redisClient.status === 'ready') {
let subscriptionsSet = [];
//We need to clear the cache for only listTypes because user can click back and select
//listTypes again. We need to store the updated values in cache. ListTypes is different
//from court subscription.
redisClient.del(`pending-${subscriptionType}-subscriptions-${userId}`);
if (subscriptionType === 'listTypes' || subscriptionType === 'listLanguage') {
redisClient.del(`pending-${subscriptionType}-subscriptions-${userId}`);
}
const rawData = await redisClient.get(`pending-${subscriptionType}-subscriptions-${userId}`);
const cachedResults = JSON.parse(rawData);
if (cachedResults?.length) {
Expand All @@ -12,6 +19,10 @@ export class PendingSubscriptionsFromCache {
subscriptions.forEach(subscription => {
if (subscriptionType === 'courts') {
this.addToSubscriptionSet(subscription, 'locationId', subscriptionsSet);
} else if (subscriptionType === 'listTypes') {
this.addToSubscriptionSet(subscription, 'listType', subscriptionsSet);
} else if (subscriptionType === 'listLanguage') {
this.addToSubscriptionSet(subscription, 'listLanguage', subscriptionsSet);
} else if (subscription.urnSearch) {
this.addToSubscriptionSet(subscription, 'caseUrn', subscriptionsSet);
} else {
Expand Down Expand Up @@ -63,7 +74,9 @@ export class PendingSubscriptionsFromCache {
}

private addToSubscriptionSet(subscription, filter, subscriptionsSet) {
if (
if (filter === 'listType' && !subscriptionsSet.includes(subscription)) {
subscriptionsSet.push(subscription);
} else if (
!subscriptionsSet.some(
cached => cached[filter] === subscription[filter] && cached['urnSearch'] === subscription['urnSearch']
)
Expand Down
Loading
Loading