|
|
|
import { HttpClient, HttpParams } from "@angular/common/http";
|
|
|
|
import { Injectable } from "@angular/core";
|
|
|
|
import { Utils, AnyObject, ResponseType, UserRoleDTO, PermItemDTO, UserDTO } from "@cdk/public-api";
|
|
|
|
import { map } from "rxjs";
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: "root",
|
|
|
|
})
|
|
|
|
export class ClientApiService {
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
|
|
|
|
public accountKey = "CATERING_CLIENT_ACCOUNT";
|
|
|
|
|
|
|
|
page(v: {}, q: {}) {
|
|
|
|
return this.http.get<any>("https://jsonplaceholder.typicode.com/users", v).pipe(
|
|
|
|
map((r) => {
|
|
|
|
return {
|
|
|
|
total: 10,
|
|
|
|
content: r,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
login(v: {}) {
|
|
|
|
const params = Utils.objectToHttpParams(v);
|
|
|
|
return this.http.get<ResponseType>("/api/login", { params });
|
|
|
|
}
|
|
|
|
|
|
|
|
logout() {
|
|
|
|
return this.http.get<ResponseType>("/api/logout");
|
|
|
|
}
|
|
|
|
|
|
|
|
getRoleList() {
|
|
|
|
return this.http.get<ResponseType<UserRoleDTO[]>>("/api/role");
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteRole(roleId: string) {
|
|
|
|
const params = new HttpParams().set("roleId", roleId);
|
|
|
|
return this.http.delete<ResponseType>("/api/role", {
|
|
|
|
params,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateRole(rule: AnyObject) {
|
|
|
|
const body = Utils.objectToFormData(rule);
|
|
|
|
const method = rule["roleId"] ? "post" : "put";
|
|
|
|
return this.http[method]<ResponseType>("/api/role", body);
|
|
|
|
}
|
|
|
|
|
|
|
|
getRolePerms() {
|
|
|
|
return this.http.get<ResponseType<PermItemDTO[]>>("/api/role/item");
|
|
|
|
}
|
|
|
|
|
|
|
|
getUserList() {
|
|
|
|
return this.http.get<ResponseType<UserDTO[]>>("/api/user");
|
|
|
|
}
|
|
|
|
|
|
|
|
checkUid(uid: string) {
|
|
|
|
const params = new HttpParams().set("uid", uid);
|
|
|
|
return this.http.delete<ResponseType>("/api/user/check", {
|
|
|
|
params,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
saveUser(user: AnyObject, edit: boolean) {
|
|
|
|
const body = Utils.objectToFormData(user);
|
|
|
|
const method = edit ? "post" : "put";
|
|
|
|
return this.http[method]<ResponseType>("/api/user", body);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteUser(uid: string) {
|
|
|
|
const params = new HttpParams().set("uid", uid);
|
|
|
|
return this.http.delete<ResponseType>("/api/user", {
|
|
|
|
params,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|