This commit is contained in:
seb
2026-08-07 05:21:56 +02:00
parent 70e0a9ddc4
commit 396389457f
22 changed files with 225 additions and 242 deletions

View File

@@ -1,18 +1,18 @@
import { CREATE } from '../../sql/tax.js';
import request from '../request.js';
/**
* Creates a new tax rate.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that creates a tax rate.
*
* @example
* const fn = create(pool);
* const id = await fn(19);
* // => 1
*/
export default function create(pool) {
/**
* Creates a new tax rate.
*
* @param {number} rate - The tax rate in percent (e.g. `19`).
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<number>} The id of the created tax rate.
*
* @example
* const id = await store.tax.create(19);
* // => 1
*/
return async (rate, tx) => {
const result = await request(pool, tx)
.input('rate', rate)

View File

@@ -1,20 +1,20 @@
import getByRate from './getByRate.js';
import create from './create.js';
/**
* Returns the id of a tax rate, creating it if it does not exist.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that ensures a tax rate exists.
*
* @example
* const fn = ensure(pool);
* const id = await fn(19);
* // => 1
*/
export default function ensure(pool) {
const get = getByRate(pool);
const add = create(pool);
/**
* Returns the id of a tax rate, creating it if it does not exist.
*
* @param {number} rate - The tax rate in percent (e.g. `19`).
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<number>} The id of the tax rate.
*
* @example
* const id = await store.tax.ensure(19);
* // => 1
*/
return async (rate, tx) => {
const row = await get(rate, tx);
if (row) return row.id;

View File

@@ -1,18 +1,18 @@
import { GET_BY_RATE } from '../../sql/tax.js';
import request from '../request.js';
/**
* Returns a tax row by its rate.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that fetches a tax rate.
*
* @example
* const fn = getByRate(pool);
* const tax = await fn(19);
* // => { id, rate }
*/
export default function getByRate(pool) {
/**
* Returns a tax row by its rate.
*
* @param {number} rate - The tax rate in percent (e.g. `19`).
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{id: number, rate: number}>} The tax row, or `undefined` if not found.
*
* @example
* const tax = await store.tax.getByRate(19);
* // => { id: 1, rate: 19 }
*/
return async (rate, tx) => {
const result = await request(pool, tx)
.input('rate', rate)

View File

@@ -1,17 +1,15 @@
import { LIST } from '../../sql/tax.js';
/**
* Lists all tax rates.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that lists tax rates.
*
* @example
* const fn = list(pool);
* const taxes = await fn();
* // => [{ id, rate }]
*/
export default function list(pool) {
/**
* Lists all tax rates.
*
* @returns {Promise<Array<{id: number, rate: number}>>} All tax rate rows.
*
* @example
* const taxes = await store.tax.list();
* // => [{ id: 1, rate: 19 }]
*/
return async () => {
const result = await pool.request().query(LIST);
return result.recordset;