Skip to content

Commit

Permalink
app (user) networw create: reuse logic to reconnect connections
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaglivo committed Jun 3, 2023
1 parent bd28eb7 commit 2dec053
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/network/connection/changeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createServerActionSuccessResponse } from '@/lib/errors/server';
import { getServerSession } from '../../auth/session';
import prisma from '../../prisma';

async function changeConnectionState(connectionId: string, newActiveState: boolean) {
export async function changeConnectionState(connectionId: string, newActiveState: boolean) {
const { user } = await getServerSession();
await prisma.networkConnection.update({
where: {
Expand Down
6 changes: 2 additions & 4 deletions src/lib/network/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { z } from 'zod';
import { getServerSession } from '../auth/session';
import { createServerActionErrorResponse, createServerActionSuccessResponse, unknownServerError } from '../errors/server';
import prisma from '../prisma';
import { changeConnectionState } from './connection/changeState';

const errors: { [errorId: string]: { type: string, message: string } } = {
NoConnectionWithYourself: { type: 'NoConnectionWithYourself', message: 'It is not possible to create a connection with yourself' },
Expand Down Expand Up @@ -43,10 +44,7 @@ export const createConnectionAction = zact(z.object({
}

if (existingConnection && !existingConnection.active) {
await prisma.networkConnection.update({
where: { id: existingConnection.id },
data: { active: true }
});
await changeConnectionState(existingConnection.id, true);
} else {
await prisma.networkConnection.create({
data: { requesterId: user.id, acceptorId: acceptorUser.id }
Expand Down

0 comments on commit 2dec053

Please sign in to comment.