index.patch.mjs 1.1 KB
import { e as eventHandler, d as getRouterParam, r as readBody, v as updateMockMemberRole } from '../../../../nitro/nitro.mjs';
import { z } from 'zod';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import '@iconify/utils';
import 'consola';

const rolePayloadSchema = z.object({
  role: z.enum(["member", "admin", "customer"])
});
const index_patch = eventHandler(async (event) => {
  const username = getRouterParam(event, "username");
  if (!username) {
    return {
      success: false,
      errorCode: "VALIDATION_ERROR",
      message: "\u7F3A\u5C11\u6210\u5458\u6807\u8BC6\u3002"
    };
  }
  const body = await readBody(event);
  const parsed = rolePayloadSchema.safeParse(body);
  if (!parsed.success) {
    return {
      success: false,
      errorCode: "VALIDATION_ERROR",
      message: "\u89D2\u8272\u53C2\u6570\u4E0D\u6B63\u786E\u3002"
    };
  }
  return updateMockMemberRole(username, parsed.data.role);
});

export { index_patch as default };
//# sourceMappingURL=index.patch.mjs.map