Skip to content

Commit

Permalink
Merge pull request #375 from code4romania/release/PROD_v1.0.20
Browse files Browse the repository at this point in the history
Release: v1.0.20
  • Loading branch information
birloiflorian authored Aug 30, 2024
2 parents 419f40e + d12188a commit b7ead36
Show file tree
Hide file tree
Showing 17 changed files with 1,604 additions and 1,513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CognitoModuleOptions } from './cognito.interfaces';
import {
AdminDeleteUserCommand,
AdminUserGlobalSignOutCommand,
AdminUpdateUserAttributesCommand,
CognitoIdentityProviderClient,
} from '@aws-sdk/client-cognito-identity-provider';

Expand All @@ -24,6 +25,21 @@ export class CognitoService {
});
}

async updateUser(cognitoId: string, phoneNumber: string): Promise<unknown> {
const command = new AdminUpdateUserAttributesCommand({
UserPoolId: this.options.defaultUserPoolId,
Username: cognitoId,
UserAttributes: [
{
Name: 'phone_number',
Value: phoneNumber,
},
],
});

return await this.cognitoProvider.send(command);
}

async deleteUser(cognitoId: string): Promise<unknown> {
const deleteUserCommand = new AdminDeleteUserCommand({
UserPoolId: this.options.defaultUserPoolId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const EventRSVPExceptionMessages: Record<
},
[EventsRSVPExceptionCodes.EVENT_RSVP_003]: {
code_error: EventsRSVPExceptionCodes.EVENT_RSVP_003,
message: 'Only ACTIVE volunteers can join events.',
message: 'Only ACTIVE or ARCHIVED volunteers can join events.',
},
[EventsRSVPExceptionCodes.EVENT_RSVP_004]: {
code_error: EventsRSVPExceptionCodes.EVENT_RSVP_004,
Expand Down
5 changes: 3 additions & 2 deletions backend/src/modules/event/repositories/event.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class EventRepository

// Get all events in progress from the organizations i am part or public events
query.andWhere(
'(event.endDate > :currentDate OR event.endDate IS NULL) AND event.startDate <= :currentDate AND ((event.isPublic = :isPublic AND event.organizationId NOT IN ' +
'(event.endDate > :currentDate OR event.endDate IS NULL) AND ((event.isPublic = :isPublic AND event.organizationId NOT IN ' +
query
.subQuery()
.select('vol.organizationId')
Expand Down Expand Up @@ -255,10 +255,11 @@ export class EventRepository
const query = this.createSelectOpenOrganizationGoingEventsBaseSelectQuery();

query.andWhere(
'(event.endDate > :currentDate OR event.endDate IS NULL) AND v.status = :active AND v.userId = :userId',
'(event.endDate > :currentDate OR event.endDate IS NULL) AND ((v.status = :active AND v.userId = :userId) OR event.isPublic = :isPublic)',
{
currentDate: new Date(),
active: VolunteerStatus.ACTIVE,
isPublic: true,
},
);

Expand Down
5 changes: 5 additions & 0 deletions backend/src/modules/user/exceptions/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum UserExceptionCodes {
USER_005 = 'USER_005',
USER_006 = 'USER_006',
USER_007 = 'USER_007',
USER_008 = 'USER_008',
}

type UserExceptionCodeType = keyof typeof UserExceptionCodes;
Expand Down Expand Up @@ -45,4 +46,8 @@ export const UserExceptionMessages: Record<
code_error: UserExceptionCodes.USER_007,
message: 'Error while trying to delete user account',
},
[UserExceptionCodes.USER_008]: {
code_error: UserExceptionCodes.USER_008,
message: 'Error while trying to update the user data',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class UpdateActivityLogUsecase
if (updates.activityTypeId) {
const taskExists = await this.activityTypeFacade.exists(
[updates.activityTypeId],
{ organizationId: log.event.organization.id },
{ organizationId: log.event?.organization.id || log.organization.id }, // in case the organization doesn't have an event associated with it
);
if (!taskExists) {
this.exceptionService.badRequestException(
Expand Down
26 changes: 13 additions & 13 deletions backend/src/usecases/event/RSVP/create-rsvp.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@ export class CreateEventRSVPUseCase
organizationId: event.organization.id,
});

if (volunteer) {
// 4. Only ACTIVE volunteers can join events. In case the user is already a volunteer and is BLOCKED or ARCHIVED. Non-volunteers will pass this validation for public events
if (volunteer.status !== VolunteerStatus.ACTIVE) {
this.exceptionsService.badRequestException(
EventRSVPExceptionMessages.EVENT_RSVP_003,
);
} else if (!volunteer.volunteerProfile) {
// 5. Volunteers must have the profile completed to RSVP.
this.exceptionsService.badRequestException(
EventRSVPExceptionMessages.EVENT_RSVP_005,
);
}
// 4. If the volunteer is blocked the user should not be able to join the event
if (volunteer?.status === VolunteerStatus.BLOCKED) {
this.exceptionsService.badRequestException(
EventRSVPExceptionMessages.EVENT_RSVP_003,
);
}

// 6. For "private" events, check if the USER is VOLUNTEER in the ORGANIZATION of the EVENT
// 5. For "private" events, check if the USER is VOLUNTEER in the ORGANIZATION of the EVENT
if (!event.isPublic && !volunteer) {
this.exceptionsService.badRequestException(
EventRSVPExceptionMessages.EVENT_RSVP_002,
);
}

// 6. For private events volunteers must have the profile completed to RSVP.
if (!event.isPublic && volunteer && !volunteer.volunteerProfile) {
this.exceptionsService.badRequestException(
EventRSVPExceptionMessages.EVENT_RSVP_005,
);
}

// 7. Check if userId and eventId is unique in RSVP, if exists, update only the "going" response
const existingRSVP = await this.eventFacade.findRSVP({
userId: data.userId,
Expand Down
19 changes: 19 additions & 0 deletions backend/src/usecases/user/create-regular-user.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ExceptionsService } from 'src/infrastructure/exceptions/exceptions.serv
import { UserExceptionMessages } from 'src/modules/user/exceptions/exceptions';
import { NotificationsSettingsFacade } from 'src/modules/notifications/notifications-settings.facade';
import { GetOneRegularUserProfileUseCase } from './get-regule-user-profile.usecase';
import { CognitoService } from 'src/infrastructure/providers/cognito/module/cognito.service';
import { JSONStringifyError } from 'src/common/helpers/utils';

@Injectable()
export class CreateRegularUsereUseCaseService
Expand All @@ -21,6 +23,7 @@ export class CreateRegularUsereUseCaseService
private exceptionService: ExceptionsService,
private readonly notificationSettingsFacade: NotificationsSettingsFacade,
private readonly getRegularUserProfileUsecase: GetOneRegularUserProfileUseCase,
private readonly cognitoService: CognitoService,
) {}

async execute(
Expand All @@ -40,11 +43,27 @@ export class CreateRegularUsereUseCaseService
const notificationsSettings =
await this.notificationSettingsFacade.create();

// 1. update cognito phone number
// OBS: This needs to be done as cognito accepts duplicates in regards to phone numbers and this will keep the data in sync
try {
await this.cognitoService.updateUser(newUser.cognitoId, newUser.phone);
} catch (error) {
this.logger.error({
...UserExceptionMessages.USER_008,
error: JSONStringifyError(error),
});
this.exceptionService.internalServerErrorException(
UserExceptionMessages.USER_008,
);
}

// 2. create new user
const user = await this.userService.createRegularUser({
...newUser,
notificationsSettingsId: notificationsSettings.id,
});

// 3. get user profile
return this.getRegularUserProfileUsecase.execute({ id: user.id });
}
}
23 changes: 20 additions & 3 deletions backend/src/usecases/user/update-regular-user.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { S3Service } from 'src/infrastructure/providers/s3/module/s3.service';
import { S3_FILE_PATHS } from 'src/common/constants/constants';
import { JSONStringifyError } from 'src/common/helpers/utils';
import { GetOneRegularUserProfileUseCase } from './get-regule-user-profile.usecase';
import { CognitoService } from 'src/infrastructure/providers/cognito/module/cognito.service';

@Injectable()
export class UpdateRegularUserUsecase
Expand All @@ -23,6 +24,7 @@ export class UpdateRegularUserUsecase
private readonly getRegularUserProfileUsecase: GetOneRegularUserProfileUseCase,
private readonly exceptionService: ExceptionsService,
private readonly s3Service: S3Service,
private readonly cognitoService: CognitoService,
) {}

async execute(
Expand All @@ -38,7 +40,22 @@ export class UpdateRegularUserUsecase
this.exceptionService.notFoundException(UserExceptionMessages.USER_001);
}

// 3. check if new profilePicture is provided
// 3. Check if the user phone number is the same as the one from the request
if (user.phone !== userUpdates.phone) {
try {
await this.cognitoService.updateUser(user.cognitoId, userUpdates.phone);
} catch (error) {
this.logger.error({
...UserExceptionMessages.USER_008,
error: JSONStringifyError(error),
});
this.exceptionService.internalServerErrorException(
UserExceptionMessages.USER_008,
);
}
}

// 4. check if new profilePicture is provided
if (profilePicture) {
try {
// 3.1 upload File and get path
Expand Down Expand Up @@ -67,13 +84,13 @@ export class UpdateRegularUserUsecase
}
}

// 4 update db structure
// 5 update db structure
const updatedUser = await this.userService.updateRegularUser(
id,
userUpdates,
);

// 5. return user profile with presigned url
// 6. return user profile with presigned url
return this.getRegularUserProfileUsecase.execute({ id: updatedUser.id });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import {
} from 'src/modules/volunteer/model/volunteer.model';
import { CreateVolunteerUseCase } from './create-volunteer.usecase';
import { AccessCodeFacade } from 'src/modules/organization/services/access-code.facade';
import { compareAsc } from 'date-fns';
import {
endOfDay,
endOfToday,
endOfTomorrow,
isWithinInterval,
startOfDay,
} from 'date-fns';
import { AccessCodeExceptionMessages } from 'src/modules/organization/exceptions/access-codes.exceptions';

@Injectable()
Expand Down Expand Up @@ -50,10 +56,19 @@ export class JoinOrganizationByAccessCodeUsecase
);
}

// Added this to have more control over the time.
const today = endOfToday();
// start of the day to have the full interval
const startDate = startOfDay(accessCode.startDate);
// end of the day to have the full interval, and also in case the interval is open ended end of tomorrow will always include today
const endDate = endOfDay(accessCode.endDate || endOfTomorrow());

// check fi the access code is valid
if (
compareAsc(accessCode.startDate, new Date()) > 0 ||
(accessCode.endDate && compareAsc(accessCode.endDate, new Date()) < 0)
!isWithinInterval(today, {
start: startDate,
end: endDate,
})
) {
this.exceptionService.badRequestException(
AccessCodeExceptionMessages.ACCESS_CODE_001,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/EditVolunteer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type VolunteerFormTypes = {
branch?: SelectItem<string>;
role?: SelectItem<string>;
department?: SelectItem<string>;
activeSince?: Date;
activeSince?: Date | null;
};

const schema = yup.object({
Expand All @@ -43,6 +43,7 @@ const schema = yup.object({
activeSince: yup
.date()
.optional()
.nullable()
.typeError(`${i18n.t('general:invalid_date')}`),
});

Expand Down
6 changes: 3 additions & 3 deletions mobile/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const expoConfig: ExpoConfig = {
name: 'vic',
slug: 'vic',
scheme: 'vic',
version: '1.0.14',
version: '1.0.19',
orientation: 'portrait',
icon: './src/assets/images/icon.png',
userInterfaceStyle: 'light',
Expand All @@ -18,7 +18,7 @@ const expoConfig: ExpoConfig = {
},
assetBundlePatterns: ['**/*'],
ios: {
buildNumber: '17',
buildNumber: '22',
supportsTablet: false,
bundleIdentifier: 'org.commitglobal.vic',
entitlements: {
Expand All @@ -32,7 +32,7 @@ const expoConfig: ExpoConfig = {
},
},
android: {
versionCode: 15,
versionCode: 22,
adaptiveIcon: {
foregroundImage: './src/assets/images/adaptive-icon.png',
backgroundColor: '#ffffff',
Expand Down
6 changes: 5 additions & 1 deletion mobile/eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@
}
},
"preview": {
"distribution": "internal",
// "distribution": "internal",
"channel": "staging",
"env": {
"EXPO_PUBLIC_ENVIRONMENT": "staging",
"EXPO_PUBLIC_API_URL": "https://api-vic-staging.ngohub.ro",
"EXPO_PUBLIC_AWS_REGION": "eu-west-1",
"EXPO_PUBLIC_USER_POOL_ID": "eu-west-1_HRB7J3vjJ",
"EXPO_PUBLIC_USER_POOL_CLIENT_ID": "4sihusclii449k2otmeetl4dgq",
"EXPO_PUBLIC_AWS_DOMAIN": "vic-staging.auth.eu-west-1.amazoncognito.com",
"EXPO_PUBLIC_PRIVACY_POLICY_LINK": "https://www.ngohub.ro/ro/politica-de-confidentialitate",
"EXPO_PUBLIC_TERMS_AND_CONDITIONS_LINK": "https://www.ngohub.ro/ro/termeni-si-conditii",
"EXPO_PUBLIC_INFORMATION_LINK": "https://www.ngohub.ro/ro/vic",
Expand Down
Loading

0 comments on commit b7ead36

Please sign in to comment.