mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 12:53:32 +00:00
refactor: migrate custom fields to transactions
refactor: extract functions to api domain refactor: strict custom field parsing refactor: remove rundown cache utilities refactor: directory restructure
This commit is contained in:
committed by
Carlos Valente
parent
b1d23467a2
commit
62c8319d70
@@ -1,21 +0,0 @@
|
||||
import type { CustomFields } from 'ontime-types';
|
||||
|
||||
import { isAlphanumericWithSpace } from '../regex-utils/isAlphanumeric.js';
|
||||
|
||||
/**
|
||||
* @description Transforms a Custom field label into a valid key or returns null if not possible
|
||||
*/
|
||||
export const customFieldLabelToKey = (label: string): string | null => {
|
||||
if (isAlphanumericWithSpace(label)) {
|
||||
return label.trim().replaceAll(' ', '_');
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const customKeyFromLabel = (label: string, fields: CustomFields): string | null => {
|
||||
const maybeMatchingKey = Object.keys(fields).find((key) => fields[key].label === label);
|
||||
if (maybeMatchingKey) {
|
||||
return maybeMatchingKey;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { CustomFields } from 'ontime-types';
|
||||
|
||||
/**
|
||||
* Transforms an alphanumeric label with spaces into a valid key
|
||||
*/
|
||||
export function customFieldLabelToKey(label: string): string {
|
||||
return label.trim().replaceAll(' ', '_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an object key in the CustomFields object that matches the given label
|
||||
*/
|
||||
export function customKeyFromLabel(label: string, fields: CustomFields): string | null {
|
||||
const maybeMatchingKey = Object.keys(fields).find((key) => fields[key].label === label);
|
||||
if (maybeMatchingKey) {
|
||||
return maybeMatchingKey;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { ProjectRundowns, Rundown } from 'ontime-types';
|
||||
|
||||
/**
|
||||
* Gets the first rundown in the project
|
||||
* We know that the project has at least one rundown
|
||||
*/
|
||||
export function getFirstRundown(rundowns: ProjectRundowns): Rundown {
|
||||
const keys = Object.keys(rundowns);
|
||||
if (keys.length === 0) {
|
||||
throw new Error('No rundowns found in project');
|
||||
}
|
||||
|
||||
const firstKey = keys[0];
|
||||
return rundowns[firstKey];
|
||||
}
|
||||
Reference in New Issue
Block a user