Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dns update workflow #289

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 0 additions & 136 deletions app/lib/domains.server.ts

This file was deleted.

55 changes: 41 additions & 14 deletions app/models/record.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Record } from '@prisma/client';

import { RecordStatus } from '@prisma/client';
import { prisma } from '~/db.server';
import dayjs from 'dayjs';

import type { Record } from '@prisma/client';
export type { Record } from '@prisma/client';

export async function getRecordsByUsername(username: Record['username']) {
Expand All @@ -12,44 +13,70 @@ export async function getRecordById(id: Record['id']) {
return prisma.record.findUnique({ where: { id } });
}

export async function createRecord(
data: Pick<Record, 'username' | 'name' | 'type' | 'value' | 'status'>
) {
export async function createRecord(data: Pick<Record, 'username' | 'type' | 'name' | 'value'>) {
// Set expiration date 6 months from now
const expiresAt = new Date();
expiresAt.setMonth(expiresAt.getMonth() + 6);
const expiresAt = dayjs().set('month', 6).toDate();
const status = RecordStatus.pending;

return prisma.record.create({ data: { ...data, expiresAt } });
return prisma.record.create({ data: { ...data, expiresAt, status } });
}

export async function updateRecordById(
id: Record['id'],
username?: Record['username'],
name?: Record['name'],
type?: Record['type'],
name?: Record['name'],
value?: Record['value'],
status?: Record['status'],
username?: Record['username'],
description?: Record['description'],
course?: Record['course'],
ports?: Record['ports'],
expiresAt?: Record['expiresAt'],
status?: Record['status']
expiresAt?: Record['expiresAt']
) {
return prisma.record.update({
where: { id },
data: {
username,
name,
type,
name,
value,
status,
username,
description,
course,
ports,
expiresAt,
},
});
}

export async function updateRecordStatusById(id: Record['id'], status: Record['status']) {
const expireToSet = dayjs().set('month', 6).toDate();

return prisma.record.update({
where: {
id,
},
data: {
status,
expiresAt: status === RecordStatus.active ? expireToSet : undefined,
},
});
}

export async function doesRecordExist(data: Pick<Record, 'username' | 'type' | 'name' | 'value'>) {
const { username, type, name, value } = data;
const count = await prisma.record.count({
where: {
username,
type,
name,
value,
},
});

return count > 0;
}

export async function deleteRecordById(id: Record['id']) {
return prisma.record.delete({ where: { id } });
}
148 changes: 0 additions & 148 deletions app/queues/dns/create-record-worker.server.ts

This file was deleted.

Loading