misc_pterodactyl-panel/resources/scripts/api/admin/users/createUser.ts

19 lines
660 B
TypeScript
Raw Normal View History

2021-01-06 23:38:39 +00:00
import http from '@/api/http';
import { User, rawDataToUser } from '@/api/admin/users/getUsers';
import { Values } from '@/api/admin/users/updateUser';
2021-01-06 23:38:39 +00:00
export type { Values };
export default (values: Values, include: string[] = []): Promise<User> => {
const data = {};
Object.keys(values).forEach(k => {
// @ts-ignore
data[k.replace(/[A-Z]/g, l => `_${l.toLowerCase()}`)] = values[k];
});
2021-01-06 23:38:39 +00:00
return new Promise((resolve, reject) => {
http.post('/api/application/users', data, { params: { include: include.join(',') } })
2021-01-06 23:38:39 +00:00
.then(({ data }) => resolve(rawDataToUser(data)))
.catch(reject);
});
};