Skip to content

Commit

Permalink
add new routes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwn04 committed Oct 13, 2024
1 parent a7e53eb commit 893feb1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions api/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export class UserController {
return { error: null, user: userProfile };
}

@Patch('/onboarding/collect')
async collectOnboarding(@AuthenticatedUser() user: UserModel): Promise<GetCurrentUserResponse> {
const userProfile = await this.userAccountService.collectOnboarding(user);
return { error: null, user: userProfile };
}

@Patch()
async patchCurrentUser(@Body() patchUserRequest: PatchUserRequest,
@AuthenticatedUser() user: UserModel): Promise<PatchUserResponse> {
Expand Down
3 changes: 3 additions & 0 deletions api/validators/UserControllerRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export class UserPatches implements IUserPatches {
@Allow()
isAttendancePublic?: boolean;

@Allow()
onboardingSeen?: boolean;

@Type(() => PasswordUpdate)
@ValidateNested()
@HasMatchingPasswords()
Expand Down
22 changes: 18 additions & 4 deletions services/UserAccountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
englishDataset,
englishRecommendedTransformers,
} from 'obscenity';
import { UserError } from 'utils/Errors';
import Repositories, { TransactionsManager } from '../repositories';
import {
Uuid,
Expand Down Expand Up @@ -166,6 +167,23 @@ export default class UserAccountService {
});
}

public async collectOnboarding(user: UserModel): Promise<UserModel> {
if (user.attendances.length < 5
|| user.resumes.length < 1
|| user.profilePicture == null
|| user.bio == null) {
throw new UserError('Onboarding tasks not completed');
}
if (user.onboardingCollected) {
throw new UserError('Onboarding reward already collected');
}
return this.transactions.readWrite(async (txn) => {
const userRepository = Repositories.user(txn);
await userRepository.addPoints(user, 10);
return userRepository.upsertUser(user, { onboardingCollected: true });
});
}

public async grantBonusPoints(emails: string[], description: string, points: number) {
return this.transactions.readWrite(async (txn) => {
const userRepository = Repositories.user(txn);
Expand All @@ -188,10 +206,6 @@ export default class UserAccountService {
.getAllNamesAndEmails());
}

public async checkOnboarding(user: UserModel) : Promise<void> {

}

/**
* UserAccountService::getFullUserProfile() differs from UserModel::getFullUserProfile() in that it also returns any
* user data that needs to be joined from other tables (e.g. resumes and social media URLs)
Expand Down
1 change: 1 addition & 0 deletions types/ApiRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface UserPatches {
graduationYear?: number;
bio?: string;
isAttendancePublic?: boolean;
onboardingSeen?: boolean;
passwordChange?: PasswordUpdate;
}

Expand Down

0 comments on commit 893feb1

Please sign in to comment.