Feat: map client to interface (#1886)

map client to interface
This commit is contained in:
Bernd Storath
2025-05-28 11:58:33 +02:00
committed by GitHub
parent 7e1aa5807d
commit a8aa85bdaa
7 changed files with 19 additions and 7 deletions
@@ -1,7 +1,7 @@
import { sql, relations } from 'drizzle-orm';
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { oneTimeLink, user } from '../../schema';
import { oneTimeLink, user, wgInterface } from '../../schema';
/** null means use value from userConfig */
@@ -13,6 +13,12 @@ export const client = sqliteTable('clients_table', {
onDelete: 'restrict',
onUpdate: 'cascade',
}),
interfaceId: text('interface_id')
.notNull()
.references(() => wgInterface.name, {
onDelete: 'cascade',
onUpdate: 'cascade',
}),
name: text().notNull(),
ipv4Address: text('ipv4_address').notNull().unique(),
ipv6Address: text('ipv6_address').notNull().unique(),
@@ -51,4 +57,8 @@ export const clientsRelations = relations(client, ({ one }) => ({
fields: [client.userId],
references: [user.id],
}),
interface: one(wgInterface, {
fields: [client.interfaceId],
references: [wgInterface.name],
}),
}));
@@ -108,6 +108,7 @@ export class ClientService {
name,
// TODO: properly assign user id
userId: 1,
interfaceId: 'wg0',
expiresAt,
privateKey,
publicKey,
@@ -171,6 +172,7 @@ export class ClientService {
.values({
name,
userId: 1,
interfaceId: 'wg0',
privateKey,
publicKey,
preSharedKey,
@@ -14,7 +14,7 @@ export type CreateClientType = Omit<
export type UpdateClientType = Omit<
CreateClientType,
'privateKey' | 'publicKey' | 'preSharedKey' | 'userId'
'privateKey' | 'publicKey' | 'preSharedKey' | 'userId' | 'interfaceId'
>;
const name = z