Fix Appwrite SDK version mismatch and TypeScript errors in user-admin.ts
This commit is contained in:
parent
022f2be5e8
commit
908646637a
Binary file not shown.
16
package-lock.json
generated
16
package-lock.json
generated
@ -23,7 +23,7 @@
|
||||
"@tiptap/starter-kit": "^3.21.0",
|
||||
"@types/dompurify": "^3.0.5",
|
||||
"@types/video.js": "^7.3.58",
|
||||
"appwrite": "^18.0.0",
|
||||
"appwrite": "^17.0.0",
|
||||
"axios": "^1.18.0",
|
||||
"cheerio": "^1.2.0",
|
||||
"clsx": "^2.1.1",
|
||||
@ -34,7 +34,7 @@
|
||||
"livekit-server-sdk": "^2.16.0",
|
||||
"lucide-react": "^0.577.0",
|
||||
"next": "^16.2.6",
|
||||
"node-appwrite": "^18.0.0",
|
||||
"node-appwrite": "^17.0.0",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3",
|
||||
"string-similarity": "^4.0.4",
|
||||
@ -3235,9 +3235,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/appwrite": {
|
||||
"version": "18.0.0",
|
||||
"resolved": "https://registry.npmjs.org/appwrite/-/appwrite-18.0.0.tgz",
|
||||
"integrity": "sha512-19qs1dj6s/6MbC1Ds6PuwR7qA5p2zGs4fPVIgSItP3kiBnm5+ScA4FNkBbwrT99Kq+mcfG3LA1GRJDOkPMUkxQ==",
|
||||
"version": "17.0.0",
|
||||
"resolved": "https://registry.npmjs.org/appwrite/-/appwrite-17.0.0.tgz",
|
||||
"integrity": "sha512-R5+jMh6dVsKC5BdcO9G3wQPxqlU048zxj/Hahq2SU86XIxb0jWThQqS7MtyLUg7tz27SrwO2JvpwUrT9SOStDA==",
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/argparse": {
|
||||
@ -6976,9 +6976,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/node-appwrite": {
|
||||
"version": "18.0.0",
|
||||
"resolved": "https://registry.npmjs.org/node-appwrite/-/node-appwrite-18.0.0.tgz",
|
||||
"integrity": "sha512-2S0T17H2Gm5ZcdInCmHk8Pc8P6mKW8cDCoSBNF3PYGxbKjT51V/HY/2n6IPRqk2HrHPySmx3JIMN+V6QBprqAw==",
|
||||
"version": "17.0.0",
|
||||
"resolved": "https://registry.npmjs.org/node-appwrite/-/node-appwrite-17.0.0.tgz",
|
||||
"integrity": "sha512-5Moi5ENPnoAfU1/6CZP9K2NTuB6Nm3dSyhokno+24RDuP7czjXCdwzfeyjmyHieggbrLkN89AYSOv9W1XkCL9w==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"node-fetch-native-with-agent": "1.7.2"
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
"@tiptap/starter-kit": "^3.21.0",
|
||||
"@types/dompurify": "^3.0.5",
|
||||
"@types/video.js": "^7.3.58",
|
||||
"appwrite": "^18.0.0",
|
||||
"appwrite": "^17.0.0",
|
||||
"axios": "^1.18.0",
|
||||
"cheerio": "^1.2.0",
|
||||
"clsx": "^2.1.1",
|
||||
@ -36,7 +36,7 @@
|
||||
"livekit-server-sdk": "^2.16.0",
|
||||
"lucide-react": "^0.577.0",
|
||||
"next": "^16.2.6",
|
||||
"node-appwrite": "^18.0.0",
|
||||
"node-appwrite": "^17.0.0",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3",
|
||||
"string-similarity": "^4.0.4",
|
||||
|
||||
@ -59,10 +59,10 @@ export async function listUsersAction(page: number = 1, search: string = '') {
|
||||
Query.offset(offset)
|
||||
];
|
||||
|
||||
const response = await admin.users.list({
|
||||
const response = await admin.users.list(
|
||||
queries,
|
||||
search: search ? search.trim() : undefined
|
||||
});
|
||||
search ? search.trim() : undefined
|
||||
);
|
||||
|
||||
// Retornamos los datos limpios evitando referencias circulares o no serializables en Server Actions
|
||||
return {
|
||||
@ -95,12 +95,13 @@ export async function createUserAction(name: string, email: string, password: st
|
||||
|
||||
try {
|
||||
const admin = getAdminServices();
|
||||
const response = await admin.users.create({
|
||||
userId: ID.unique(),
|
||||
email: email.trim().toLowerCase(),
|
||||
password: password,
|
||||
name: name.trim()
|
||||
});
|
||||
const response = await admin.users.create(
|
||||
ID.unique(),
|
||||
email.trim().toLowerCase(),
|
||||
undefined, // phone
|
||||
password,
|
||||
name.trim()
|
||||
);
|
||||
|
||||
revalidatePath('/dashboard/users');
|
||||
return {
|
||||
@ -129,7 +130,7 @@ export async function updateUserAction(userId: string, name: string, email: stri
|
||||
|
||||
// 1. Actualizar Nombre (operación independiente)
|
||||
try {
|
||||
await admin.users.updateName({ userId, name: name.trim() });
|
||||
await admin.users.updateName(userId, name.trim());
|
||||
} catch (e: any) {
|
||||
const msg = e?.response?.message || e?.message || 'Error al actualizar el nombre.';
|
||||
console.error(`[updateUserAction] updateName error para ${userId}:`, msg);
|
||||
@ -138,7 +139,7 @@ export async function updateUserAction(userId: string, name: string, email: stri
|
||||
|
||||
// 2. Actualizar Email (operación independiente)
|
||||
try {
|
||||
await admin.users.updateEmail({ userId, email: email.trim().toLowerCase() });
|
||||
await admin.users.updateEmail(userId, email.trim().toLowerCase());
|
||||
} catch (e: any) {
|
||||
const msg = e?.response?.message || e?.message || 'Error al actualizar el correo.';
|
||||
console.error(`[updateUserAction] updateEmail error para ${userId}:`, msg);
|
||||
@ -150,7 +151,7 @@ export async function updateUserAction(userId: string, name: string, email: stri
|
||||
const sanitizedLabels = labels
|
||||
.map(l => l.trim().toLowerCase())
|
||||
.filter(l => /^[a-z0-9_-]+$/.test(l)); // solo alfanumérico, guiones y guiones bajos
|
||||
await admin.users.updateLabels({ userId, labels: sanitizedLabels });
|
||||
await admin.users.updateLabels(userId, sanitizedLabels);
|
||||
} catch (e: any) {
|
||||
const msg = e?.response?.message || e?.message || 'Error al actualizar etiquetas/roles.';
|
||||
console.error(`[updateUserAction] updateLabels error para ${userId}:`, msg);
|
||||
@ -185,10 +186,10 @@ export async function changeUserPasswordAction(userId: string, password: string)
|
||||
|
||||
try {
|
||||
const admin = getAdminServices();
|
||||
await admin.users.updatePassword({
|
||||
await admin.users.updatePassword(
|
||||
userId,
|
||||
password
|
||||
});
|
||||
);
|
||||
|
||||
return { success: true };
|
||||
} catch (error: any) {
|
||||
@ -214,10 +215,10 @@ export async function toggleUserStatusAction(userId: string, block: boolean) {
|
||||
// Appwrite updateStatus: status = true (activo), status = false (bloqueado)
|
||||
// Si block es true, el status nuevo debe ser false (bloqueado).
|
||||
// Si block es false, el status nuevo debe ser true (activo).
|
||||
await admin.users.updateStatus({
|
||||
await admin.users.updateStatus(
|
||||
userId,
|
||||
status: !block
|
||||
});
|
||||
!block
|
||||
);
|
||||
|
||||
revalidatePath('/dashboard/users');
|
||||
return { success: true };
|
||||
@ -240,9 +241,9 @@ export async function deleteUserAction(userId: string) {
|
||||
|
||||
try {
|
||||
const admin = getAdminServices();
|
||||
await admin.users.delete({
|
||||
await admin.users.delete(
|
||||
userId
|
||||
});
|
||||
);
|
||||
|
||||
revalidatePath('/dashboard/users');
|
||||
return { success: true };
|
||||
@ -263,9 +264,7 @@ export async function getUserStatsAction() {
|
||||
const admin = getAdminServices();
|
||||
|
||||
// Obtenemos los primeros 100 usuarios para calcular métricas (Appwrite no da un endpoint de conteo agrupado directo)
|
||||
const response = await admin.users.list({
|
||||
queries: [Query.limit(100)]
|
||||
});
|
||||
const response = await admin.users.list([Query.limit(100)]);
|
||||
|
||||
let total = response.total;
|
||||
let active = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user