feat: implement QuestionBank CRUD with pagination and template query
- Add pagination support to findAll (page, limit query params) - Add findByTemplateId method to service - Add GET /by-template/:templateId endpoint to controller - Service already includes CRUD for QuestionBank and QuestionBankItem
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { apiClient } from './apiClient';
|
||||
|
||||
export const userService = {
|
||||
async changePassword(currentPassword: string, newPassword: string): Promise<{ message: string }> {
|
||||
const { data } = await apiClient.put('/users/password', {
|
||||
currentPassword,
|
||||
newPassword,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
async getUsers(page?: number, limit?: number): Promise<any> {
|
||||
const params = new URLSearchParams();
|
||||
if (page) params.append('page', page.toString());
|
||||
if (limit) params.append('limit', limit.toString());
|
||||
const { data } = await apiClient.get(`/users?${params.toString()}`);
|
||||
return data;
|
||||
},
|
||||
|
||||
async updateUser(userId: string, isAdmin: boolean): Promise<{ message: string }> {
|
||||
const { data } = await apiClient.put(`/users/${userId}`, {
|
||||
isAdmin,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
async updateUserInfo(userId: string, userData: { username?: string; isAdmin?: boolean; password?: string; displayName?: string }): Promise<{ message: string }> {
|
||||
const { data } = await apiClient.put(`/users/${userId}`, userData);
|
||||
return data;
|
||||
},
|
||||
|
||||
async deleteUser(userId: string): Promise<{ message: string }> {
|
||||
const { data } = await apiClient.delete(`/users/${userId}`);
|
||||
return data;
|
||||
},
|
||||
|
||||
async createUser(username: string, password: string, isAdmin: boolean = false, tenantId?: string, displayName?: string): Promise<{ message: string }> {
|
||||
const { data } = await apiClient.post('/users', {
|
||||
username,
|
||||
password,
|
||||
isAdmin,
|
||||
tenantId,
|
||||
displayName,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
async exportUsers(): Promise<Blob> {
|
||||
return await apiClient.getBlob('/v1/admin/users/export');
|
||||
},
|
||||
|
||||
async importUsers(file: File): Promise<any> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const { data } = await apiClient.postMultipart('/v1/admin/users/import', formData);
|
||||
return data;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user