Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
SupertigerDev committed Jan 22, 2025
1 parent 18eaf20 commit ad731ee
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/services/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createServerRole, deleteServerRole } from './ServerRole';
import { addToObjectIfExists } from '../common/addToObjectIfExists';
import { removeDuplicates } from '../common/utils';
import { LastOnlineStatus } from './User/User';
import { logServerDelete, logServerUserBanned, logServerUserKicked, logServerUserUnbanned } from './AuditLog';
import { logServerDelete, logServerOwnershipUpdate, logServerUserBanned, logServerUserKicked, logServerUserUnbanned } from './AuditLog';

const serverMemberWithLastOnlineDetails = Prisma.validator<Prisma.ServerMemberDefaultArgs>()({
include: { user: { select: { ...publicUserExcludeFields, lastOnlineAt: true, lastOnlineStatus: true } } },
Expand Down Expand Up @@ -1091,6 +1091,10 @@ interface TransferServerOwnershipOpts {
serverId: string;
}
export const transferServerOwnership = async (opts: TransferServerOwnershipOpts) => {
const server = await prisma.server.findFirst({ where: { id: opts.serverId }, select: { createdById: true } });
if (!server) return [null, generateError('Server not found.')] as const;
if (server.createdById === opts.newOwnerUserId) return [null, generateError('Cannot transfer ownership to yourself.')] as const;

const member = await prisma.serverMember.findUnique({
where: { userId_serverId: { userId: opts.newOwnerUserId, serverId: opts.serverId } },
select: {
Expand All @@ -1116,6 +1120,7 @@ export const transferServerOwnership = async (opts: TransferServerOwnershipOpts)
await updateServerCache(opts.serverId, { createdById: opts.newOwnerUserId });

emitServerUpdated(opts.serverId, { createdById: opts.newOwnerUserId, verified: false });
logServerOwnershipUpdate({ serverId: opts.serverId, newOwnerUserId: opts.newOwnerUserId, oldOwnerUserId: server.createdById });

return [true, null] as const;
};

0 comments on commit ad731ee

Please sign in to comment.