Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions src/entities/registration.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
Expand Down Expand Up @@ -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),
};
}
Expand All @@ -299,6 +307,7 @@ export class RegistrationEntity extends PickType(Registration, [
"project",
"referral",
"shareEmailMlh",
"textOptIn",
"time",
"veteran",
"excitement",
Expand Down
60 changes: 59 additions & 1 deletion src/modules/registration/registration.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,6 +37,12 @@ import {
DefaultFromEmail,
} from "common/sendgrid";

class UpdateTextOptInDto {
@ApiProperty({ type: "boolean" })
@IsBoolean()
textOptIn: boolean;
}

class UpdateStatusBulkDto {
@ApiProperty({ type: [String] })
@IsArray()
Expand Down Expand Up @@ -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({
Expand Down
3 changes: 3 additions & 0 deletions src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class UserRegistrationExportRow {
@ApiProperty()
share_email_mlh: boolean;

@ApiProperty()
text_opt_in: boolean;

@ApiProperty()
driving: boolean;

Expand Down
1 change: 1 addition & 0 deletions src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading