diff --git a/src/entities/registration.entity.ts b/src/entities/registration.entity.ts index 2ebb11b8..63d1095a 100644 --- a/src/entities/registration.entity.ts +++ b/src/entities/registration.entity.ts @@ -170,6 +170,13 @@ export class Registration extends Entity { @Column({ type: "boolean", required: false, nullable: true }) shareEmailMlh?: boolean = false; + @ApiProperty({ type: "boolean", required: false, default: false }) + @IsOptional() + @IsBoolean() + @Type(() => Boolean) + @Column({ type: "boolean", required: false }) + textOptIn?: boolean = false; + @ApiProperty() @IsString() @Column({ type: "string" }) @@ -275,6 +282,7 @@ export class Registration extends Entity { ...this.parseBoolean("shareAddressMlh", json.shareAddressMlh), ...this.parseBoolean("shareAddressSponsors", json.shareAddressSponsors), ...this.parseBoolean("shareEmailMlh", json.shareEmailMlh), + ...this.parseBoolean("textOptIn", json.textOptIn), ...this.parseBoolean("firstHackathon", json.firstHackathon), }; } @@ -299,6 +307,7 @@ export class RegistrationEntity extends PickType(Registration, [ "project", "referral", "shareEmailMlh", + "textOptIn", "time", "veteran", "excitement", diff --git a/src/modules/registration/registration.controller.ts b/src/modules/registration/registration.controller.ts index 29607091..2479c9b0 100644 --- a/src/modules/registration/registration.controller.ts +++ b/src/modules/registration/registration.controller.ts @@ -18,7 +18,7 @@ import { import { RegistrationWithScoreDto } from "./dto/registration-with-score.dto"; import { UpdateStatusDto } from "./dto/update-status.dto"; import { ApiProperty, ApiTags } from "@nestjs/swagger"; -import { Role, Roles } from "common/gcp"; +import { RestrictedRoles, Role, Roles } from "common/gcp"; import { ApiDoc } from "common/docs"; import { ArrayMinSize, @@ -37,6 +37,12 @@ import { DefaultFromEmail, } from "common/sendgrid"; +class UpdateTextOptInDto { + @ApiProperty({ type: "boolean" }) + @IsBoolean() + textOptIn: boolean; +} + class UpdateStatusBulkDto { @ApiProperty({ type: [String] }) @IsArray() @@ -191,6 +197,58 @@ export class RegistrationController { } } + @Patch("/:userId/text-opt-in") + @RestrictedRoles({ + roles: [Role.NONE, Role.VOLUNTEER], + predicate: (req) => req.user && req.user.sub === req.params.userId, + }) + @Roles(Role.TEAM) + @ApiDoc({ + summary: "Update Text Opt-In", + params: [ + { + name: "userId", + type: "string", + description: "The ID of the user to update", + }, + ], + request: { + body: { type: UpdateTextOptInDto }, + validate: true, + }, + response: { + ok: { type: RegistrationEntity }, + custom: [{ status: 404, description: "Registration not found" }], + }, + auth: Role.NONE, + restricted: true, + dbException: true, + }) + async updateTextOptIn( + @Param("userId") userId: string, + @Body( + new ValidationPipe({ + whitelist: true, + forbidNonWhitelisted: true, + }), + ) + body: UpdateTextOptInDto, + ) { + const registration = await this.registrationRepo + .findAll() + .byHackathon() + .where("userId", userId) + .first(); + + if (!registration) { + throw new NotFoundException(`Registration for user ${userId} not found`); + } + + return this.registrationRepo + .patchOne(registration.id, { textOptIn: body.textOptIn }) + .exec(); + } + @Patch("/:userId/application-status") @Roles(Role.NONE) @ApiDoc({ diff --git a/src/modules/user/user.controller.ts b/src/modules/user/user.controller.ts index 368079a2..68bdd9c7 100644 --- a/src/modules/user/user.controller.ts +++ b/src/modules/user/user.controller.ts @@ -124,6 +124,9 @@ class UserRegistrationExportRow { @ApiProperty() share_email_mlh: boolean; + @ApiProperty() + text_opt_in: boolean; + @ApiProperty() driving: boolean; diff --git a/src/modules/user/user.service.ts b/src/modules/user/user.service.ts index 850da635..ef3809dd 100644 --- a/src/modules/user/user.service.ts +++ b/src/modules/user/user.service.ts @@ -90,6 +90,7 @@ export class UserService { registrations.share_address_mlh, registrations.share_address_sponsors, registrations.share_email_mlh, + registrations.text_opt_in, registrations.driving, registrations.travel_reimbursement, registrations.first_hackathon