@overture-stack/lyric
Version:
Data Submission system
150 lines (149 loc) • 7.05 kB
TypeScript
import type { ExtractTablesWithRelations } from 'drizzle-orm';
import type { PgTransaction } from 'drizzle-orm/pg-core';
import type { PostgresJsQueryResultHKT } from 'drizzle-orm/postgres-js';
import { SQL } from 'drizzle-orm/sql';
import { type DataDiff, NewSubmittedData, SubmittedData } from '@overture-stack/lyric-data-model/models';
import { BaseDependencies } from '../config/config.js';
import { PaginationOptions, SubmittedDataResponse } from '../utils/types.js';
declare const repository: (dependencies: BaseDependencies) => {
/**
* Deletes a submitted data record by its system ID, logs the deletion, and optionally audits the deletion if auditing is enabled.
* @param params The parameters for the deletion operation.
* @param params.diff The difference between the old and new data, used for auditing
* @param params.submissionId The ID of the Submission associated with the record
* @param params.systemId The unique identifier of the record to delete
* @param params.username The name of the user performing the deletion
* @param tx The transaction to use for the operation, optional
* @returns The deleted record
*/
deleteBySystemId: (params: {
diff: DataDiff;
submissionId: number;
systemId: string;
username: string;
}, tx?: PgTransaction<PostgresJsQueryResultHKT, SubmittedData, ExtractTablesWithRelations<SubmittedData>>) => Promise<{
id: number;
data: import("@overture-stack/lectern-client").DataRecord;
dictionaryCategoryId: number;
entityName: string;
isValid: boolean;
lastValidSchemaId: number | null;
organization: string;
originalSchemaId: number;
systemId: string;
createdAt: Date | null;
createdBy: string | null;
updatedAt: Date | null;
updatedBy: string | null;
}[]>;
/**
* Save new SubmittedData in Database
* @param data A SubmittedData object to be saved
* @param tx The transaction to use for the operation, optional
* @returns The created SubmittedData
*/
save: (data: NewSubmittedData, tx?: PgTransaction<PostgresJsQueryResultHKT, SubmittedData, ExtractTablesWithRelations<SubmittedData>>) => Promise<SubmittedData>;
/**
* Returns a list of all organizations found by category ID
* @param {number} categoryId
* @returns
*/
getAllOrganizationsByCategoryId: (categoryId: number) => Promise<string[]>;
/**
* Find SubmittedData by category ID and organization
* @param {number} categoryId Category ID
* @param {string} organization Organization Name
* @returns The SubmittedData found
*/
getSubmittedDataByCategoryIdAndOrganization: (categoryId: number, organization: string) => Promise<SubmittedData[]>;
/**
* Find SubmittedData by category ID with pagination
* @param {number} categoryId Category ID
* @param {PaginationOptions} paginationOptions Pagination properties
* @param {object} filter Filter Options
* @param {string[] | undefined} filter.entityNames Array of entity names to filter
* @returns The SubmittedData found
*/
getSubmittedDataByCategoryIdPaginated: (categoryId: number, paginationOptions: PaginationOptions, filter?: {
entityNames?: string[];
}) => Promise<SubmittedDataResponse[]>;
/**
* Find SubmittedData by category ID and Organization with pagination
* @param {number} categoryId Category ID
* @param {string} organization Organization Name
* @param {PaginationOptions} paginationOptions Pagination properties
* @param {object} filter Filter Options
* @param {SQL | undefined} filter.sql SQL command to filter
* @param {string[] | undefined} filter.entityNames Array of entity names to filter
* @returns The SubmittedData found
*/
getSubmittedDataByCategoryIdAndOrganizationPaginated: (categoryId: number, organization: string, paginationOptions: PaginationOptions, filter?: {
sql?: SQL;
entityNames?: string[];
}) => Promise<SubmittedDataResponse[]>;
/**
* Counts the total of records found by Category and Organization
* @param {number} categoryId Category ID
* @param {string} organization Organization Name
* @param {object} filter Filter Options
* @param {SQL | undefined} filter.sql SQL command to filter
* @param {string[] | undefined} filter.entityNames Array of entity names to filter
* @returns Total number of recourds
*/
getTotalRecordsByCategoryIdAndOrganization: (categoryId: number, organization: string, filter?: {
sql?: SQL;
entityNames?: string[];
}) => Promise<number>;
/**
* Counts the total of records found by Category
* @param {number} categoryId Category ID
* @param {object} filter Filter options
* @param {SQL | undefined} filter.sql SQL command
* @param {string[] | undefined} filter.entityNames Array of entity names to filter
* @returns Total number of recourds
*/
getTotalRecordsByCategoryId: (categoryId: number, filter?: {
sql?: SQL;
entityNames?: string[];
}) => Promise<number>;
/**
* Update a SubmittedData record in database
* @param submittedDataId Submitted Data ID
* @param dataDiff Difference before and after the updata
* @param newData Set fields to update
* @param oldIsValid Previous isValid value
* @param submissionId Submission ID
* @param tx The transaction to use for the operation, optional
* @returns An updated record
*/
update: ({ submittedDataId, dataDiff, newData, oldIsValid, submissionId, }: {
submittedDataId: number;
dataDiff: DataDiff;
newData: Partial<SubmittedData>;
oldIsValid: boolean;
submissionId: number;
}, tx?: PgTransaction<PostgresJsQueryResultHKT, SubmittedData, ExtractTablesWithRelations<SubmittedData>>) => Promise<SubmittedData>;
/**
* Query to retrieve an unique SubmittedData record searching by System ID
* Returns a SubmittedData record if found. Otherwise returns undefined
* @param {string} systemId
* @returns {Promise<SubmittedData | undefined>}
*/
getSubmittedDataBySystemId: (systemId: string) => Promise<SubmittedData | undefined>;
/**
* Query to retrieve submitted data filtered by JSONB field on an organization
* Returns an array of SubmittedData records found or an empty array if there are no matching records
* @param {string} organization
* @param {Object} filterData
* @param {string} filterData.entityName
* @param {string} filterData.dataField
* @param {string | undefined} filterData.dataValue
* @returns {Promise<SubmittedData[]>}
*/
getSubmittedDataFiltered: (organization: string, filterData: {
entityName: string;
dataField: string;
dataValue: string | undefined;
}[]) => Promise<SubmittedData[]>;
};
export default repository;