Skip to content

Commit a40e917

Browse files
authored
Merge pull request #147 from CapstoneProjectCMC/feature/sap-service-and-payment
create block details and stuff
2 parents 31214f4 + 1e604f9 commit a40e917

33 files changed

+1067
-696
lines changed

src/app/core/guards/router-protected/role.guard.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ import { Observable } from 'rxjs';
1111
import { decodeJWT } from '../../../shared/utils/stringProcess';
1212
import { sendNotification } from '../../../shared/utils/notification';
1313
import { Store } from '@ngrx/store';
14+
import { Location } from '@angular/common';
1415

1516
@Injectable({
1617
providedIn: 'root',
1718
})
1819
export class RoleGuard implements CanActivate {
19-
constructor(private router: Router, private store: Store) {}
20+
constructor(
21+
private router: Router,
22+
private store: Store,
23+
private location: Location
24+
) {}
2025

2126
canActivate(
2227
next: ActivatedRouteSnapshot,
@@ -44,7 +49,9 @@ export class RoleGuard implements CanActivate {
4449
'warning'
4550
);
4651
// nếu không đủ quyền, redirect sang trang 403 hoặc trang chủ
47-
return this.router.createUrlTree(['/']);
52+
this.location.back();
53+
// return this.router.createUrlTree(['/']); // về trang chủ
54+
return false;
4855
}
4956
}
5057
}

src/app/core/models/organization.model.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ export type EditOrgRequest = {
7474
email?: string;
7575
phone?: string;
7676
address?: string;
77-
status?: string;
77+
status?: number;
7878
logo?: File;
7979
};
80+
81+
export type ParamGetAllBlockOfOrg = {
82+
blocksPage?: number;
83+
blocksSize?: number;
84+
membersPage?: number;
85+
membersSize?: number;
86+
activeOnlyMembers?: boolean;
87+
includeUnassigned?: boolean;
88+
};

src/app/core/router-manager/vetical-menu-dynamic/exercise-vetical-menu.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { SidebarItem } from '../../models/data-handle';
22

3-
export function sidebarExercises(role: string): SidebarItem[] {
3+
export function sidebarExercises(roles: string[]): SidebarItem[] {
44
return [
5-
// {
6-
// id: 'exam',
7-
// path: 'exercise/exam-list',
8-
// label: 'Bài thi',
9-
// icon: 'fas fa-file-alt',
10-
// },
115
{
126
id: 'exercise',
137
path: '/exercise/exercise-layout/my-assign-list',

src/app/core/router-manager/vetical-menu-dynamic/org-vertical-menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function sidebarOrgRouter(roles: string[]): SidebarItem[] {
55
{
66
id: 'list-orgs',
77
path: '/organization/orgs-list',
8-
label: 'Nạp tiền',
8+
label: 'Danh sách tổ chức',
99
icon: 'fa-solid fa-tasks',
1010
},
1111
];

src/app/core/router-manager/vetical-menu-dynamic/payment-vertical-menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function sidebarPaymentRouter(role: string): SidebarItem[] {
1717
{
1818
id: 'purchase-history',
1919
path: '/service-and-payment/purchase-history',
20-
label: 'Lịch sử giao dịch',
20+
label: 'Lịch sử đã mua',
2121
icon: 'fa-solid fa-cart-shopping',
2222
},
2323
];

src/app/core/services/api-service/organization.service.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { ApiMethod } from '../config-service/api.methods';
33
import { ApiResponse, IPaginationResponse } from '../../models/api-response';
44
import { API_CONFIG } from '../config-service/api.enpoints';
55
import {
6+
BlockResponse,
67
CreateOrgRequest,
78
EditOrgRequest,
89
FilterOrgs,
910
OrganizationInfo,
1011
OrganizationResponse,
12+
ParamGetAllBlockOfOrg,
1113
} from '../../models/organization.model';
1214
import { PostResponse } from '../../models/post.models';
1315

@@ -45,9 +47,12 @@ export class OrganizationService {
4547
}
4648

4749
editOrg(orgId: string, data: EditOrgRequest) {
48-
return this.api.put<ApiResponse<null>>(
49-
API_CONFIG.ENDPOINTS.PUT.EDIT_ORG(orgId),
50-
data
50+
const { logo, ...otherData } = data;
51+
52+
return this.api.patchWithFormData<ApiResponse<null>>(
53+
API_CONFIG.ENDPOINTS.PATCH.EDIT_ORG(orgId),
54+
otherData,
55+
logo
5156
);
5257
}
5358

@@ -56,4 +61,45 @@ export class OrganizationService {
5661
API_CONFIG.ENDPOINTS.DELETE.DELETE_ORG(orgId)
5762
);
5863
}
64+
65+
createBlockInOrg(
66+
orgId: string,
67+
data: { name: string; code: string; description: string }
68+
) {
69+
return this.api.post<ApiResponse<null>>(
70+
API_CONFIG.ENDPOINTS.POST.CREATE_BLOCK_IN_ORG(orgId),
71+
data
72+
);
73+
}
74+
75+
getAllBlockOfOrg(orgId: string, params: ParamGetAllBlockOfOrg) {
76+
return this.api.get<ApiResponse<IPaginationResponse<BlockResponse[]>>>(
77+
API_CONFIG.ENDPOINTS.GET.SEACH_ALL_BLOCKS(orgId, params)
78+
);
79+
}
80+
81+
updateBlock(
82+
id: string,
83+
data: { name?: string; code?: string; description?: string }
84+
) {
85+
return this.api.patch<ApiResponse<null>>(
86+
API_CONFIG.ENDPOINTS.PATCH.EDIT_BLOCK(id),
87+
data
88+
);
89+
}
90+
91+
deleteBlock(id: string) {
92+
return this.api.delete<ApiResponse<null>>(
93+
API_CONFIG.ENDPOINTS.DELETE.DELETE_BLOCK(id)
94+
);
95+
}
96+
97+
getBlockDetails(
98+
blockId: string,
99+
data: { membersPage: number; membersSize: number; activeOnly: boolean }
100+
) {
101+
return this.api.get<ApiResponse<BlockResponse>>(
102+
API_CONFIG.ENDPOINTS.GET.GET_BLOCK_DETAILS(blockId, data)
103+
);
104+
}
59105
}

src/app/core/services/config-service/api.enpoints.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { environment } from '../../../../environments/environment';
22
import { EnumType } from '../../models/data-handle';
3-
import { FilterOrgs } from '../../models/organization.model';
3+
import {
4+
FilterOrgs,
5+
ParamGetAllBlockOfOrg,
6+
} from '../../models/organization.model';
47
import { SearchingUser } from '../../models/user.models';
58

69
export const version = '/v1';
@@ -168,8 +171,35 @@ export const API_CONFIG = {
168171

169172
return query;
170173
},
171-
GET_ORG_DETAILS_BY_ID: (orgId: string) =>
172-
`/org/api/Organization/${orgId}`,
174+
GET_ORG_DETAILS_BY_ID: (orgId: string) => `/org/organization/${orgId}`,
175+
SEACH_ALL_BLOCKS: (orgId: string, params: ParamGetAllBlockOfOrg) => {
176+
let query = `/org/${orgId}/blocks?`;
177+
if (
178+
params?.blocksPage !== undefined &&
179+
params?.blocksSize !== undefined
180+
) {
181+
query += `blocksPage=${params.blocksPage}&blocksSize=${params.blocksSize}&`;
182+
}
183+
if (
184+
params?.membersPage !== undefined &&
185+
params?.membersSize !== undefined
186+
) {
187+
query += `membersPage=${params.membersPage}&membersSize=${params.membersSize}&`;
188+
}
189+
if (params?.activeOnlyMembers !== undefined) {
190+
query += `activeOnlyMembers=${params.activeOnlyMembers}&`;
191+
}
192+
if (params?.includeUnassigned !== undefined) {
193+
query += `includeUnassigned=${params.includeUnassigned}&`;
194+
}
195+
// Xóa dấu `&` hoặc `?` cuối cùng nếu có
196+
return query.replace(/[&?]$/, '');
197+
},
198+
GET_BLOCK_DETAILS: (
199+
blockId: string,
200+
data: { membersPage: number; membersSize: number; activeOnly: boolean }
201+
) =>
202+
`/org/block/${blockId}?membersPage=${data.membersPage}&membersSize=${data.membersSize}&activeOnly=${data.activeOnly}`,
173203
},
174204
POST: {
175205
LOGIN: '/identity/auth/login',
@@ -236,10 +266,10 @@ export const API_CONFIG = {
236266
TOPUP: '/payment/topup',
237267
PURCHASE: '/payment/purchase',
238268
CREATE_ORGANIZATION: '/org/organization',
269+
CREATE_BLOCK_IN_ORG: (orgId: string) => `/org/${orgId}/block`,
239270
},
240271
PUT: {
241272
EDIT_FILE: (id: string) => `/file/api/FileDocument/edit/${id}`,
242-
EDIT_ORG: (id: string) => `/org/api/Organization/${id}`,
243273
},
244274
PATCH: {
245275
UPDATE_EXERCISE: (exerciseId: string) =>
@@ -257,6 +287,8 @@ export const API_CONFIG = {
257287
`/submission/coding/exercise/${exerciseId}/coding-detail`,
258288
RENAME_THREAD: (threadId: string) => `/ai/chat/thread/${threadId}`,
259289
CHANGE_MY_PASSWORD: `/identity/user/password`,
290+
EDIT_ORG: (id: string) => `/org/organization/${id}`,
291+
EDIT_BLOCK: (blockId: string) => `/org/block/${blockId}`,
260292
},
261293
DELETE: {
262294
DELETE_QUESTION: (exerciseId: string, questionId: string) =>
@@ -277,6 +309,7 @@ export const API_CONFIG = {
277309
UNSAVE_EXERCISE: (exerciseId: string) =>
278310
`/profile/exercise/${exerciseId}/save`,
279311
DELETE_ORG: (orgId: string) => `/org/organization/${orgId}`,
312+
DELETE_BLOCK: (blockId: string) => `/org/block/${blockId}`,
280313
},
281314
},
282315
HEADERS: {

src/app/features/conversation-chat/pages/chat/chat.component.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,6 @@ <h3>{{ selectedConversation.conversationName }}</h3>
177177
</div>
178178

179179
<form class="message-form" (ngSubmit)="handleSendMessage()">
180-
<input
181-
type="text"
182-
class="message-input"
183-
placeholder="Type a message"
184-
[(ngModel)]="message"
185-
name="message"
186-
autocomplete="off"
187-
/>
188180
<button
189181
class="btn btn--icon btn--primary"
190182
type="submit"
@@ -206,6 +198,14 @@ <h3>{{ selectedConversation.conversationName }}</h3>
206198
<polygon points="22 2 15 22 11 13 2 9 22 2"></polygon>
207199
</svg>
208200
</button>
201+
<input
202+
type="text"
203+
class="message-input"
204+
placeholder="Type a message"
205+
[(ngModel)]="message"
206+
name="message"
207+
autocomplete="off"
208+
/>
209209
</form>
210210
</ng-container>
211211

src/app/features/excercise/exercise-layout/exercise-layout.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export class ExerciseLayoutComponent implements OnInit, OnDestroy {
3030
private routerSubscription!: Subscription;
3131

3232
constructor(private router: Router) {
33-
const role = decodeJWT(localStorage.getItem('token') ?? '')?.payload.scope;
34-
this.sidebarData = sidebarExercises(role);
33+
const roles = decodeJWT(localStorage.getItem('token') ?? '')?.payload.roles;
34+
this.sidebarData = sidebarExercises(roles);
3535
}
3636

3737
ngOnInit() {

src/app/features/excercise/exercise-pages/assign-exercise/assign-exercise.component.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
2+
import { ActivatedRoute, Router } from '@angular/router';
33
import {
44
SearchUserProfileResponse,
55
User,
@@ -18,7 +18,6 @@ import {
1818
import { forkJoin } from 'rxjs/internal/observable/forkJoin';
1919
import { catchError } from 'rxjs/internal/operators/catchError';
2020
import { of } from 'rxjs/internal/observable/of';
21-
import { Subscription } from 'rxjs/internal/Subscription';
2221
import {
2322
AssignedStudentsListResponse,
2423
MySubmissionsHistoryResponse,
@@ -33,10 +32,6 @@ import { CodingService } from '../../../../core/services/api-service/coding.serv
3332
})
3433
export class AssignExerciseComponent implements OnInit {
3534
private debounceTimer: ReturnType<typeof setTimeout> | null = null;
36-
private checkTypeExercise: string[] = [
37-
'/assign-exercise-code',
38-
'/assign-exercise-quiz',
39-
];
4035

4136
avatarUrlDefault: string = avatarUrlDefault;
4237
exerciseTypeCall: MySubmissionsHistoryResponse['exerciseType'] = 'QUIZ';

0 commit comments

Comments
 (0)