Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added toggle feature #121

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion apps/migrate/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ export class AppService {
return JSON.parse(correctJsonSyntax);
} catch (error) {
console.error('Could not parse:', correctJsonSyntax);
throw new Error(error);
throw new Error(error as string); // @TODO :Investigate this, whecn just new Error(error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not looked but do we have a tech debt or regular research ticket written for this?

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
BaSubmitEpApplicationDto,
ChangePasswordDto,
CreateChangeMakerProfileDto,
ForDonationDto,
GetSuperAdminForExchangePartnerDto,
SignUpDto,
SubmitEpApplicationDto,
Expand Down Expand Up @@ -332,6 +333,21 @@ export const changePasswordError = createAction(
props<{ error: OrchaOperationError }>()
);

/**
* @TODO Delete this on fail
*/
export const changeForDonation = createAction(
'[UserSession] Change forDonation',
props<{ dto: ForDonationDto }>()
);

export const changeForDonationSuccess = createAction('[UserSession] Change forDonation Success');

export const changeForDonationError = createAction(
'[UserSession] Change forDonation Error',
props<{ error: OrchaOperationError }>()
);

/*
___ _ _ _ _ _ _
| __(_)_ _ (_)__| |_ _ | |___ _ _ _ _(_)__| |___
Expand Down
4 changes: 4 additions & 0 deletions libs/client/shared/data-access/src/lib/+state/user.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EditCmProfileDto,
EditEpProfileDto,
EditSpProfileDto,
ForDonationDto,
GetSuperAdminForExchangePartnerDto,
ImConfig,
SignUpDto,
Expand Down Expand Up @@ -207,6 +208,9 @@ export class UserFacade {
changePassword: (dto: ChangePasswordDto) => {
this.store.dispatch(UserSessionActions.changePassword({ dto }));
},
changeForDonation: (dto: ForDonationDto) => {
this.store.dispatch(UserSessionActions.changeForDonation({ dto }));
},
},
selectors: {
state$: this.store.select(UserSessionSelectors.getState),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ export class UserOrchestration implements IClientOrchestration<IUserOrchestratio
@ClientOperation()
finishJoyride!: IClientOrchestration<IUserOrchestration>['finishJoyride'];
@ClientOperation()
changeForDonation!: IClientOrchestration<IUserOrchestration>['changeForDonation'];
@ClientOperation()
adminUserSearch!: IClientOrchestration<IUserOrchestration>['adminUserSearch'];
}
17 changes: 16 additions & 1 deletion libs/client/shell/src/lib/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Dark mode is {{ state.darkMode ? 'on' : 'off' }}.
</div>
</im-block>
<!-- -->
<im-block>
<div header class="im-primary-text">Nav Tabs</div>
<div body class="item">
Expand All @@ -32,6 +33,7 @@
Nav Tabs is {{ state.navTabs ? 'on' : 'off' }}.
</div>
</im-block>
<!-- -->
<im-block>
<div header class="im-primary-text">Side Menu Behavior</div>
<div body class="item">
Expand All @@ -47,7 +49,20 @@
}}
</div>
</im-block>

<!-- Change for donation -->
<ng-container *ngIf="state.authenticated">
<div body [formGroup]="changeForDonationForm">
<im-block>
<div header class="im-primary-text">Raising For Donation?</div>
<div body class="item">
<div>Toggle between Raising credit for donation and personal use.</div>
<ion-toggle [checked]="state.forDonation" (ionChange)="(changeForDonation)"></ion-toggle>
{{ state.forDonation ? 'Marked to Donating when On.' : 'For personal use when Off.' }}
</div>
</im-block>
</div>
</ng-container>
<!-- -->
<ng-container *ngIf="state.authenticated && !state.isAdmin">
<im-block>
<div header class="im-primary-text">Change Password</div>
Expand Down
18 changes: 18 additions & 0 deletions libs/client/shell/src/lib/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface State {
navTabs: boolean;
isAdmin: boolean;
sideMenuBehavior: UserSessionState['sideMenuBehavior'];
forDonation: boolean; // UserSessionState['forDonation'];
}

@Component({
Expand All @@ -40,6 +41,9 @@ export class SettingsComponent extends StatefulComponent<State> implements OnIni
},
{ validators: (ac) => ConfirmPasswordValidator.MatchPassword(ac, 'newPassword', 'confirmPassword') }
);
readonly changeForDonationForm = new FormGroup({
forDonation: new FormControl('', (e) => Validators.required(e)),
});

readonly pwdValidationText = ImConfig.regex.password.text;

Expand All @@ -50,10 +54,12 @@ export class SettingsComponent extends StatefulComponent<State> implements OnIni
navTabs: true,
isAdmin: false,
sideMenuBehavior: 'hidden',
forDonation: true, // @TODO Check and change to initial user state
});
}

ngOnInit(): void {
console.log(this.user);
const theme = localStorage.getItem('theme');
this.state.darkMode = theme === 'dark';

Expand Down Expand Up @@ -110,10 +116,22 @@ export class SettingsComponent extends StatefulComponent<State> implements OnIni
);
}

creditForOrgs() {
this.user.session.dispatchers.toggleSideMenuBehavior(
this.state.sideMenuBehavior === 'hidden' ? 'responsive' : 'hidden'
);
}

changePassword() {
this.user.session.dispatchers.changePassword({
currentPassword: this.changePasswordForm.value.currentPassword,
newPassword: this.changePasswordForm.value.newPassword,
});
}

changeForDonation() {
this.user.session.dispatchers.changeForDonation({
forDonation: true,
});
}
}
20 changes: 18 additions & 2 deletions libs/server/core/application-services/src/lib/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {
ChangePasswordDto,
defaultStorefrontListingStatus,
environment,
ForDonationDto,
GrantBaPrivilegesDto,
ImConfig,
ISnoopData,
RevokeBaPrivilegesDto,
SearchUserDto,
SignUpDto,
SnoopDto,
User
User,
} from '@involvemint/shared/domain';
import { HttpException, HttpService, HttpStatus, Injectable } from '@nestjs/common';
import { IQuery, parseQuery } from '@orcha/common';
Expand All @@ -32,7 +33,7 @@ export class UserService {
private readonly email: EmailService,
private readonly httpService: HttpService,
private readonly epRepo: ExchangePartnerRepository
) { }
) {}

async verifyUserEmail(email: string): Promise<boolean> {
const user = await this.userRepo.findOne(email, { id: true });
Expand Down Expand Up @@ -447,6 +448,21 @@ export class UserService {
return {};
}

/**
* Changes wheter the uer wants to raise the credtis for personal or donation use
* @param token
* @param dto
* @returns
*/
async changeForDonation(token: string, dto: ForDonationDto) {
console.log('Should change for donation ', dto);
const { id } = await this.auth.validateUserToken(token);
await this.userRepo.update(id, {
forDonation: dto.forDonation,
});
return {};
}

async finishJoyride(token: string) {
const user = await this.auth.validateUserToken(token);
return this.userRepo.update(user.id, { joyride: false });
Expand Down
3 changes: 3 additions & 0 deletions libs/server/core/domain-services/src/lib/user/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class UserEntity implements Required<User> {
@Column({ default: false })
baAdmin!: boolean;

@Column({ default: false })
forDonation!: boolean;

@OneToOne(() => ChangeMakerEntity, (e) => e.user, { nullable: true })
@JoinColumn()
changeMaker!: ChangeMakerEntity;
Expand Down
6 changes: 6 additions & 0 deletions libs/server/orcha/src/lib/user/user.orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AdminLoginQuery,
AdminUserSearchDto,
ChangePasswordDto,
ForDonationDto,
ForgotPasswordChangeDto,
ForgotPasswordDto,
GrantBaPrivilegesDto,
Expand Down Expand Up @@ -123,6 +124,11 @@ export class UserOrchestration implements IServerOrchestration<IUserOrchestratio
return this.user.changePassword(token, dto);
}

@ServerOperation()
async changeForDonation(_: IQuery<{}>, token: string, dto: ForDonationDto) {
return this.user.changeForDonation(token, dto);
}

@ServerOperation()
async finishJoyride(_: IQuery<{}>, token: string) {
return this.user.finishJoyride(token);
Expand Down
7 changes: 6 additions & 1 deletion libs/shared/domain/src/lib/domain/user/user.dtos.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsOptional, IsString, Matches } from 'class-validator';
import { IsBoolean, IsOptional, IsString, Matches } from 'class-validator';
import { ImConfig } from '../../config';

export abstract class VerifyUserEmailDto {
Expand Down Expand Up @@ -114,6 +114,11 @@ export abstract class ChangePasswordDto {
newPassword!: string;
}

export abstract class ForDonationDto {
@IsBoolean()
forDonation!: boolean;
}

export abstract class AdminUserSearchDto {
@IsString()
searchStr!: string;
Expand Down
1 change: 1 addition & 0 deletions libs/shared/domain/src/lib/domain/user/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface User {
active: boolean;
activationHash?: string;
forgotPasswordHash?: string;
forDonation?: boolean;
joyride: boolean;
baAdmin: boolean;

Expand Down
2 changes: 2 additions & 0 deletions libs/shared/domain/src/lib/domain/user/user.orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AdminLoginDto,
AdminUserSearchDto,
ChangePasswordDto,
ForDonationDto,
ForgotPasswordChangeDto,
ForgotPasswordDto,
GrantBaPrivilegesDto,
Expand Down Expand Up @@ -38,6 +39,7 @@ export interface IUserOrchestration {
forgotPassword: IOperation<{}, ForgotPasswordDto>;
forgotPasswordChange: IOperation<{}, ForgotPasswordChangeDto>;
changePassword: IOperation<{}, ChangePasswordDto>;
changeForDonation: IOperation<{}, ForDonationDto>;
finishJoyride: IOperation<{}, undefined>;
adminUserSearch: IOperation<User[], AdminUserSearchDto>;
}
38 changes: 19 additions & 19 deletions libs/shared/domain/src/lib/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export const environment: Env = {
host,
apiUrl: `http://${host}:3335`,
appUrl: `http://${host}:4202`,
storageBucket: 'your storage bucket',
storageBucket: 'involvemint-tech',
adminPasswordHash:
'sZfCJx5X3sGSwkokIs9IVFxDfxWd2lEKsAhkOSDfEK8u2YS98y5rJAmXmtrJs7AQ29xkHMmz0bDfLkXCKS9/+A==',
gcpApiKey: 'insert your key here',
gcpApiKey: 'AIzaSyBmrVarnXPU9Wfdp07kQSna7Qqa5F1jHDw',
typeOrmConfig: {
type: 'postgres',
host: '127.0.0.1',
Expand All @@ -25,16 +25,15 @@ export const environment: Env = {
ssl: false,
},
firebaseEnv: {
apiKey: 'insert your key here',
authDomain: 'firebase auth domain',
databaseURL: '',
projectId: 'your project id',
storageBucket: 'Your project storage bucket', //your-something.appspot.com
messagingSenderId: '',
appId: 'your app id',
measurementId: 'Your measurementId',
apiKey: 'AIzaSyBmrVarnXPU9Wfdp07kQSna7Qqa5F1jHDw',
authDomain: 'involvemint-tech.firebaseapp.com',
databaseURL: 'https://involvemint-tech.firebaseio.com',
projectId: 'involvemint-tech',
storageBucket: 'involvemint-tech.appspot.com',
messagingSenderId: '58069019596',
appId: '1:58069019596:web:e743232f22300632b84b69',
measurementId: 'G-1KE5J3JBW7',
},
// mailgun and twilio are optional
mailgun: {
apiKey: '',
domain: '',
Expand All @@ -46,23 +45,24 @@ export const environment: Env = {
},
gcp: {
type: 'service_account',
project_id: 'project-id',
private_key_id: 'Your Private Key',
project_id: 'involvemint-tech',
private_key_id: '198bde8a228202aa9eb393c3a622eed1f95ca874',
private_key:
'-----BEGIN PRIVATE KEY-----\nYour Private Key\n-----END PRIVATE KEY-----\n',
client_email: 'Your client email',
client_id: 'client id',
'-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQD1fEG+td0dLLKe\nx1ACy6p+86gUHJUu7iHGFMIpI6FG5syF4a1nME4M1yJeNQaB49qODdEsDoH2mMLK\nbimQuMrhn6DKSZHaZvnClRBDhZINFY8luLUic2Tp94BB4P1CvAJCX+Ep1bYb9IR6\n0qbO+Nb8iSmGUNcyH/fI53ts1wWwkBL+ZT91M3H73Xjb6D1zqDrgJvX/MI6hojIz\n8UImhKOJZ9t/p2n+j216dntDfQO0PMVwQGB1qOziZqQgBojyH2ghFQd1y133CjjV\nIUzoP9p4uz7bmgC7KJxP21Tb1Xh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aiTPhcVwGh\nPC9u4x+S81LI8wDM/8ByNMh1SUzVzjNxuNaMpfg5AoGBANwaIhTeTFGOchPAZ6QI\nrJci5gCoFyMJV79s1Ps3QanFDWkrsnaM0o4MVi7+HyYd/QMxcocjB850i2X/+iWo\n+Fyvy0izNXXWT1EDXUg2R29OQSD954doyZ+SGuD2O/OwBCW9ZKf6j9qjIouIM91f\nhnB6BglSo88y1x1QtFyVHUUq\n-----END PRIVATE KEY-----\n',
client_email: '[email protected]',
client_id: '104053853939127292965',
auth_uri: 'https://accounts.google.com/o/oauth2/auth',
token_uri: 'https://oauth2.googleapis.com/token',
auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs',
client_x509_cert_url:
'cert url',
'https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-k5bmt%40involvemint-tech.iam.gserviceaccount.com',
},
// I don't think this is used
scrypt: {
memCost: 14,
rounds: 8,
saltSeparator: 'Bw==',
signerKey: 'de/PQ/Gy53mgslvUgDUKDCgHJPArYqbFnGILLQZNe5My/CvqIThVL/CsndU8oudZ9lc4B7PT8w3sAar2/luQxA==',
// TODO switch
// signerKey: 'qUmhMeByCl+H+YaT4RlH/kri/BLQEkCRrySxVqrODKR8MIhwU49k3WzyZJtr1R3dgQXDPq+7LUmIs+vuFdp8Nw==',
},
};
};
Loading