Skip to content

Commit f05b46a

Browse files
refactor: remove middle name, nationality, and alternate telephone fields from user model and related queries
1 parent 7264365 commit f05b46a

File tree

22 files changed

+32
-164
lines changed

22 files changed

+32
-164
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- 0181_RemoveUserColumns.sql
2+
DO
3+
$$
4+
BEGIN
5+
IF register_patch(
6+
'0181_RemoveUserColumns.sql',
7+
'DBAdmin',
8+
'Remove middle name, nationality, and alternate telephone columns from users table',
9+
'2025-05-12'
10+
) THEN
11+
BEGIN
12+
-- first drop the FK on nationality
13+
ALTER TABLE public.users
14+
DROP CONSTRAINT IF EXISTS users_nationality_fkey;
15+
16+
-- now drop the unwanted columns
17+
ALTER TABLE public.users
18+
DROP COLUMN middlename,
19+
DROP COLUMN nationality,
20+
DROP COLUMN telephone_alt;
21+
22+
DROP TABLE IF EXISTS public.nationalities;
23+
END;
24+
END IF;
25+
END;
26+
$$
27+
LANGUAGE plpgsql;

apps/backend/src/auth/OAuthAuthorization.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,19 @@ export class OAuthAuthorization extends UserAuthorization {
164164
const newUser = await this.userDataSource.create(
165165
(userInfo.title as string) ?? 'unspecified',
166166
userInfo.given_name,
167-
undefined,
168167
userInfo.family_name,
169168
userInfo.email,
170169
userInfo.preferred_username ?? '',
171170
userInfo.sub,
172171
tokenSet.refresh_token ?? '',
173172
client.issuer.metadata.issuer,
174173
userInfo.gender ?? 'unspecified',
175-
1,
176174
new Date(),
177175
institutionId ?? 1,
178176
'',
179177
(userInfo.position as string) ?? '',
180178
userInfo.email,
181-
'',
182-
undefined
179+
''
183180
);
184181

185182
const roleID = this.getUserRole(newUser);

apps/backend/src/datasources/AdminDataSource.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export interface AdminDataSource {
2929
getInstitutionByName(institutionName: string): Promise<Institution | null>;
3030
getInstitutionUsers(id: number): Promise<BasicUserDetails[]>;
3131
getCountries(): Promise<Entry[]>;
32-
getNationalities(): Promise<Entry[]>;
3332
get(id: number): Promise<string | null>;
3433
setPageText(id: number, text: string): Promise<Page>;
3534
resetDB(includeSeeds: boolean): Promise<string[]>;

apps/backend/src/datasources/UserDataSource.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,19 @@ export interface UserDataSource {
5656
create(
5757
user_title: string | undefined,
5858
firstname: string,
59-
middlename: string | undefined,
6059
lastname: string,
6160
username: string,
6261
preferredname: string | undefined,
6362
oidc_sub: string,
6463
oauth_refreshtoken: string,
6564
oauth_issuer: string,
6665
gender: string,
67-
nationality: number,
6866
birthdate: Date,
6967
institution: number,
7068
department: string,
7169
position: string,
7270
email: string,
73-
telephone: string,
74-
telephone_alt: string | undefined
71+
telephone: string
7572
): Promise<User>;
7673
ensureDummyUserExists(userId: number): Promise<User>;
7774
ensureDummyUsersExist(userIds: number[]): Promise<User[]>;

apps/backend/src/datasources/mockups/AdminDataSource.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ export class AdminDataSourceMock implements AdminDataSource {
121121
async getCountries(): Promise<Entry[]> {
122122
throw new Error('Method not implemented.');
123123
}
124-
async getNationalities(): Promise<Entry[]> {
125-
throw new Error('Method not implemented.');
126-
}
124+
127125
async get(id: number): Promise<string | null> {
128126
return 'HELLO WORLD';
129127
}

apps/backend/src/datasources/mockups/UserDataSource.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,20 @@ export const dummyUserOfficer = new User(
4545
4,
4646
'Mr.',
4747
'John',
48-
'Smith',
4948
'Doe',
5049
'JoDo',
5150
'Hailey',
5251
'324235',
5352
'683142616',
5453
'issuer',
5554
'male',
56-
12,
5755
new Date('1990-01-25'),
5856
3,
5957
'Other',
6058
'IT department',
6159
'Producer',
6260
'Dorris83@gmail.com',
6361
'+46700568256',
64-
'',
6562
false,
6663
'2019-07-17 08:25:12.23043+00',
6764
'2019-07-17 08:25:12.23043+00'
@@ -81,23 +78,20 @@ export const dummyUser = new User(
8178
2,
8279
'Dr.',
8380
'Jane',
84-
'',
8581
'Doe',
8682
'JaDa',
8783
'Meta',
8884
'12312414',
8985
'568567353',
9086
'issuer',
9187
'male',
92-
2,
9388
new Date('1981-05-04'),
9489
3,
9590
'Other',
9691
'IT department',
9792
'Architect',
9893
'Cleve30@yahoo.com',
9994
'+38978414058',
100-
'+46700568256',
10195
false,
10296
'2019-07-17 08:25:12.23043+00',
10397
'2019-07-17 08:25:12.23043+00'
@@ -195,23 +189,20 @@ export const dummyPlaceHolderUser = new User(
195189
5,
196190
'Dr.',
197191
'Jane',
198-
'',
199192
'Doe',
200193
'JaDa',
201194
'Meta',
202195
'12312414',
203196
'568567353',
204197
'issuer',
205198
'male',
206-
2,
207199
new Date('1981-05-04'),
208200
3,
209201
'Other',
210202
'IT department',
211203
'Architect',
212204
'placeholder@ess.se',
213205
'+46700568256',
214-
'',
215206
true,
216207
'2019-07-17 08:25:12.23043+00',
217208
'2019-07-17 08:25:12.23043+00'
@@ -221,23 +212,20 @@ export const dummyUserNotOnProposal = new User(
221212
3,
222213
'Dr.',
223214
'Noel',
224-
'',
225215
'Doe',
226216
'NoDO',
227217
'Damion',
228218
'182082741',
229219
'Apricot',
230220
'issuer',
231221
'female',
232-
3,
233222
new Date('1991-11-08'),
234223
5,
235224
'Other',
236225
'IT department',
237226
'Facilitator',
238227
'Tyrique41@hotmail.com',
239228
'+46700568256',
240-
'',
241229
false,
242230
'2019-07-17 08:25:12.23043+00',
243231
'2019-07-17 08:25:12.23043+00'

apps/backend/src/datasources/postgres/AdminDataSource.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
createSettingsObject,
3535
FeatureRecord,
3636
InstitutionRecord,
37-
NationalityRecord,
3837
PageTextRecord,
3938
SettingsRecord,
4039
TokensAndPermissionsRecord,
@@ -192,17 +191,6 @@ export default class PostgresAdminDataSource implements AdminDataSource {
192191
return createPageObject(pagetextRecord);
193192
}
194193

195-
async getNationalities(): Promise<Entry[]> {
196-
return database
197-
.select()
198-
.from('nationalities')
199-
.then((natDB: NationalityRecord[]) =>
200-
natDB.map((nat) => {
201-
return { id: nat.nationality_id, value: nat.nationality };
202-
})
203-
);
204-
}
205-
206194
async getInstitutions(filter: InstitutionsFilter): Promise<Institution[]> {
207195
return database
208196
.select()

apps/backend/src/datasources/postgres/UserDataSource.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,15 @@ export default class PostgresUserDataSource implements UserDataSource {
7474
const {
7575
firstname,
7676
user_title,
77-
middlename,
7877
lastname,
7978
preferredname,
8079
gender,
81-
nationality,
8280
birthdate,
8381
institutionId,
8482
department,
8583
position,
8684
email,
8785
telephone,
88-
telephone_alt,
8986
placeholder,
9087
oidcSub,
9188
oauthRefreshToken,
@@ -96,18 +93,15 @@ export default class PostgresUserDataSource implements UserDataSource {
9693
.update({
9794
firstname,
9895
user_title,
99-
middlename,
10096
lastname,
10197
preferredname,
10298
gender,
103-
nationality,
10499
birthdate,
105100
institution_id: institutionId,
106101
department,
107102
position,
108103
email,
109104
telephone,
110-
telephone_alt,
111105
placeholder,
112106
oidc_sub: oidcSub,
113107
oauth_refresh_token: oauthRefreshToken,
@@ -126,22 +120,19 @@ export default class PostgresUserDataSource implements UserDataSource {
126120
.insert({
127121
user_title: '',
128122
firstname,
129-
middlename: '',
130123
lastname,
131124
username: email,
132125
preferredname: firstname,
133126
oidc_sub: '',
134127
oauth_refresh_token: '',
135128
oauth_issuer: '',
136129
gender: '',
137-
nationality: null,
138130
birthdate: '2000-01-01',
139131
institution_id: 1,
140132
department: '',
141133
position: '',
142134
email,
143135
telephone: '',
144-
telephone_alt: '',
145136
placeholder: true,
146137
})
147138
.returning(['*'])
@@ -324,43 +315,37 @@ export default class PostgresUserDataSource implements UserDataSource {
324315
async create(
325316
user_title: string | undefined,
326317
firstname: string,
327-
middlename: string | undefined,
328318
lastname: string,
329319
username: string,
330320
preferredname: string | undefined,
331321
oidc_sub: string,
332322
oauth_refresh_token: string,
333323
oauth_issuer: string,
334324
gender: string,
335-
nationality: number,
336325
birthdate: Date,
337326
institution_id: number,
338327
department: string,
339328
position: string,
340329
email: string,
341-
telephone: string,
342-
telephone_alt: string | undefined
330+
telephone: string
343331
): Promise<User> {
344332
return database
345333
.insert({
346334
user_title,
347335
firstname,
348-
middlename,
349336
lastname,
350337
username,
351338
preferredname,
352339
oidc_sub,
353340
oauth_refresh_token,
354341
oauth_issuer,
355342
gender,
356-
nationality,
357343
birthdate,
358344
institution_id,
359345
department,
360346
position,
361347
email,
362348
telephone,
363-
telephone_alt,
364349
})
365350
.returning(['*'])
366351
.into('users')
@@ -420,21 +405,18 @@ export default class PostgresUserDataSource implements UserDataSource {
420405
user_id: userId,
421406
user_title: '',
422407
firstname: '',
423-
middlename: '',
424408
lastname: '',
425409
username: userId.toString(),
426410
preferredname: '',
427411
oidc_sub: '',
428412
oauth_refresh_token: '',
429413
gender: '',
430-
nationality: 1,
431414
birthdate: '2000-01-01',
432415
institution_id: 1,
433416
department: '',
434417
position: '',
435418
email: userId.toString(),
436419
telephone: '',
437-
telephone_alt: '',
438420
};
439421
}
440422

0 commit comments

Comments
 (0)