Skip to content
Merged
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 src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const routes: Routes = [
import('./features/organization/organization.module').then(
(m) => m.OrganizationModule
),
data: { roles: ['ROLE_ADMIN'] },
data: { roles: ['ADMIN'] },
canActivate: [RoleGuard],
},
],
Expand Down
8 changes: 4 additions & 4 deletions src/app/core/guards/router-protected/role.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export class RoleGuard implements CanActivate {
| Observable<boolean | UrlTree>
| Promise<boolean | UrlTree> {
const expectedRoles = next.data['roles'] as string[]; // lấy roles từ route
const userRole = decodeJWT(localStorage.getItem('token') ?? '')?.payload
.scope;
const userRoles = decodeJWT(localStorage.getItem('token') ?? '')?.payload
.roles;

if (!expectedRoles || expectedRoles.length === 0) {
return true; // không yêu cầu role -> cho vào
}

if (expectedRoles.includes(userRole)) {
if (userRoles && userRoles.some((role) => expectedRoles.includes(role))) {
return true;
} else {
sendNotification(
Expand All @@ -60,7 +60,7 @@ export class RoleGuard implements CanActivate {
import('./features/service-payment/service-and-payment.module').then(
(m) => m.ServiceAndPaymentModule
),
data: { roles: ['ROLE_ADMIN'] },
data: { roles: ['ADMIN'] },
canActivate: [RoleGuard],
},

Expand Down
68 changes: 68 additions & 0 deletions src/app/core/models/organization.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { IPaginationResponse } from './api-response';
import { UserBasicInfo } from './exercise.model';

export type OrganizationInfo = {
id: string;
name: string;
Expand All @@ -9,3 +12,68 @@ export type OrganizationInfo = {
logoUrl: string | null;
status: number; // 0 Active, 1 Inactive, 2 Pending
};

export type CreateOrgRequest = {
name: string;
description: string;
email: string;
phone: string;
address: string;
status: string;
logo: File;
};

//Search response
export type MemberResponse = {
user: UserBasicInfo;
role: string;
active: boolean;
};

export type BlockResponse = {
id: string;
orgId: string;
name: string;
code: string;
description: string;
createdAt: string;
updatedAt: string;
members: IPaginationResponse<MemberResponse[]>;
};

export type OrganizationResponse = {
id: string;
name: string;
description: string;
logoUrl: string | null;
email: string;
phone: string;
address: string;
status: string;
createdAt: string;
updatedAt: string;
blocks: IPaginationResponse<BlockResponse[]>;
};

//filter
export type FilterOrgs = {
q?: string;
status?: string;
includeBlocks?: boolean;
blocksPage?: number;
blocksSize?: number;
membersPage?: number;
membersSize?: number;
activeOnlyMembers?: boolean;
includeUnassigned?: boolean;
};

//edit basic info
export type EditOrgRequest = {
description?: string;
email?: string;
phone?: string;
address?: string;
status?: string;
logo?: File;
};
11 changes: 11 additions & 0 deletions src/app/core/models/post.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface PostCardInfo {
downvote: number;
public: boolean;
allowComment: boolean;
isSaved?: boolean;
}

export interface Tag {
Expand Down Expand Up @@ -164,3 +165,13 @@ export interface PostDataCreateRequest {
isLectureVideo: boolean;
isTextbook: boolean;
}

export type SavedPostResponse = {
id: string;
saveAt: string;
post: {
id: string;
postId: string;
title: string;
};
};
16 changes: 9 additions & 7 deletions src/app/core/router-manager/horizontal-menu.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { SidebarItem } from '../models/data-handle';

export function getNavHorizontalItems(role: string): SidebarItem[] {
const auth_lv1 = ['ROLE_ADMIN', 'ROLE_TEACHER'];
const auth_lv2 = ['ROLE_ADMIN'];
export function getNavHorizontalItems(roles: string[]): SidebarItem[] {
const auth_lv1 = ['ADMIN', 'TEACHER'];
const auth_lv2 = ['ADMIN'];
console.log(roles);

return [
{
Expand All @@ -28,20 +29,21 @@ export function getNavHorizontalItems(role: string): SidebarItem[] {
path: 'conversations/chat',
label: 'Tin nhắn',
icon: 'fas fa-comments',
isVisible: !(roles.length !== 0),
},
{
id: 'statistics',
path: '/statistics',
label: 'Thống kê',
icon: 'fas fa-chart-bar',
isVisible: !auth_lv2.includes(role),
isVisible: !roles.includes(auth_lv2[0]),
},
{
id: 'management',
path: 'management/admin',
label: 'Admin quản lý',
icon: 'fas fa-user-shield',
isVisible: !auth_lv2.includes(role),
isVisible: !roles.includes(auth_lv2[0]),
},
{
id: 'payment',
Expand All @@ -51,10 +53,10 @@ export function getNavHorizontalItems(role: string): SidebarItem[] {
},
{
id: 'organization ',
path: '/organization/list',
path: '/organization/orgs-list',
label: 'Tổ chức',
icon: 'fa-solid fa-building-user',
isVisible: !auth_lv2.includes(role),
isVisible: !roles.includes(auth_lv2[0]),
},
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { SidebarItem } from '../../models/data-handle';

export function sidebarOrgRouter(roles: string[]): SidebarItem[] {
return [
{
id: 'list-orgs',
path: '/organization/orgs-list',
label: 'Nạp tiền',
icon: 'fa-solid fa-tasks',
},
];
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { SidebarItem } from '../../models/data-handle';

export function sidebarPosts(role: string): SidebarItem[] {
export function sidebarPosts(roles: string[]): SidebarItem[] {
return [
{
id: 'populat',
path: 'exercise/popular',
label: 'Bài viết phổ biến',
id: 'saved-posts',
path: '/post-features/saved-posts-list',
label: 'Bài viết đã lưu',
icon: 'fas fa-file-alt',
},
{
id: 'exercise',
path: '/post-management/post-list',
path: '/post-features/post-list',
label: 'Quản lý bài viết',
icon: 'fas fa-tasks',
},
Expand Down
59 changes: 59 additions & 0 deletions src/app/core/services/api-service/organization.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Injectable } from '@angular/core';
import { ApiMethod } from '../config-service/api.methods';
import { ApiResponse, IPaginationResponse } from '../../models/api-response';
import { API_CONFIG } from '../config-service/api.enpoints';
import {
CreateOrgRequest,
EditOrgRequest,
FilterOrgs,
OrganizationInfo,
OrganizationResponse,
} from '../../models/organization.model';
import { PostResponse } from '../../models/post.models';

@Injectable({
providedIn: 'root',
})
export class OrganizationService {
constructor(private api: ApiMethod) {}

createOrg(dataCreate: CreateOrgRequest) {
const { logo, ...otherData } = dataCreate;
return this.api.postWithFormData<ApiResponse<null>>(
API_CONFIG.ENDPOINTS.POST.CREATE_ORGANIZATION,
otherData, // các field string
{ logo }
);
}

searchOrgsFilter(page: number, size: number, search?: FilterOrgs) {
const endpoint = API_CONFIG.ENDPOINTS.GET.SEARCH_ORGS_FILTER(
page,
size,
search ? search : null
);

return this.api.get<
ApiResponse<IPaginationResponse<OrganizationResponse[]>>
>(endpoint);
}

getOrgDetails(orgId: string) {
return this.api.get<ApiResponse<OrganizationInfo>>(
API_CONFIG.ENDPOINTS.GET.GET_ORG_DETAILS_BY_ID(orgId)
);
}

editOrg(orgId: string, data: EditOrgRequest) {
return this.api.put<ApiResponse<null>>(
API_CONFIG.ENDPOINTS.PUT.EDIT_ORG(orgId),
data
);
}

deleteOrg(orgId: string) {
return this.api.delete<ApiResponse<null>>(
API_CONFIG.ENDPOINTS.DELETE.DELETE_ORG(orgId)
);
}
}
49 changes: 0 additions & 49 deletions src/app/core/services/api-service/playground.service.ts

This file was deleted.

20 changes: 20 additions & 0 deletions src/app/core/services/api-service/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CreatePostRequest,
postData,
PostResponse,
SavedPostResponse,
} from '../../models/post.models';

@Injectable({
Expand Down Expand Up @@ -142,4 +143,23 @@ export class PostService {
API_CONFIG.ENDPOINTS.DELETE.DELETE_POST(id)
);
}

savePost(postId: string) {
return this.api.post<ApiResponse<null>>(
API_CONFIG.ENDPOINTS.POST.SAVE_POST(postId),
null
);
}

unSavePost(postId: string) {
return this.api.delete<ApiResponse<null>>(
API_CONFIG.ENDPOINTS.POST.SAVE_POST(postId)
);
}

getSavedPosts(page: number, size: number) {
return this.api.get<ApiResponse<IPaginationResponse<SavedPostResponse[]>>>(
API_CONFIG.ENDPOINTS.GET.GET_SAVED_POSTS(page, size)
);
}
}
Loading