Skip to content

Commit

Permalink
chore(user-profile): Remove migration worker and make user profile st…
Browse files Browse the repository at this point in the history
…rict (#14791)

* Remove worker and make user profile strict

* Fix dependant type errors.

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
saevarma and kodiakhq[bot] authored Jun 10, 2024
1 parent f8f6646 commit d8665eb
Show file tree
Hide file tree
Showing 37 changed files with 152 additions and 1,675 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,15 @@ export class UserProfileService {
auth,
).meUserProfileControllerFindUserProfile()
return {
email: userProfile.isRestricted ? undefined : userProfile.email,
email: userProfile.isRestricted
? undefined
: userProfile.email ?? undefined,
emailVerified: userProfile.isRestricted
? undefined
: userProfile.emailVerified,
phoneNumber: userProfile.isRestricted
? undefined
: userProfile.mobilePhoneNumber,
: userProfile.mobilePhoneNumber ?? undefined,
phoneNumberVerified: userProfile.isRestricted
? undefined
: userProfile.mobilePhoneNumberVerified,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const WORK_ENDING_HOUR = 23 // 11 PM
type HandleNotification = {
profile: {
nationalId: string
email?: string
email?: string | null
documentNotifications: boolean
emailNotifications: boolean
locale?: string
Expand Down
36 changes: 0 additions & 36 deletions apps/services/user-profile/infra/service-portal-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ import {
NationalRegistryB2C,
} from '../../../../infra/src/dsl/xroad'

// We basically don't want it to run in a cron job
// but manually, so set it to run once a year on dec 31st
const schedule = '0 0 31 12 *'

const namespace = 'service-portal'
const serviceId = `${namespace}-api`
const workerId = `${serviceId}-worker`
const imageId = 'services-user-profile'

const envVariables: EnvironmentVariables = {
Expand All @@ -36,11 +31,6 @@ const envVariables: EnvironmentVariables = {
staging: 'false',
prod: 'false',
},
USER_PROFILE_WORKER_PAGE_SIZE: {
dev: '3000',
staging: '3000',
prod: '3000',
},
AUTH_DELEGATION_API_URL: {
dev: 'http://web-services-auth-delegation-api.identity-server-delegation.svc.cluster.local',
staging:
Expand Down Expand Up @@ -68,32 +58,6 @@ const secrets: Secrets = {
'/k8s/api/NATIONAL_REGISTRY_B2C_CLIENT_SECRET',
}

export const workerSetup = (): ServiceBuilder<typeof workerId> =>
service(workerId)
.namespace(namespace)
.image(imageId)
.env(envVariables)
.secrets(secrets)
.files({ filename: 'islyklar.p12', env: 'ISLYKILL_CERT' })
.command('node')
.args('main.js', '--job=worker')
.resources({
limits: { cpu: '800m', memory: '1024Mi' },
requests: { cpu: '400m', memory: '512Mi' },
})
.db()
.extraAttributes({
dev: {
schedule,
},
staging: {
schedule,
},
prod: {
schedule,
},
})

export const serviceSetup = (): ServiceBuilder<typeof serviceId> =>
service(serviceId)
.namespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

module.exports = {
async up(queryInterface) {
return queryInterface.dropTable('user_profile_advania')
},

async down(queryInterface, Sequelize) {
/**
* This migration is cleaning up the migration table used when we migrated from the old user profile database.
*
* There is no down action as we cannot reinstate the data that was dropped along with the table.
*/
},
}
9 changes: 1 addition & 8 deletions apps/services/user-profile/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@
"buildTarget": "services-user-profile:build"
}
},
"worker": {
"executor": "@nx/js:node",
"options": {
"buildTarget": "services-user-profile:build",
"args": ["--job", "worker"]
}
},
"lint": {
"executor": "@nx/linter:eslint",
"options": {
Expand Down Expand Up @@ -98,7 +91,7 @@
"migrate/generate": {
"executor": "nx:run-commands",
"options": {
"command": "../../../node_modules/.bin/sequelize-cli migration:generate --name $(whoami)",
"command": "../../../node_modules/.bin/sequelize-cli migration:generate",
"cwd": "apps/services/user-profile/"
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IsNotEmpty, IsString } from 'class-validator'
import { ApiProperty } from '@nestjs/swagger'
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'

export class ConfirmEmailDto {
@IsNotEmpty()
@IsString()
@ApiProperty()
readonly hash!: string
@ApiPropertyOptional()
readonly hash?: string

@IsNotEmpty()
@IsString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IsNotEmpty, IsString } from 'class-validator'
import { ApiProperty } from '@nestjs/swagger'
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'

export class ConfirmSmsDto {
@IsNotEmpty()
@IsString()
@ApiProperty()
readonly code!: string
@ApiPropertyOptional()
readonly code?: string

@IsNotEmpty()
@IsString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {
UpdatedAt,
} from 'sequelize-typescript'
import { ApiProperty } from '@nestjs/swagger'
import type {
CreationOptional,
InferAttributes,
InferCreationAttributes,
} from 'sequelize'

@Table({
tableName: 'email_verification',
Expand All @@ -17,23 +22,26 @@ import { ApiProperty } from '@nestjs/swagger'
},
],
})
export class EmailVerification extends Model<EmailVerification> {
export class EmailVerification extends Model<
InferAttributes<EmailVerification>,
InferCreationAttributes<EmailVerification>
> {
@Column({
type: DataType.UUID,
primaryKey: true,
allowNull: false,
defaultValue: DataType.UUIDV4,
})
@ApiProperty()
id!: string
id!: CreationOptional<string>

@CreatedAt
@ApiProperty()
created!: Date
created!: CreationOptional<Date>

@UpdatedAt
@ApiProperty()
modified!: Date
modified!: CreationOptional<Date>

@Column({
type: DataType.STRING,
Expand All @@ -47,7 +55,7 @@ export class EmailVerification extends Model<EmailVerification> {
type: DataType.BOOLEAN,
})
@ApiProperty()
confirmed!: boolean
confirmed!: CreationOptional<boolean>

@Column({
type: DataType.STRING,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {
UpdatedAt,
} from 'sequelize-typescript'
import { ApiProperty } from '@nestjs/swagger'
import type {
CreationOptional,
InferAttributes,
InferCreationAttributes,
} from 'sequelize'

@Table({
tableName: 'sms_verification',
Expand All @@ -17,23 +22,26 @@ import { ApiProperty } from '@nestjs/swagger'
},
],
})
export class SmsVerification extends Model<SmsVerification> {
export class SmsVerification extends Model<
InferAttributes<SmsVerification>,
InferCreationAttributes<SmsVerification>
> {
@Column({
type: DataType.UUID,
primaryKey: true,
allowNull: false,
defaultValue: DataType.UUIDV4,
})
@ApiProperty()
id!: string
id!: CreationOptional<string>

@CreatedAt
@ApiProperty()
created!: Date
created!: CreationOptional<Date>

@UpdatedAt
@ApiProperty()
modified!: Date
modified!: CreationOptional<Date>

@Column({
type: DataType.STRING,
Expand All @@ -53,7 +61,7 @@ export class SmsVerification extends Model<SmsVerification> {
type: DataType.BOOLEAN,
})
@ApiProperty()
confirmed!: boolean
confirmed!: CreationOptional<boolean>

@Column({
type: DataType.STRING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import {
CreatedAt,
UpdatedAt,
} from 'sequelize-typescript'
import type {
CreationOptional,
InferAttributes,
InferCreationAttributes,
} from 'sequelize'

@Table({
tableName: 'user_device_tokens',
Expand All @@ -16,20 +21,23 @@ import {
},
],
})
export class UserDeviceTokens extends Model<UserDeviceTokens> {
export class UserDeviceTokens extends Model<
InferAttributes<UserDeviceTokens>,
InferCreationAttributes<UserDeviceTokens>
> {
@Column({
type: DataType.UUID,
primaryKey: true,
allowNull: false,
defaultValue: DataType.UUIDV4,
})
id!: string
id!: CreationOptional<string>

@CreatedAt
created!: Date
created!: CreationOptional<Date>

@UpdatedAt
modified!: Date
modified!: CreationOptional<Date>

@Column({
type: DataType.STRING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
HttpCode,
Delete,
Patch,
NotFoundException,
} from '@nestjs/common'
import { NoContentException } from '@island.is/nest/problem'
import {
Expand Down Expand Up @@ -49,6 +48,7 @@ import { UserProfileService } from './userProfile.service'
import { VerificationService } from './verification.service'
import { DataStatus } from './types/dataStatusTypes'
import { ActorLocale } from './dto/actorLocale'
import { Locale } from './types/localeTypes'

@UseGuards(IdsUserGuard, ScopesGuard)
@ApiTags('User Profile')
Expand Down Expand Up @@ -113,7 +113,7 @@ export class UserProfileController {

return {
nationalId: userProfile.nationalId,
locale: userProfile.locale,
locale: userProfile.locale ?? Locale.ICELANDIC,
}
}

Expand Down Expand Up @@ -201,8 +201,7 @@ export class UserProfileController {
try {
return await this.findOneByNationalId(nationalId, user)
} catch (error) {
const ret = await this.create({ nationalId }, user)
return ret
return this.create({ nationalId }, user)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ export class UserProfileService {
private readonly userDeviceTokensModel: typeof UserDeviceTokens,
) {}

async findById(id: string): Promise<UserProfile | null> {
this.logger.debug(`Finding user profile by id "${id}"`)
return this.userProfileModel.findOne({
where: { id },
})
}

async create(userProfileDto: CreateUserProfileDto): Promise<UserProfile> {
return this.userProfileModel.create({ ...userProfileDto })
}
Expand Down Expand Up @@ -74,7 +67,7 @@ export class UserProfileService {
...body,
nationalId: user.nationalId,
})
} catch (e: any) {
} catch (e) {
throw new BadRequestException(e.errors)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class UserTokenController {
async findOneByNationalId(
@Param('nationalId')
nationalId: string,
): Promise<UserProfile> {
): Promise<UserProfile | null> {
const userProfile = await this.userProfileService.findByNationalId(
nationalId,
)
Expand Down
Loading

0 comments on commit d8665eb

Please sign in to comment.