Demo: a static copy of one review, without the review service. Reviewed marks apply in this tab until it reloads, and view settings stay in this browser. Comments, decisions, and publication need an installed mcp-review. About mcp-review · Get early access

Move the storefront API to typed handlers

Every endpoint of the storefront API moves from an Express callback to a typed handler, so validation, access checks, errors and logging happen in one pipeline instead of in 224 copies.

What changes

  • A new pipeline in src/http/ matches the route, checks access, validates the path, query and body against a schema, runs the handler, and writes one JSON answer.
  • Each of the 32 resources gets its schemas in src/schemas/, and its 7 handlers move to the new form.
  • The handler tests move from Mocha and supertest to node:test against the handlers themselves.
  • The tax rate table moves into the repository, so checkout no longer calls the finance service for each order.
  • The scheduled jobs import the shared @storefront/logger package. That change is mechanical.
flowchart LR
  Request[request] --> Pipeline[http pipeline]
  Pipeline --> Schemas[schemas]
  Pipeline --> Handlers[typed handlers]
  Handlers --> DB[(database)]

How to review

Read Typed request pipeline first: every other section depends on it. The handler sections repeat one pattern per resource, so a few files of each show it; the tests and the API reference follow the handlers.

Coverage

Presentation
All 1051 selected changes are placed. 1050 in groups · 0 unbucketed · 1 generated · 0 without a text diff
Explanations
8 of 8 groups have an explanation.
Agent analysis
Reading the analysis status…
Human review
0 of 1051 hunks are marked reviewed.

Typed request pipeline

The pipeline is the reason for this change. A handler now declares its method, path, access and schemas, and runHandler does the rest in a fixed order.

Order of the checks

  1. Access: a user or admin endpoint without a session answers 401, and a non-admin on an admin endpoint 403.
  2. Validation: the path, the query and the body each pass their schema, or the answer is 422 with the problems.
  3. The handler runs. An HttpError becomes its status and code; any other error becomes a 500 that quotes the request ID.

What to check

  • readJson caps the body at 1 MiB and answers 413 above it.
  • A 204 answer writes no body.
  • app.ts keeps listen, so the deployment does not change.
  • src/handlers/index.ts replaces the Express route table and lists each literal path before the path with a parameter.
docs/handlers.md
+23 -0
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Typed handlers
Every endpoint of the storefront API is a typed handler. A handler names its method, its path, who may call it, and the schemas of its path, query and body. The pipeline does everything else.
```mermaid
flowchart LR
Request[request] --> Router[router]
Router --> Access{access}
Access -- denied --> Error[JSON error]
Access -- allowed --> Validate{schemas}
Validate -- invalid --> Error
Validate -- valid --> Run[handler.run]
Run --> Answer[JSON answer]
Run -- HttpError --> Error
```
## Write a handler
1. Add the schemas of the request to `src/schemas/<resource>.ts`.
2. Export the handler from `src/handlers/<resource>/<action>.ts` with `handler({ ... })`.
3. Add it to `src/handlers/index.ts`.
Throw an `HttpError` for an answer that the caller can act on, such as a 404 or a 409. Any other error becomes a 500 with the request ID, and the log keeps the details.
src/app.ts
+16 -11
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

import { createServer } from 'node:http';import { createServer } from 'node:http';
import { randomUUID } from 'node:crypto';import { randomUUID } from 'node:crypto';
import express from 'express';import { handlers } from './handlers';
import { routes } from './routes';import { runHandler } from './http/pipeline';
import { log } from './log';import { createRouter } from './http/router';
import { writeJson } from './http/json';
export const app = express();
app.use(express.json());const match = createRouter(handlers);
for (const route of routes) app[route.method](route.path, route.handler);
app.use(function (err, req, res, next) {export const app = createServer((request, response) => {
log.error('unhandled error', err); const url = new URL(request.url ?? '/', 'http://storefront.local');
res.status(500).json({ error: 'internal error' }); const found = match(request.method ?? 'GET', url.pathname);
}); if (!found) {
writeJson(response, 404, { error: { code: 'not_found', message: 'No such endpoint' } }, {});
return;
}
void runHandler(found.spec, request, response, found.params, request.headers['x-request-id']?.toString() ?? randomUUID());
});
import express from 'express';
import { routes } from './routes';
import { log } from './log';
export const app = express();
app.use(express.json());
for (const route of routes) app[route.method](route.path, route.handler);
app.use(function (err, req, res, next) {
log.error('unhandled error', err);
res.status(500).json({ error: 'internal error' });
});
import { handlers } from './handlers';
import { runHandler } from './http/pipeline';
import { createRouter } from './http/router';
import { writeJson } from './http/json';
const match = createRouter(handlers);
export const app = createServer((request, response) => {
const url = new URL(request.url ?? '/', 'http://storefront.local');
const found = match(request.method ?? 'GET', url.pathname);
if (!found) {
writeJson(response, 404, { error: { code: 'not_found', message: 'No such endpoint' } }, {});
return;
}
void runHandler(found.spec, request, response, found.params, request.headers['x-request-id']?.toString() ?? randomUUID());
});
export function listen(port: number) {export function listen(port: number) {
return app.listen(port); return app.listen(port);
src/routes.ts
+0 -453
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

src/handlers/index.ts
+452 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

src/http/errors.ts
+23 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

/** An error that a handler throws on purpose. The pipeline answers with its status and a JSON body that names the code. */
export class HttpError extends Error {
constructor(
readonly status: number,
readonly code: string,
message: string,
readonly details: unknown = null
) {
super(message);
this.name = 'HttpError';
}
}
export function errorBody(error: HttpError) {
return { error: { code: error.code, message: error.message, details: error.details } };
}
export function internalError(requestId: string) {
return {
status: 500,
body: { error: { code: 'internal', message: `Something went wrong. Quote ${requestId} to support.` } },
};
}
src/http/handler.ts
+26 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import type { ZodType } from 'zod';
import type { Logger } from '@storefront/logger';
import type { User } from '../auth';
export type Access = 'public' | 'user' | 'admin';
export type HandlerResult = {
status: number;
headers?: Record<string, string>;
body: unknown;
};
export type HandlerSpec<Params, Query, Body> = {
method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
path: string;
auth: Access;
params?: ZodType<Params>;
query?: ZodType<Query>;
body?: ZodType<Body>;
run(input: { params: Params; query: Query; body: Body; user: User | null; log: Logger }): Promise<HandlerResult>;
};
/** A typed handler: the pipeline validates the path, query and body against its schemas, checks its access, and turns a thrown HttpError into a JSON error. */
export function handler<Params, Query, Body>(spec: HandlerSpec<Params, Query, Body>) {
return spec;
}
src/http/json.ts
+30 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import type { IncomingMessage, ServerResponse } from 'node:http';
import { HttpError } from './errors';
const MAX_BODY_BYTES = 1024 * 1024;
/** The JSON body of a request, at most 1 MiB. */
export async function readJson(request: IncomingMessage): Promise<unknown> {
const chunks: Buffer[] = [];
let size = 0;
for await (const chunk of request) {
size += chunk.length;
if (size > MAX_BODY_BYTES) throw new HttpError(413, 'too_large', 'The request body is over 1 MiB');
chunks.push(chunk);
}
if (size === 0) return null;
try {
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
} catch {
throw new HttpError(400, 'invalid_json', 'The request body is not JSON');
}
}
export function writeJson(response: ServerResponse, status: number, body: unknown, headers: Record<string, string>) {
if (status === 204) {
response.writeHead(204, headers).end();
return;
}
const text = typeof body === 'string' ? body : JSON.stringify(body);
response.writeHead(status, { 'Content-Type': 'application/json; charset=utf-8', ...headers }).end(text);
}
src/http/pipeline.ts
+48 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import type { IncomingMessage, ServerResponse } from 'node:http';
import { logger } from '@storefront/logger';
import { userFromRequest } from '../auth';
import { errorBody, HttpError, internalError } from './errors';
import type { HandlerSpec } from './handler';
import { readJson, writeJson } from './json';
/** Run one typed handler for one request: access, validation, the handler, and one JSON answer. */
export async function runHandler(
spec: HandlerSpec<unknown, unknown, unknown>,
request: IncomingMessage,
response: ServerResponse,
params: Record<string, string>,
requestId: string
) {
const log = logger.child({ requestId, route: `${spec.method} ${spec.path}` });
try {
const user = await userFromRequest(request);
if (spec.auth !== 'public' && user === null) throw new HttpError(401, 'unauthenticated', 'Sign in first');
if (spec.auth === 'admin' && user?.role !== 'admin') throw new HttpError(403, 'forbidden', 'Admins only');
const url = new URL(request.url ?? '/', 'http://storefront.local');
const parsed = {
params: spec.params ? spec.params.safeParse(params) : { success: true, data: params },
query: spec.query ? spec.query.safeParse(Object.fromEntries(url.searchParams)) : { success: true, data: {} },
body: spec.body ? spec.body.safeParse(await readJson(request)) : { success: true, data: null },
};
for (const [part, result] of Object.entries(parsed))
if (!result.success)
throw new HttpError(422, 'invalid_request', `The ${part} is not valid`, result.error.issues);
const result = await spec.run({
params: parsed.params.data,
query: parsed.query.data,
body: parsed.body.data,
user,
log,
});
writeJson(response, result.status, result.body, result.headers ?? {});
} catch (error) {
if (error instanceof HttpError) {
log.info('request rejected', { status: error.status, code: error.code });
writeJson(response, error.status, errorBody(error), {});
return;
}
log.error('handler failed', { error });
const failure = internalError(requestId);
writeJson(response, failure.status, failure.body, {});
}
}
src/http/router.ts
+25 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import type { HandlerSpec } from './handler';
type Route = { spec: HandlerSpec<unknown, unknown, unknown>; pattern: RegExp; names: string[] };
/** Match a method and a path against the registered handlers. A path segment `:name` captures one parameter. */
export function createRouter(specs: HandlerSpec<unknown, unknown, unknown>[]) {
const routes: Route[] = specs.map((spec) => {
const names: string[] = [];
const source = spec.path.replace(/:([a-zA-Z]+)/g, (_match, name: string) => {
names.push(name);
return '([^/]+)';
});
return { spec, pattern: new RegExp(`^${source}$`), names };
});
return function match(method: string, path: string) {
for (const route of routes) {
if (route.spec.method !== method) continue;
const found = route.pattern.exec(path);
if (!found) continue;
const params = Object.fromEntries(route.names.map((name, index) => [name, decodeURIComponent(found[index + 1] ?? '')]));
return { spec: route.spec, params };
}
return null;
};
}

Catalog handlers

The handlers of products, categories, brands, prices, stock levels, reviews, collections and media move to the typed form.

Each file keeps its toResponse shape, so the JSON of every answer stays the same. The behaviour changes in three ways:

  • A create with an existing key, such as a product SKU or a category slug, answers 409 instead of a database error.
  • Delete needs an admin. Before, any signed-in user could delete.
  • List and search take their limits from the schema, so a limit over 100 is a 422 instead of being cut silently.

src/catalog/categoryMappings.ts keys every category by the external ID of the new catalog import instead of its legacy code. Each entry changes only that field.

src/catalog/categoryMappings.ts
+240 -240
Line diff: Difftastic could not parse this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

Lines 8–734 load when you scroll near them.

parent: 'apparel', parent: 'apparel',
position: 1, position: 1,
visible: true, visible: true,
legacyCode: 'C0001', externalId: 'cat_0001',
legacyCode: 'C0001',
externalId: 'cat_0001',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-bestsellers', code: 'apparel-bestsellers',
name: 'Apparel: Bestsellers', name: 'Apparel: Bestsellers',
parent: 'apparel', parent: 'apparel',
position: 2, position: 2,
visible: true, visible: true,
legacyCode: 'C0002', externalId: 'cat_0002',
legacyCode: 'C0002',
externalId: 'cat_0002',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-sale', code: 'apparel-sale',
name: 'Apparel: Sale', name: 'Apparel: Sale',
parent: 'apparel', parent: 'apparel',
position: 3, position: 3,
visible: true, visible: true,
legacyCode: 'C0003', externalId: 'cat_0003',
legacyCode: 'C0003',
externalId: 'cat_0003',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-gifts', code: 'apparel-gifts',
name: 'Apparel: Gifts', name: 'Apparel: Gifts',
parent: 'apparel', parent: 'apparel',
position: 4, position: 4,
visible: true, visible: true,
legacyCode: 'C0004', externalId: 'cat_0004',
legacyCode: 'C0004',
externalId: 'cat_0004',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-essentials', code: 'apparel-essentials',
name: 'Apparel: Essentials', name: 'Apparel: Essentials',
parent: 'apparel', parent: 'apparel',
position: 5, position: 5,
visible: true, visible: true,
legacyCode: 'C0005', externalId: 'cat_0005',
legacyCode: 'C0005',
externalId: 'cat_0005',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-premium', code: 'apparel-premium',
name: 'Apparel: Premium', name: 'Apparel: Premium',
parent: 'apparel', parent: 'apparel',
position: 6, position: 6,
visible: true, visible: true,
legacyCode: 'C0006', externalId: 'cat_0006',
legacyCode: 'C0006',
externalId: 'cat_0006',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-eco', code: 'apparel-eco',
name: 'Apparel: Eco range', name: 'Apparel: Eco range',
parent: 'apparel', parent: 'apparel',
position: 7, position: 7,
visible: true, visible: true,
legacyCode: 'C0007', externalId: 'cat_0007',
legacyCode: 'C0007',
externalId: 'cat_0007',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-bundles', code: 'apparel-bundles',
name: 'Apparel: Bundles', name: 'Apparel: Bundles',
parent: 'apparel', parent: 'apparel',
position: 8, position: 8,
visible: true, visible: true,
legacyCode: 'C0008', externalId: 'cat_0008',
legacyCode: 'C0008',
externalId: 'cat_0008',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-clearance', code: 'apparel-clearance',
name: 'Apparel: Clearance', name: 'Apparel: Clearance',
parent: 'apparel', parent: 'apparel',
position: 9, position: 9,
visible: false, visible: false,
legacyCode: 'C0009', externalId: 'cat_0009',
legacyCode: 'C0009',
externalId: 'cat_0009',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-seasonal', code: 'apparel-seasonal',
name: 'Apparel: Seasonal', name: 'Apparel: Seasonal',
parent: 'apparel', parent: 'apparel',
position: 10, position: 10,
visible: true, visible: true,
legacyCode: 'C0010', externalId: 'cat_0010',
legacyCode: 'C0010',
externalId: 'cat_0010',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-kids', code: 'apparel-kids',
name: 'Apparel: Kids', name: 'Apparel: Kids',
parent: 'apparel', parent: 'apparel',
position: 11, position: 11,
visible: true, visible: true,
legacyCode: 'C0011', externalId: 'cat_0011',
legacyCode: 'C0011',
externalId: 'cat_0011',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-travel', code: 'apparel-travel',
name: 'Apparel: Travel', name: 'Apparel: Travel',
parent: 'apparel', parent: 'apparel',
position: 12, position: 12,
visible: true, visible: true,
legacyCode: 'C0012', externalId: 'cat_0012',
legacyCode: 'C0012',
externalId: 'cat_0012',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-compact', code: 'apparel-compact',
name: 'Apparel: Compact', name: 'Apparel: Compact',
parent: 'apparel', parent: 'apparel',
position: 13, position: 13,
visible: true, visible: true,
legacyCode: 'C0013', externalId: 'cat_0013',
legacyCode: 'C0013',
externalId: 'cat_0013',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-family', code: 'apparel-family',
name: 'Apparel: Family size', name: 'Apparel: Family size',
parent: 'apparel', parent: 'apparel',
position: 14, position: 14,
visible: true, visible: true,
legacyCode: 'C0014', externalId: 'cat_0014',
legacyCode: 'C0014',
externalId: 'cat_0014',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-refills', code: 'apparel-refills',
name: 'Apparel: Refills', name: 'Apparel: Refills',
parent: 'apparel', parent: 'apparel',
position: 15, position: 15,
visible: true, visible: true,
legacyCode: 'C0015', externalId: 'cat_0015',
legacyCode: 'C0015',
externalId: 'cat_0015',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-spares', code: 'apparel-spares',
name: 'Apparel: Spare parts', name: 'Apparel: Spare parts',
parent: 'apparel', parent: 'apparel',
position: 16, position: 16,
visible: true, visible: true,
legacyCode: 'C0016', externalId: 'cat_0016',
legacyCode: 'C0016',
externalId: 'cat_0016',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-accessories', code: 'apparel-accessories',
name: 'Apparel: Accessories', name: 'Apparel: Accessories',
parent: 'apparel', parent: 'apparel',
position: 17, position: 17,
visible: true, visible: true,
legacyCode: 'C0017', externalId: 'cat_0017',
legacyCode: 'C0017',
externalId: 'cat_0017',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-care', code: 'apparel-care',
name: 'Apparel: Care', name: 'Apparel: Care',
parent: 'apparel', parent: 'apparel',
position: 18, position: 18,
visible: true, visible: true,
legacyCode: 'C0018', externalId: 'cat_0018',
legacyCode: 'C0018',
externalId: 'cat_0018',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-storage', code: 'apparel-storage',
name: 'Apparel: Storage', name: 'Apparel: Storage',
parent: 'apparel', parent: 'apparel',
position: 19, position: 19,
visible: true, visible: true,
legacyCode: 'C0019', externalId: 'cat_0019',
legacyCode: 'C0019',
externalId: 'cat_0019',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'apparel-starter', code: 'apparel-starter',
name: 'Apparel: Starter sets', name: 'Apparel: Starter sets',
parent: 'apparel', parent: 'apparel',
position: 20, position: 20,
visible: true, visible: true,
legacyCode: 'C0020', externalId: 'cat_0020',
legacyCode: 'C0020',
externalId: 'cat_0020',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-new', code: 'footwear-new',
name: 'Footwear: New in', name: 'Footwear: New in',
parent: 'footwear', parent: 'footwear',
position: 21, position: 21,
visible: true, visible: true,
legacyCode: 'C0021', externalId: 'cat_0021',
legacyCode: 'C0021',
externalId: 'cat_0021',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-bestsellers', code: 'footwear-bestsellers',
name: 'Footwear: Bestsellers', name: 'Footwear: Bestsellers',
parent: 'footwear', parent: 'footwear',
position: 22, position: 22,
visible: true, visible: true,
legacyCode: 'C0022', externalId: 'cat_0022',
legacyCode: 'C0022',
externalId: 'cat_0022',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-sale', code: 'footwear-sale',
name: 'Footwear: Sale', name: 'Footwear: Sale',
parent: 'footwear', parent: 'footwear',
position: 23, position: 23,
visible: true, visible: true,
legacyCode: 'C0023', externalId: 'cat_0023',
legacyCode: 'C0023',
externalId: 'cat_0023',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-gifts', code: 'footwear-gifts',
name: 'Footwear: Gifts', name: 'Footwear: Gifts',
parent: 'footwear', parent: 'footwear',
position: 24, position: 24,
visible: true, visible: true,
legacyCode: 'C0024', externalId: 'cat_0024',
legacyCode: 'C0024',
externalId: 'cat_0024',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-essentials', code: 'footwear-essentials',
name: 'Footwear: Essentials', name: 'Footwear: Essentials',
parent: 'footwear', parent: 'footwear',
position: 25, position: 25,
visible: true, visible: true,
legacyCode: 'C0025', externalId: 'cat_0025',
legacyCode: 'C0025',
externalId: 'cat_0025',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-premium', code: 'footwear-premium',
name: 'Footwear: Premium', name: 'Footwear: Premium',
parent: 'footwear', parent: 'footwear',
position: 26, position: 26,
visible: true, visible: true,
legacyCode: 'C0026', externalId: 'cat_0026',
legacyCode: 'C0026',
externalId: 'cat_0026',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-eco', code: 'footwear-eco',
name: 'Footwear: Eco range', name: 'Footwear: Eco range',
parent: 'footwear', parent: 'footwear',
position: 27, position: 27,
visible: true, visible: true,
legacyCode: 'C0027', externalId: 'cat_0027',
legacyCode: 'C0027',
externalId: 'cat_0027',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-bundles', code: 'footwear-bundles',
name: 'Footwear: Bundles', name: 'Footwear: Bundles',
parent: 'footwear', parent: 'footwear',
position: 28, position: 28,
visible: true, visible: true,
legacyCode: 'C0028', externalId: 'cat_0028',
legacyCode: 'C0028',
externalId: 'cat_0028',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-clearance', code: 'footwear-clearance',
name: 'Footwear: Clearance', name: 'Footwear: Clearance',
parent: 'footwear', parent: 'footwear',
position: 29, position: 29,
visible: false, visible: false,
legacyCode: 'C0029', externalId: 'cat_0029',
legacyCode: 'C0029',
externalId: 'cat_0029',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-seasonal', code: 'footwear-seasonal',
name: 'Footwear: Seasonal', name: 'Footwear: Seasonal',
parent: 'footwear', parent: 'footwear',
position: 30, position: 30,
visible: true, visible: true,
legacyCode: 'C0030', externalId: 'cat_0030',
legacyCode: 'C0030',
externalId: 'cat_0030',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-kids', code: 'footwear-kids',
name: 'Footwear: Kids', name: 'Footwear: Kids',
parent: 'footwear', parent: 'footwear',
position: 31, position: 31,
visible: true, visible: true,
legacyCode: 'C0031', externalId: 'cat_0031',
legacyCode: 'C0031',
externalId: 'cat_0031',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-travel', code: 'footwear-travel',
name: 'Footwear: Travel', name: 'Footwear: Travel',
parent: 'footwear', parent: 'footwear',
position: 32, position: 32,
visible: true, visible: true,
legacyCode: 'C0032', externalId: 'cat_0032',
legacyCode: 'C0032',
externalId: 'cat_0032',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-compact', code: 'footwear-compact',
name: 'Footwear: Compact', name: 'Footwear: Compact',
parent: 'footwear', parent: 'footwear',
position: 33, position: 33,
visible: true, visible: true,
legacyCode: 'C0033', externalId: 'cat_0033',
legacyCode: 'C0033',
externalId: 'cat_0033',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-family', code: 'footwear-family',
name: 'Footwear: Family size', name: 'Footwear: Family size',
parent: 'footwear', parent: 'footwear',
position: 34, position: 34,
visible: true, visible: true,
legacyCode: 'C0034', externalId: 'cat_0034',
legacyCode: 'C0034',
externalId: 'cat_0034',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-refills', code: 'footwear-refills',
name: 'Footwear: Refills', name: 'Footwear: Refills',
parent: 'footwear', parent: 'footwear',
position: 35, position: 35,
visible: true, visible: true,
legacyCode: 'C0035', externalId: 'cat_0035',
legacyCode: 'C0035',
externalId: 'cat_0035',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-spares', code: 'footwear-spares',
name: 'Footwear: Spare parts', name: 'Footwear: Spare parts',
parent: 'footwear', parent: 'footwear',
position: 36, position: 36,
visible: true, visible: true,
legacyCode: 'C0036', externalId: 'cat_0036',
legacyCode: 'C0036',
externalId: 'cat_0036',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-accessories', code: 'footwear-accessories',
name: 'Footwear: Accessories', name: 'Footwear: Accessories',
parent: 'footwear', parent: 'footwear',
position: 37, position: 37,
visible: true, visible: true,
legacyCode: 'C0037', externalId: 'cat_0037',
legacyCode: 'C0037',
externalId: 'cat_0037',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-care', code: 'footwear-care',
name: 'Footwear: Care', name: 'Footwear: Care',
parent: 'footwear', parent: 'footwear',
position: 38, position: 38,
visible: true, visible: true,
legacyCode: 'C0038', externalId: 'cat_0038',
legacyCode: 'C0038',
externalId: 'cat_0038',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-storage', code: 'footwear-storage',
name: 'Footwear: Storage', name: 'Footwear: Storage',
parent: 'footwear', parent: 'footwear',
position: 39, position: 39,
visible: true, visible: true,
legacyCode: 'C0039', externalId: 'cat_0039',
legacyCode: 'C0039',
externalId: 'cat_0039',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'footwear-starter', code: 'footwear-starter',
name: 'Footwear: Starter sets', name: 'Footwear: Starter sets',
parent: 'footwear', parent: 'footwear',
position: 40, position: 40,
visible: true, visible: true,
legacyCode: 'C0040', externalId: 'cat_0040',
legacyCode: 'C0040',
externalId: 'cat_0040',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-new', code: 'home-new',
name: 'Home: New in', name: 'Home: New in',
parent: 'home', parent: 'home',
position: 41, position: 41,
visible: true, visible: true,
legacyCode: 'C0041', externalId: 'cat_0041',
legacyCode: 'C0041',
externalId: 'cat_0041',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-bestsellers', code: 'home-bestsellers',
name: 'Home: Bestsellers', name: 'Home: Bestsellers',
parent: 'home', parent: 'home',
position: 42, position: 42,
visible: true, visible: true,
legacyCode: 'C0042', externalId: 'cat_0042',
legacyCode: 'C0042',
externalId: 'cat_0042',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-sale', code: 'home-sale',
name: 'Home: Sale', name: 'Home: Sale',
parent: 'home', parent: 'home',
position: 43, position: 43,
visible: true, visible: true,
legacyCode: 'C0043', externalId: 'cat_0043',
legacyCode: 'C0043',
externalId: 'cat_0043',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-gifts', code: 'home-gifts',
name: 'Home: Gifts', name: 'Home: Gifts',
parent: 'home', parent: 'home',
position: 44, position: 44,
visible: true, visible: true,
legacyCode: 'C0044', externalId: 'cat_0044',
legacyCode: 'C0044',
externalId: 'cat_0044',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-essentials', code: 'home-essentials',
name: 'Home: Essentials', name: 'Home: Essentials',
parent: 'home', parent: 'home',
position: 45, position: 45,
visible: true, visible: true,
legacyCode: 'C0045', externalId: 'cat_0045',
legacyCode: 'C0045',
externalId: 'cat_0045',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-premium', code: 'home-premium',
name: 'Home: Premium', name: 'Home: Premium',
parent: 'home', parent: 'home',
position: 46, position: 46,
visible: true, visible: true,
legacyCode: 'C0046', externalId: 'cat_0046',
legacyCode: 'C0046',
externalId: 'cat_0046',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-eco', code: 'home-eco',
name: 'Home: Eco range', name: 'Home: Eco range',
parent: 'home', parent: 'home',
position: 47, position: 47,
visible: true, visible: true,
legacyCode: 'C0047', externalId: 'cat_0047',
legacyCode: 'C0047',
externalId: 'cat_0047',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-bundles', code: 'home-bundles',
name: 'Home: Bundles', name: 'Home: Bundles',
parent: 'home', parent: 'home',
position: 48, position: 48,
visible: true, visible: true,
legacyCode: 'C0048', externalId: 'cat_0048',
legacyCode: 'C0048',
externalId: 'cat_0048',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-clearance', code: 'home-clearance',
name: 'Home: Clearance', name: 'Home: Clearance',
parent: 'home', parent: 'home',
position: 49, position: 49,
visible: false, visible: false,
legacyCode: 'C0049', externalId: 'cat_0049',
legacyCode: 'C0049',
externalId: 'cat_0049',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-seasonal', code: 'home-seasonal',
name: 'Home: Seasonal', name: 'Home: Seasonal',
parent: 'home', parent: 'home',
position: 50, position: 50,
visible: true, visible: true,
legacyCode: 'C0050', externalId: 'cat_0050',
legacyCode: 'C0050',
externalId: 'cat_0050',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-kids', code: 'home-kids',
name: 'Home: Kids', name: 'Home: Kids',
parent: 'home', parent: 'home',
position: 51, position: 51,
visible: true, visible: true,
legacyCode: 'C0051', externalId: 'cat_0051',
legacyCode: 'C0051',
externalId: 'cat_0051',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-travel', code: 'home-travel',
name: 'Home: Travel', name: 'Home: Travel',
parent: 'home', parent: 'home',
position: 52, position: 52,
visible: true, visible: true,
legacyCode: 'C0052', externalId: 'cat_0052',
legacyCode: 'C0052',
externalId: 'cat_0052',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-compact', code: 'home-compact',
name: 'Home: Compact', name: 'Home: Compact',
parent: 'home', parent: 'home',
position: 53, position: 53,
visible: true, visible: true,
legacyCode: 'C0053', externalId: 'cat_0053',
legacyCode: 'C0053',
externalId: 'cat_0053',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-family', code: 'home-family',
name: 'Home: Family size', name: 'Home: Family size',
parent: 'home', parent: 'home',
position: 54, position: 54,
visible: true, visible: true,
legacyCode: 'C0054', externalId: 'cat_0054',
legacyCode: 'C0054',
externalId: 'cat_0054',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-refills', code: 'home-refills',
name: 'Home: Refills', name: 'Home: Refills',
parent: 'home', parent: 'home',
position: 55, position: 55,
visible: true, visible: true,
legacyCode: 'C0055', externalId: 'cat_0055',
legacyCode: 'C0055',
externalId: 'cat_0055',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-spares', code: 'home-spares',
name: 'Home: Spare parts', name: 'Home: Spare parts',
parent: 'home', parent: 'home',
position: 56, position: 56,
visible: true, visible: true,
legacyCode: 'C0056', externalId: 'cat_0056',
legacyCode: 'C0056',
externalId: 'cat_0056',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-accessories', code: 'home-accessories',
name: 'Home: Accessories', name: 'Home: Accessories',
parent: 'home', parent: 'home',
position: 57, position: 57,
visible: true, visible: true,
legacyCode: 'C0057', externalId: 'cat_0057',
legacyCode: 'C0057',
externalId: 'cat_0057',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-care', code: 'home-care',
name: 'Home: Care', name: 'Home: Care',
parent: 'home', parent: 'home',
position: 58, position: 58,
visible: true, visible: true,
legacyCode: 'C0058', externalId: 'cat_0058',
legacyCode: 'C0058',
externalId: 'cat_0058',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-storage', code: 'home-storage',
name: 'Home: Storage', name: 'Home: Storage',
parent: 'home', parent: 'home',
position: 59, position: 59,
visible: true, visible: true,
legacyCode: 'C0059', externalId: 'cat_0059',
legacyCode: 'C0059',
externalId: 'cat_0059',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'home-starter', code: 'home-starter',
name: 'Home: Starter sets', name: 'Home: Starter sets',
parent: 'home', parent: 'home',
position: 60, position: 60,
visible: true, visible: true,
legacyCode: 'C0060', externalId: 'cat_0060',
legacyCode: 'C0060',
externalId: 'cat_0060',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-new', code: 'kitchen-new',
name: 'Kitchen: New in', name: 'Kitchen: New in',
parent: 'kitchen', parent: 'kitchen',
position: 61, position: 61,
visible: true, visible: true,
legacyCode: 'C0061', externalId: 'cat_0061',
legacyCode: 'C0061',
externalId: 'cat_0061',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-bestsellers', code: 'kitchen-bestsellers',
name: 'Kitchen: Bestsellers', name: 'Kitchen: Bestsellers',
parent: 'kitchen', parent: 'kitchen',
position: 62, position: 62,
visible: true, visible: true,
legacyCode: 'C0062', externalId: 'cat_0062',
legacyCode: 'C0062',
externalId: 'cat_0062',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-sale', code: 'kitchen-sale',
name: 'Kitchen: Sale', name: 'Kitchen: Sale',
parent: 'kitchen', parent: 'kitchen',
position: 63, position: 63,
visible: true, visible: true,
legacyCode: 'C0063', externalId: 'cat_0063',
legacyCode: 'C0063',
externalId: 'cat_0063',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-gifts', code: 'kitchen-gifts',
name: 'Kitchen: Gifts', name: 'Kitchen: Gifts',
parent: 'kitchen', parent: 'kitchen',
position: 64, position: 64,
visible: true, visible: true,
legacyCode: 'C0064', externalId: 'cat_0064',
legacyCode: 'C0064',
externalId: 'cat_0064',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-essentials', code: 'kitchen-essentials',
name: 'Kitchen: Essentials', name: 'Kitchen: Essentials',
parent: 'kitchen', parent: 'kitchen',
position: 65, position: 65,
visible: true, visible: true,
legacyCode: 'C0065', externalId: 'cat_0065',
legacyCode: 'C0065',
externalId: 'cat_0065',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-premium', code: 'kitchen-premium',
name: 'Kitchen: Premium', name: 'Kitchen: Premium',
parent: 'kitchen', parent: 'kitchen',
position: 66, position: 66,
visible: true, visible: true,
legacyCode: 'C0066', externalId: 'cat_0066',
legacyCode: 'C0066',
externalId: 'cat_0066',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-eco', code: 'kitchen-eco',
name: 'Kitchen: Eco range', name: 'Kitchen: Eco range',
parent: 'kitchen', parent: 'kitchen',
position: 67, position: 67,
visible: true, visible: true,
legacyCode: 'C0067', externalId: 'cat_0067',
legacyCode: 'C0067',
externalId: 'cat_0067',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-bundles', code: 'kitchen-bundles',
name: 'Kitchen: Bundles', name: 'Kitchen: Bundles',
parent: 'kitchen', parent: 'kitchen',
position: 68, position: 68,
visible: true, visible: true,
legacyCode: 'C0068', externalId: 'cat_0068',
legacyCode: 'C0068',
externalId: 'cat_0068',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-clearance', code: 'kitchen-clearance',
name: 'Kitchen: Clearance', name: 'Kitchen: Clearance',
parent: 'kitchen', parent: 'kitchen',
position: 69, position: 69,
visible: false, visible: false,
legacyCode: 'C0069', externalId: 'cat_0069',
legacyCode: 'C0069',
externalId: 'cat_0069',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-seasonal', code: 'kitchen-seasonal',
name: 'Kitchen: Seasonal', name: 'Kitchen: Seasonal',
parent: 'kitchen', parent: 'kitchen',
position: 70, position: 70,
visible: true, visible: true,
legacyCode: 'C0070', externalId: 'cat_0070',
legacyCode: 'C0070',
externalId: 'cat_0070',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-kids', code: 'kitchen-kids',
name: 'Kitchen: Kids', name: 'Kitchen: Kids',
parent: 'kitchen', parent: 'kitchen',
position: 71, position: 71,
visible: true, visible: true,
legacyCode: 'C0071', externalId: 'cat_0071',
legacyCode: 'C0071',
externalId: 'cat_0071',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-travel', code: 'kitchen-travel',
name: 'Kitchen: Travel', name: 'Kitchen: Travel',
parent: 'kitchen', parent: 'kitchen',
position: 72, position: 72,
visible: true, visible: true,
legacyCode: 'C0072', externalId: 'cat_0072',
legacyCode: 'C0072',
externalId: 'cat_0072',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-compact', code: 'kitchen-compact',
name: 'Kitchen: Compact', name: 'Kitchen: Compact',
parent: 'kitchen', parent: 'kitchen',
position: 73, position: 73,
visible: true, visible: true,
legacyCode: 'C0073', externalId: 'cat_0073',
legacyCode: 'C0073',
externalId: 'cat_0073',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-family', code: 'kitchen-family',
name: 'Kitchen: Family size', name: 'Kitchen: Family size',
parent: 'kitchen', parent: 'kitchen',
position: 74, position: 74,
visible: true, visible: true,
legacyCode: 'C0074', externalId: 'cat_0074',
legacyCode: 'C0074',
externalId: 'cat_0074',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-refills', code: 'kitchen-refills',
name: 'Kitchen: Refills', name: 'Kitchen: Refills',
parent: 'kitchen', parent: 'kitchen',
position: 75, position: 75,
visible: true, visible: true,
legacyCode: 'C0075', externalId: 'cat_0075',
legacyCode: 'C0075',
externalId: 'cat_0075',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-spares', code: 'kitchen-spares',
name: 'Kitchen: Spare parts', name: 'Kitchen: Spare parts',
parent: 'kitchen', parent: 'kitchen',
position: 76, position: 76,
visible: true, visible: true,
legacyCode: 'C0076', externalId: 'cat_0076',
legacyCode: 'C0076',
externalId: 'cat_0076',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-accessories', code: 'kitchen-accessories',
name: 'Kitchen: Accessories', name: 'Kitchen: Accessories',
parent: 'kitchen', parent: 'kitchen',
position: 77, position: 77,
visible: true, visible: true,
legacyCode: 'C0077', externalId: 'cat_0077',
legacyCode: 'C0077',
externalId: 'cat_0077',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-care', code: 'kitchen-care',
name: 'Kitchen: Care', name: 'Kitchen: Care',
parent: 'kitchen', parent: 'kitchen',
position: 78, position: 78,
visible: true, visible: true,
legacyCode: 'C0078', externalId: 'cat_0078',
legacyCode: 'C0078',
externalId: 'cat_0078',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-storage', code: 'kitchen-storage',
name: 'Kitchen: Storage', name: 'Kitchen: Storage',
parent: 'kitchen', parent: 'kitchen',
position: 79, position: 79,
visible: true, visible: true,
legacyCode: 'C0079', externalId: 'cat_0079',
legacyCode: 'C0079',
externalId: 'cat_0079',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'kitchen-starter', code: 'kitchen-starter',
name: 'Kitchen: Starter sets', name: 'Kitchen: Starter sets',
parent: 'kitchen', parent: 'kitchen',
position: 80, position: 80,
visible: true, visible: true,
legacyCode: 'C0080', externalId: 'cat_0080',
legacyCode: 'C0080',
externalId: 'cat_0080',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {
code: 'garden-new', code: 'garden-new',
name: 'Garden: New in', name: 'Garden: New in',
parent: 'garden', parent: 'garden',
position: 81, position: 81,
visible: true, visible: true,
legacyCode: 'C0081', externalId: 'cat_0081',
legacyCode: 'C0081',
externalId: 'cat_0081',
updatedBy: 'catalog-import', updatedBy: 'catalog-import',
}, },
{ {

Lines 737–1463 load when you scroll near them.

Lines 1466–2165 load when you scroll near them.

src/handlers/attributes/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Attributes: create one record.// Attributes: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateAttributeBody } from '../../schemas/attributes';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateAttributeBody } from '../../schemas/attributes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
label: row.label, label: row.label,
kind: row.kind, kind: row.kind,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createAttribute(req, res, next) {export const createAttribute = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/attributes',
const body = req.body || {}; auth: 'user',
if (body.code === undefined) { body: CreateAttributeBody,
res.status(400).json({ error: 'code is required' }); async run({ body, user, log }) {
return; const existing = await db.attributes.findOne({ code: body.code });
} if (existing)
if (body.label === undefined) { throw new HttpError(409, 'conflict', `A Attribute with code ${body.code} exists`);
res.status(400).json({ error: 'label is required' }); const row = await db.attributes.insert({ ...body, created_by: user.id });
return; log.info('Attribute created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.attributes.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createAttribute failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createAttribute(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.code === undefined) {
res.status(400).json({ error: 'code is required' });
return;
}
if (body.label === undefined) {
res.status(400).json({ error: 'label is required' });
return;
}
db.attributes.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createAttribute failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createAttribute = handler({
method: 'POST',
path: '/attributes',
auth: 'user',
body: CreateAttributeBody,
async run({ body, user, log }) {
const existing = await db.attributes.findOne({ code: body.code });
if (existing)
throw new HttpError(409, 'conflict', `A Attribute with code ${body.code} exists`);
const row = await db.attributes.insert({ ...body, created_by: user.id });
log.info('Attribute created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/attributes/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Attributes: delete one record.// Attributes: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { AttributeParams } from '../../schemas/attributes';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { AttributeParams } from '../../schemas/attributes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
label: row.label, label: row.label,
kind: row.kind, kind: row.kind,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteAttribute(req, res, next) {export const deleteAttribute = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/attributes/:id',
db.attributes.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: AttributeParams,
log.error('deleteAttribute failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.attributes.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Attribute not found');
if (!removed) return res.status(404).json({ error: 'Attribute not found' }); log.info('Attribute deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteAttribute(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.attributes.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteAttribute failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Attribute not found' });
res.status(204).end();
});
});
};
export const deleteAttribute = handler({
method: 'DELETE',
path: '/attributes/:id',
auth: 'admin',
params: AttributeParams,
async run({ params, user, log }) {
const removed = await db.attributes.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Attribute not found');
log.info('Attribute deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/attributes/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Attributes: export every record as CSV or JSON.// Attributes: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportAttributesQuery } from '../../schemas/attributes';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportAttributesQuery } from '../../schemas/attributes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
label: row.label, label: row.label,
kind: row.kind, kind: row.kind,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportAttributes(req, res, next) {export const exportAttributes = handler({
db.attributes.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/attributes/export',
log.error('exportAttributes failed', err); auth: 'admin',
return next(err); query: ExportAttributesQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.attributes.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('attributes exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'code', 'label', 'kind'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'code', 'label', 'kind']),
};
},
});
module.exports = function exportAttributes(req, res, next) {
db.attributes.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportAttributes failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'code', 'label', 'kind']));
});
};
export const exportAttributes = handler({
method: 'GET',
path: '/attributes/export',
auth: 'admin',
query: ExportAttributesQuery,
async run({ query, log }) {
const rows = await db.attributes.findMany({ limit: query.limit });
log.info('attributes exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'code', 'label', 'kind']),
};
},
});
src/handlers/attributes/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Attributes: read one record.// Attributes: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { AttributeParams } from '../../schemas/attributes';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { AttributeParams } from '../../schemas/attributes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
label: row.label, label: row.label,
kind: row.kind, kind: row.kind,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getAttribute(req, res, next) {export const getAttribute = handler({
db.attributes.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/attributes/:id',
log.error('getAttribute failed', err); auth: 'public',
return next(err); params: AttributeParams,
} async run({ params }) {
if (!row) { const row = await db.attributes.findById(params.id);
res.status(404).json({ error: 'Attribute not found' }); if (!row) throw new HttpError(404, 'not_found', 'Attribute not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getAttribute(req, res, next) {
db.attributes.findById(req.params.id, function (err, row) {
if (err) {
log.error('getAttribute failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Attribute not found' });
return;
}
res.json(toResponse(row));
});
};
export const getAttribute = handler({
method: 'GET',
path: '/attributes/:id',
auth: 'public',
params: AttributeParams,
async run({ params }) {
const row = await db.attributes.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Attribute not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/attributes/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Attributes: list one page.// Attributes: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListAttributesQuery } from '../../schemas/attributes';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListAttributesQuery } from '../../schemas/attributes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
label: row.label, label: row.label,
kind: row.kind, kind: row.kind,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listAttributes(req, res, next) {export const listAttributes = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.attributes.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/attributes',
if (err) { auth: 'public',
log.error('listAttributes failed', err); query: ListAttributesQuery,
return next(err); async run({ query }) {
} const rows = await db.attributes.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listAttributes(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.attributes.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listAttributes failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listAttributes = handler({
method: 'GET',
path: '/attributes',
auth: 'public',
query: ListAttributesQuery,
async run({ query }) {
const rows = await db.attributes.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/attributes/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Attributes: search by text.// Attributes: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchAttributesQuery } from '../../schemas/attributes';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchAttributesQuery } from '../../schemas/attributes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
label: row.label, label: row.label,
kind: row.kind, kind: row.kind,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchAttributes(req, res, next) {export const searchAttributes = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/attributes/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchAttributesQuery,
} async run({ query }) {
db.attributes.search(q, { limit: 50 }, function (err, rows) { const rows = await db.attributes.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchAttributes failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchAttributes(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.attributes.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchAttributes failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchAttributes = handler({
method: 'GET',
path: '/attributes/search',
auth: 'public',
query: SearchAttributesQuery,
async run({ query }) {
const rows = await db.attributes.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/attributes/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Attributes: change the fields of one record.// Attributes: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { AttributeParams, UpdateAttributeBody } from '../../schemas/attributes';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { AttributeParams, UpdateAttributeBody } from '../../schemas/attributes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
label: row.label, label: row.label,
kind: row.kind, kind: row.kind,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateAttribute(req, res, next) {export const updateAttribute = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/attributes/:id',
db.attributes.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: AttributeParams,
if (!row) return res.status(404).json({ error: 'Attribute not found' }); body: UpdateAttributeBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.code !== undefined) changes.code = req.body.code; const updated = await db.attributes.update(params.id, { ...body, updated_by: user.id });
if (req.body.label !== undefined) changes.label = req.body.label; if (!updated) throw new HttpError(404, 'not_found', 'Attribute not found');
if (req.body.kind !== undefined) changes.kind = req.body.kind; log.info('Attribute updated', { id: updated.id, fields: Object.keys(body) });
db.attributes.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateAttribute failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateAttribute(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.attributes.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Attribute not found' });
const changes = {};
if (req.body.code !== undefined) changes.code = req.body.code;
if (req.body.label !== undefined) changes.label = req.body.label;
if (req.body.kind !== undefined) changes.kind = req.body.kind;
db.attributes.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateAttribute failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateAttribute = handler({
method: 'PATCH',
path: '/attributes/:id',
auth: 'user',
params: AttributeParams,
body: UpdateAttributeBody,
async run({ params, body, user, log }) {
const updated = await db.attributes.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Attribute not found');
log.info('Attribute updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/brands/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Brands: create one record.// Brands: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateBrandBody } from '../../schemas/brands';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateBrandBody } from '../../schemas/brands';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
website: row.website, website: row.website,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createBrand(req, res, next) {export const createBrand = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/brands',
const body = req.body || {}; auth: 'user',
if (body.slug === undefined) { body: CreateBrandBody,
res.status(400).json({ error: 'slug is required' }); async run({ body, user, log }) {
return; const existing = await db.brands.findOne({ slug: body.slug });
} if (existing)
if (body.name === undefined) { throw new HttpError(409, 'conflict', `A Brand with slug ${body.slug} exists`);
res.status(400).json({ error: 'name is required' }); const row = await db.brands.insert({ ...body, created_by: user.id });
return; log.info('Brand created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.brands.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createBrand failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createBrand(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.slug === undefined) {
res.status(400).json({ error: 'slug is required' });
return;
}
if (body.name === undefined) {
res.status(400).json({ error: 'name is required' });
return;
}
db.brands.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createBrand failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createBrand = handler({
method: 'POST',
path: '/brands',
auth: 'user',
body: CreateBrandBody,
async run({ body, user, log }) {
const existing = await db.brands.findOne({ slug: body.slug });
if (existing)
throw new HttpError(409, 'conflict', `A Brand with slug ${body.slug} exists`);
const row = await db.brands.insert({ ...body, created_by: user.id });
log.info('Brand created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/brands/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Brands: delete one record.// Brands: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { BrandParams } from '../../schemas/brands';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { BrandParams } from '../../schemas/brands';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
website: row.website, website: row.website,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteBrand(req, res, next) {export const deleteBrand = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/brands/:id',
db.brands.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: BrandParams,
log.error('deleteBrand failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.brands.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Brand not found');
if (!removed) return res.status(404).json({ error: 'Brand not found' }); log.info('Brand deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteBrand(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.brands.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteBrand failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Brand not found' });
res.status(204).end();
});
});
};
export const deleteBrand = handler({
method: 'DELETE',
path: '/brands/:id',
auth: 'admin',
params: BrandParams,
async run({ params, user, log }) {
const removed = await db.brands.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Brand not found');
log.info('Brand deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/brands/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Brands: export every record as CSV or JSON.// Brands: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportBrandsQuery } from '../../schemas/brands';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportBrandsQuery } from '../../schemas/brands';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
website: row.website, website: row.website,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportBrands(req, res, next) {export const exportBrands = handler({
db.brands.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/brands/export',
log.error('exportBrands failed', err); auth: 'admin',
return next(err); query: ExportBrandsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.brands.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('brands exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'website'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'website']),
};
},
});
module.exports = function exportBrands(req, res, next) {
db.brands.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportBrands failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'website']));
});
};
export const exportBrands = handler({
method: 'GET',
path: '/brands/export',
auth: 'admin',
query: ExportBrandsQuery,
async run({ query, log }) {
const rows = await db.brands.findMany({ limit: query.limit });
log.info('brands exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'website']),
};
},
});
src/handlers/brands/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Brands: read one record.// Brands: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { BrandParams } from '../../schemas/brands';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { BrandParams } from '../../schemas/brands';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
website: row.website, website: row.website,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getBrand(req, res, next) {export const getBrand = handler({
db.brands.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/brands/:id',
log.error('getBrand failed', err); auth: 'public',
return next(err); params: BrandParams,
} async run({ params }) {
if (!row) { const row = await db.brands.findById(params.id);
res.status(404).json({ error: 'Brand not found' }); if (!row) throw new HttpError(404, 'not_found', 'Brand not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getBrand(req, res, next) {
db.brands.findById(req.params.id, function (err, row) {
if (err) {
log.error('getBrand failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Brand not found' });
return;
}
res.json(toResponse(row));
});
};
export const getBrand = handler({
method: 'GET',
path: '/brands/:id',
auth: 'public',
params: BrandParams,
async run({ params }) {
const row = await db.brands.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Brand not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/brands/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Brands: list one page.// Brands: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListBrandsQuery } from '../../schemas/brands';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListBrandsQuery } from '../../schemas/brands';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
website: row.website, website: row.website,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listBrands(req, res, next) {export const listBrands = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.brands.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/brands',
if (err) { auth: 'public',
log.error('listBrands failed', err); query: ListBrandsQuery,
return next(err); async run({ query }) {
} const rows = await db.brands.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listBrands(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.brands.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listBrands failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listBrands = handler({
method: 'GET',
path: '/brands',
auth: 'public',
query: ListBrandsQuery,
async run({ query }) {
const rows = await db.brands.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/brands/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Brands: search by text.// Brands: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchBrandsQuery } from '../../schemas/brands';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchBrandsQuery } from '../../schemas/brands';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
website: row.website, website: row.website,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchBrands(req, res, next) {export const searchBrands = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/brands/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchBrandsQuery,
} async run({ query }) {
db.brands.search(q, { limit: 50 }, function (err, rows) { const rows = await db.brands.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchBrands failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchBrands(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.brands.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchBrands failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchBrands = handler({
method: 'GET',
path: '/brands/search',
auth: 'public',
query: SearchBrandsQuery,
async run({ query }) {
const rows = await db.brands.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/brands/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Brands: change the fields of one record.// Brands: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { BrandParams, UpdateBrandBody } from '../../schemas/brands';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { BrandParams, UpdateBrandBody } from '../../schemas/brands';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
website: row.website, website: row.website,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateBrand(req, res, next) {export const updateBrand = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/brands/:id',
db.brands.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: BrandParams,
if (!row) return res.status(404).json({ error: 'Brand not found' }); body: UpdateBrandBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.slug !== undefined) changes.slug = req.body.slug; const updated = await db.brands.update(params.id, { ...body, updated_by: user.id });
if (req.body.name !== undefined) changes.name = req.body.name; if (!updated) throw new HttpError(404, 'not_found', 'Brand not found');
if (req.body.website !== undefined) changes.website = req.body.website; log.info('Brand updated', { id: updated.id, fields: Object.keys(body) });
db.brands.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateBrand failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateBrand(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.brands.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Brand not found' });
const changes = {};
if (req.body.slug !== undefined) changes.slug = req.body.slug;
if (req.body.name !== undefined) changes.name = req.body.name;
if (req.body.website !== undefined) changes.website = req.body.website;
db.brands.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateBrand failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateBrand = handler({
method: 'PATCH',
path: '/brands/:id',
auth: 'user',
params: BrandParams,
body: UpdateBrandBody,
async run({ params, body, user, log }) {
const updated = await db.brands.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Brand not found');
log.info('Brand updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/bundles/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Bundles: create one record.// Bundles: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateBundleBody } from '../../schemas/bundles';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateBundleBody } from '../../schemas/bundles';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
productIds: row.productIds, productIds: row.productIds,
discountPercent: row.discountPercent, discountPercent: row.discountPercent,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createBundle(req, res, next) {export const createBundle = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/bundles',
const body = req.body || {}; auth: 'user',
if (body.sku === undefined) { body: CreateBundleBody,
res.status(400).json({ error: 'sku is required' }); async run({ body, user, log }) {
return; const existing = await db.bundles.findOne({ sku: body.sku });
} if (existing)
if (body.productIds === undefined) { throw new HttpError(409, 'conflict', `A Bundle with sku ${body.sku} exists`);
res.status(400).json({ error: 'productIds is required' }); const row = await db.bundles.insert({ ...body, created_by: user.id });
return; log.info('Bundle created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.bundles.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createBundle failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createBundle(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.sku === undefined) {
res.status(400).json({ error: 'sku is required' });
return;
}
if (body.productIds === undefined) {
res.status(400).json({ error: 'productIds is required' });
return;
}
db.bundles.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createBundle failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createBundle = handler({
method: 'POST',
path: '/bundles',
auth: 'user',
body: CreateBundleBody,
async run({ body, user, log }) {
const existing = await db.bundles.findOne({ sku: body.sku });
if (existing)
throw new HttpError(409, 'conflict', `A Bundle with sku ${body.sku} exists`);
const row = await db.bundles.insert({ ...body, created_by: user.id });
log.info('Bundle created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/bundles/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Bundles: delete one record.// Bundles: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { BundleParams } from '../../schemas/bundles';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { BundleParams } from '../../schemas/bundles';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
productIds: row.productIds, productIds: row.productIds,
discountPercent: row.discountPercent, discountPercent: row.discountPercent,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteBundle(req, res, next) {export const deleteBundle = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/bundles/:id',
db.bundles.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: BundleParams,
log.error('deleteBundle failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.bundles.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Bundle not found');
if (!removed) return res.status(404).json({ error: 'Bundle not found' }); log.info('Bundle deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteBundle(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.bundles.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteBundle failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Bundle not found' });
res.status(204).end();
});
});
};
export const deleteBundle = handler({
method: 'DELETE',
path: '/bundles/:id',
auth: 'admin',
params: BundleParams,
async run({ params, user, log }) {
const removed = await db.bundles.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Bundle not found');
log.info('Bundle deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/bundles/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Bundles: export every record as CSV or JSON.// Bundles: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportBundlesQuery } from '../../schemas/bundles';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportBundlesQuery } from '../../schemas/bundles';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
productIds: row.productIds, productIds: row.productIds,
discountPercent: row.discountPercent, discountPercent: row.discountPercent,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportBundles(req, res, next) {export const exportBundles = handler({
db.bundles.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/bundles/export',
log.error('exportBundles failed', err); auth: 'admin',
return next(err); query: ExportBundlesQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.bundles.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('bundles exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'sku', 'productIds', 'discountPercent'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'sku', 'productIds', 'discountPercent']),
};
},
});
module.exports = function exportBundles(req, res, next) {
db.bundles.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportBundles failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'sku', 'productIds', 'discountPercent']));
});
};
export const exportBundles = handler({
method: 'GET',
path: '/bundles/export',
auth: 'admin',
query: ExportBundlesQuery,
async run({ query, log }) {
const rows = await db.bundles.findMany({ limit: query.limit });
log.info('bundles exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'sku', 'productIds', 'discountPercent']),
};
},
});
src/handlers/bundles/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Bundles: read one record.// Bundles: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { BundleParams } from '../../schemas/bundles';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { BundleParams } from '../../schemas/bundles';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
productIds: row.productIds, productIds: row.productIds,
discountPercent: row.discountPercent, discountPercent: row.discountPercent,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getBundle(req, res, next) {export const getBundle = handler({
db.bundles.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/bundles/:id',
log.error('getBundle failed', err); auth: 'public',
return next(err); params: BundleParams,
} async run({ params }) {
if (!row) { const row = await db.bundles.findById(params.id);
res.status(404).json({ error: 'Bundle not found' }); if (!row) throw new HttpError(404, 'not_found', 'Bundle not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getBundle(req, res, next) {
db.bundles.findById(req.params.id, function (err, row) {
if (err) {
log.error('getBundle failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Bundle not found' });
return;
}
res.json(toResponse(row));
});
};
export const getBundle = handler({
method: 'GET',
path: '/bundles/:id',
auth: 'public',
params: BundleParams,
async run({ params }) {
const row = await db.bundles.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Bundle not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/bundles/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Bundles: list one page.// Bundles: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListBundlesQuery } from '../../schemas/bundles';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListBundlesQuery } from '../../schemas/bundles';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
productIds: row.productIds, productIds: row.productIds,
discountPercent: row.discountPercent, discountPercent: row.discountPercent,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listBundles(req, res, next) {export const listBundles = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.bundles.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/bundles',
if (err) { auth: 'public',
log.error('listBundles failed', err); query: ListBundlesQuery,
return next(err); async run({ query }) {
} const rows = await db.bundles.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listBundles(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.bundles.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listBundles failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listBundles = handler({
method: 'GET',
path: '/bundles',
auth: 'public',
query: ListBundlesQuery,
async run({ query }) {
const rows = await db.bundles.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/bundles/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Bundles: search by text.// Bundles: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchBundlesQuery } from '../../schemas/bundles';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchBundlesQuery } from '../../schemas/bundles';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
productIds: row.productIds, productIds: row.productIds,
discountPercent: row.discountPercent, discountPercent: row.discountPercent,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchBundles(req, res, next) {export const searchBundles = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/bundles/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchBundlesQuery,
} async run({ query }) {
db.bundles.search(q, { limit: 50 }, function (err, rows) { const rows = await db.bundles.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchBundles failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchBundles(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.bundles.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchBundles failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchBundles = handler({
method: 'GET',
path: '/bundles/search',
auth: 'public',
query: SearchBundlesQuery,
async run({ query }) {
const rows = await db.bundles.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/bundles/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Bundles: change the fields of one record.// Bundles: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { BundleParams, UpdateBundleBody } from '../../schemas/bundles';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { BundleParams, UpdateBundleBody } from '../../schemas/bundles';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
productIds: row.productIds, productIds: row.productIds,
discountPercent: row.discountPercent, discountPercent: row.discountPercent,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateBundle(req, res, next) {export const updateBundle = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/bundles/:id',
db.bundles.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: BundleParams,
if (!row) return res.status(404).json({ error: 'Bundle not found' }); body: UpdateBundleBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.sku !== undefined) changes.sku = req.body.sku; const updated = await db.bundles.update(params.id, { ...body, updated_by: user.id });
if (req.body.productIds !== undefined) changes.productIds = req.body.productIds; if (!updated) throw new HttpError(404, 'not_found', 'Bundle not found');
if (req.body.discountPercent !== undefined) changes.discountPercent = req.body.discountPercent; log.info('Bundle updated', { id: updated.id, fields: Object.keys(body) });
db.bundles.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateBundle failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateBundle(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.bundles.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Bundle not found' });
const changes = {};
if (req.body.sku !== undefined) changes.sku = req.body.sku;
if (req.body.productIds !== undefined) changes.productIds = req.body.productIds;
if (req.body.discountPercent !== undefined) changes.discountPercent = req.body.discountPercent;
db.bundles.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateBundle failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateBundle = handler({
method: 'PATCH',
path: '/bundles/:id',
auth: 'user',
params: BundleParams,
body: UpdateBundleBody,
async run({ params, body, user, log }) {
const updated = await db.bundles.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Bundle not found');
log.info('Bundle updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/categories/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Categories: create one record.// Categories: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateCategoryBody } from '../../schemas/categories';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateCategoryBody } from '../../schemas/categories';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
parentId: row.parentId, parentId: row.parentId,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createCategory(req, res, next) {export const createCategory = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/categories',
const body = req.body || {}; auth: 'user',
if (body.slug === undefined) { body: CreateCategoryBody,
res.status(400).json({ error: 'slug is required' }); async run({ body, user, log }) {
return; const existing = await db.categories.findOne({ slug: body.slug });
} if (existing)
if (body.name === undefined) { throw new HttpError(409, 'conflict', `A Category with slug ${body.slug} exists`);
res.status(400).json({ error: 'name is required' }); const row = await db.categories.insert({ ...body, created_by: user.id });
return; log.info('Category created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.categories.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createCategory failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createCategory(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.slug === undefined) {
res.status(400).json({ error: 'slug is required' });
return;
}
if (body.name === undefined) {
res.status(400).json({ error: 'name is required' });
return;
}
db.categories.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createCategory failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createCategory = handler({
method: 'POST',
path: '/categories',
auth: 'user',
body: CreateCategoryBody,
async run({ body, user, log }) {
const existing = await db.categories.findOne({ slug: body.slug });
if (existing)
throw new HttpError(409, 'conflict', `A Category with slug ${body.slug} exists`);
const row = await db.categories.insert({ ...body, created_by: user.id });
log.info('Category created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/categories/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Categories: delete one record.// Categories: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CategoryParams } from '../../schemas/categories';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CategoryParams } from '../../schemas/categories';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
parentId: row.parentId, parentId: row.parentId,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteCategory(req, res, next) {export const deleteCategory = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/categories/:id',
db.categories.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: CategoryParams,
log.error('deleteCategory failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.categories.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Category not found');
if (!removed) return res.status(404).json({ error: 'Category not found' }); log.info('Category deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteCategory(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.categories.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteCategory failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Category not found' });
res.status(204).end();
});
});
};
export const deleteCategory = handler({
method: 'DELETE',
path: '/categories/:id',
auth: 'admin',
params: CategoryParams,
async run({ params, user, log }) {
const removed = await db.categories.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Category not found');
log.info('Category deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/categories/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Categories: export every record as CSV or JSON.// Categories: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportCategoriesQuery } from '../../schemas/categories';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportCategoriesQuery } from '../../schemas/categories';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
parentId: row.parentId, parentId: row.parentId,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportCategories(req, res, next) {export const exportCategories = handler({
db.categories.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/categories/export',
log.error('exportCategories failed', err); auth: 'admin',
return next(err); query: ExportCategoriesQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.categories.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('categories exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'parentId', 'position'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'parentId', 'position']),
};
},
});
module.exports = function exportCategories(req, res, next) {
db.categories.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportCategories failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'parentId', 'position']));
});
};
export const exportCategories = handler({
method: 'GET',
path: '/categories/export',
auth: 'admin',
query: ExportCategoriesQuery,
async run({ query, log }) {
const rows = await db.categories.findMany({ limit: query.limit });
log.info('categories exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'parentId', 'position']),
};
},
});
src/handlers/categories/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Categories: read one record.// Categories: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CategoryParams } from '../../schemas/categories';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CategoryParams } from '../../schemas/categories';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
parentId: row.parentId, parentId: row.parentId,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getCategory(req, res, next) {export const getCategory = handler({
db.categories.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/categories/:id',
log.error('getCategory failed', err); auth: 'public',
return next(err); params: CategoryParams,
} async run({ params }) {
if (!row) { const row = await db.categories.findById(params.id);
res.status(404).json({ error: 'Category not found' }); if (!row) throw new HttpError(404, 'not_found', 'Category not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getCategory(req, res, next) {
db.categories.findById(req.params.id, function (err, row) {
if (err) {
log.error('getCategory failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Category not found' });
return;
}
res.json(toResponse(row));
});
};
export const getCategory = handler({
method: 'GET',
path: '/categories/:id',
auth: 'public',
params: CategoryParams,
async run({ params }) {
const row = await db.categories.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Category not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/categories/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Categories: list one page.// Categories: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListCategoriesQuery } from '../../schemas/categories';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListCategoriesQuery } from '../../schemas/categories';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
parentId: row.parentId, parentId: row.parentId,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listCategories(req, res, next) {export const listCategories = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.categories.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/categories',
if (err) { auth: 'public',
log.error('listCategories failed', err); query: ListCategoriesQuery,
return next(err); async run({ query }) {
} const rows = await db.categories.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listCategories(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.categories.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listCategories failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listCategories = handler({
method: 'GET',
path: '/categories',
auth: 'public',
query: ListCategoriesQuery,
async run({ query }) {
const rows = await db.categories.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/categories/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Categories: search by text.// Categories: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchCategoriesQuery } from '../../schemas/categories';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchCategoriesQuery } from '../../schemas/categories';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
parentId: row.parentId, parentId: row.parentId,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchCategories(req, res, next) {export const searchCategories = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/categories/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchCategoriesQuery,
} async run({ query }) {
db.categories.search(q, { limit: 50 }, function (err, rows) { const rows = await db.categories.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchCategories failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchCategories(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.categories.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchCategories failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchCategories = handler({
method: 'GET',
path: '/categories/search',
auth: 'public',
query: SearchCategoriesQuery,
async run({ query }) {
const rows = await db.categories.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/categories/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Categories: change the fields of one record.// Categories: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CategoryParams, UpdateCategoryBody } from '../../schemas/categories';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CategoryParams, UpdateCategoryBody } from '../../schemas/categories';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
parentId: row.parentId, parentId: row.parentId,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateCategory(req, res, next) {export const updateCategory = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/categories/:id',
db.categories.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: CategoryParams,
if (!row) return res.status(404).json({ error: 'Category not found' }); body: UpdateCategoryBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.slug !== undefined) changes.slug = req.body.slug; const updated = await db.categories.update(params.id, { ...body, updated_by: user.id });
if (req.body.name !== undefined) changes.name = req.body.name; if (!updated) throw new HttpError(404, 'not_found', 'Category not found');
if (req.body.parentId !== undefined) changes.parentId = req.body.parentId; log.info('Category updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.position !== undefined) changes.position = req.body.position; return { status: 200, body: toResponse(updated) };
db.categories.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updateCategory failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateCategory(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.categories.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Category not found' });
const changes = {};
if (req.body.slug !== undefined) changes.slug = req.body.slug;
if (req.body.name !== undefined) changes.name = req.body.name;
if (req.body.parentId !== undefined) changes.parentId = req.body.parentId;
if (req.body.position !== undefined) changes.position = req.body.position;
db.categories.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateCategory failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateCategory = handler({
method: 'PATCH',
path: '/categories/:id',
auth: 'user',
params: CategoryParams,
body: UpdateCategoryBody,
async run({ params, body, user, log }) {
const updated = await db.categories.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Category not found');
log.info('Category updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/collections/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Collections: create one record.// Collections: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateCollectionBody } from '../../schemas/collections';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateCollectionBody } from '../../schemas/collections';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
title: row.title, title: row.title,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createCollection(req, res, next) {export const createCollection = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/collections',
const body = req.body || {}; auth: 'user',
if (body.slug === undefined) { body: CreateCollectionBody,
res.status(400).json({ error: 'slug is required' }); async run({ body, user, log }) {
return; const existing = await db.collections.findOne({ slug: body.slug });
} if (existing)
if (body.title === undefined) { throw new HttpError(409, 'conflict', `A Collection with slug ${body.slug} exists`);
res.status(400).json({ error: 'title is required' }); const row = await db.collections.insert({ ...body, created_by: user.id });
return; log.info('Collection created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.collections.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createCollection failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createCollection(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.slug === undefined) {
res.status(400).json({ error: 'slug is required' });
return;
}
if (body.title === undefined) {
res.status(400).json({ error: 'title is required' });
return;
}
db.collections.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createCollection failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createCollection = handler({
method: 'POST',
path: '/collections',
auth: 'user',
body: CreateCollectionBody,
async run({ body, user, log }) {
const existing = await db.collections.findOne({ slug: body.slug });
if (existing)
throw new HttpError(409, 'conflict', `A Collection with slug ${body.slug} exists`);
const row = await db.collections.insert({ ...body, created_by: user.id });
log.info('Collection created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/collections/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Collections: delete one record.// Collections: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CollectionParams } from '../../schemas/collections';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CollectionParams } from '../../schemas/collections';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
title: row.title, title: row.title,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteCollection(req, res, next) {export const deleteCollection = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/collections/:id',
db.collections.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: CollectionParams,
log.error('deleteCollection failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.collections.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Collection not found');
if (!removed) return res.status(404).json({ error: 'Collection not found' }); log.info('Collection deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteCollection(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.collections.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteCollection failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Collection not found' });
res.status(204).end();
});
});
};
export const deleteCollection = handler({
method: 'DELETE',
path: '/collections/:id',
auth: 'admin',
params: CollectionParams,
async run({ params, user, log }) {
const removed = await db.collections.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Collection not found');
log.info('Collection deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/collections/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Collections: export every record as CSV or JSON.// Collections: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportCollectionsQuery } from '../../schemas/collections';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportCollectionsQuery } from '../../schemas/collections';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
title: row.title, title: row.title,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportCollections(req, res, next) {export const exportCollections = handler({
db.collections.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/collections/export',
log.error('exportCollections failed', err); auth: 'admin',
return next(err); query: ExportCollectionsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.collections.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('collections exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'slug', 'title', 'productIds'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'slug', 'title', 'productIds']),
};
},
});
module.exports = function exportCollections(req, res, next) {
db.collections.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportCollections failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'slug', 'title', 'productIds']));
});
};
export const exportCollections = handler({
method: 'GET',
path: '/collections/export',
auth: 'admin',
query: ExportCollectionsQuery,
async run({ query, log }) {
const rows = await db.collections.findMany({ limit: query.limit });
log.info('collections exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'slug', 'title', 'productIds']),
};
},
});
src/handlers/collections/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Collections: read one record.// Collections: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CollectionParams } from '../../schemas/collections';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CollectionParams } from '../../schemas/collections';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
title: row.title, title: row.title,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getCollection(req, res, next) {export const getCollection = handler({
db.collections.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/collections/:id',
log.error('getCollection failed', err); auth: 'public',
return next(err); params: CollectionParams,
} async run({ params }) {
if (!row) { const row = await db.collections.findById(params.id);
res.status(404).json({ error: 'Collection not found' }); if (!row) throw new HttpError(404, 'not_found', 'Collection not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getCollection(req, res, next) {
db.collections.findById(req.params.id, function (err, row) {
if (err) {
log.error('getCollection failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Collection not found' });
return;
}
res.json(toResponse(row));
});
};
export const getCollection = handler({
method: 'GET',
path: '/collections/:id',
auth: 'public',
params: CollectionParams,
async run({ params }) {
const row = await db.collections.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Collection not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/collections/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Collections: list one page.// Collections: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListCollectionsQuery } from '../../schemas/collections';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListCollectionsQuery } from '../../schemas/collections';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
title: row.title, title: row.title,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listCollections(req, res, next) {export const listCollections = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.collections.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/collections',
if (err) { auth: 'public',
log.error('listCollections failed', err); query: ListCollectionsQuery,
return next(err); async run({ query }) {
} const rows = await db.collections.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listCollections(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.collections.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listCollections failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listCollections = handler({
method: 'GET',
path: '/collections',
auth: 'public',
query: ListCollectionsQuery,
async run({ query }) {
const rows = await db.collections.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/collections/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Collections: search by text.// Collections: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchCollectionsQuery } from '../../schemas/collections';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchCollectionsQuery } from '../../schemas/collections';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
title: row.title, title: row.title,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchCollections(req, res, next) {export const searchCollections = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/collections/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchCollectionsQuery,
} async run({ query }) {
db.collections.search(q, { limit: 50 }, function (err, rows) { const rows = await db.collections.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchCollections failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchCollections(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.collections.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchCollections failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchCollections = handler({
method: 'GET',
path: '/collections/search',
auth: 'public',
query: SearchCollectionsQuery,
async run({ query }) {
const rows = await db.collections.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/collections/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Collections: change the fields of one record.// Collections: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CollectionParams, UpdateCollectionBody } from '../../schemas/collections';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CollectionParams, UpdateCollectionBody } from '../../schemas/collections';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
title: row.title, title: row.title,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateCollection(req, res, next) {export const updateCollection = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/collections/:id',
db.collections.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: CollectionParams,
if (!row) return res.status(404).json({ error: 'Collection not found' }); body: UpdateCollectionBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.slug !== undefined) changes.slug = req.body.slug; const updated = await db.collections.update(params.id, { ...body, updated_by: user.id });
if (req.body.title !== undefined) changes.title = req.body.title; if (!updated) throw new HttpError(404, 'not_found', 'Collection not found');
if (req.body.productIds !== undefined) changes.productIds = req.body.productIds; log.info('Collection updated', { id: updated.id, fields: Object.keys(body) });
db.collections.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateCollection failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateCollection(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.collections.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Collection not found' });
const changes = {};
if (req.body.slug !== undefined) changes.slug = req.body.slug;
if (req.body.title !== undefined) changes.title = req.body.title;
if (req.body.productIds !== undefined) changes.productIds = req.body.productIds;
db.collections.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateCollection failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateCollection = handler({
method: 'PATCH',
path: '/collections/:id',
auth: 'user',
params: CollectionParams,
body: UpdateCollectionBody,
async run({ params, body, user, log }) {
const updated = await db.collections.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Collection not found');
log.info('Collection updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/inventory/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Inventory: create one record.// Inventory: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateStockLevelBody } from '../../schemas/inventory';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateStockLevelBody } from '../../schemas/inventory';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
warehouseId: row.warehouseId, warehouseId: row.warehouseId,
onHand: row.onHand, onHand: row.onHand,
reserved: row.reserved, reserved: row.reserved,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createStockLevel(req, res, next) {export const createStockLevel = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/inventory',
const body = req.body || {}; auth: 'user',
if (body.sku === undefined) { body: CreateStockLevelBody,
res.status(400).json({ error: 'sku is required' }); async run({ body, user, log }) {
return; const existing = await db.inventory.findOne({ sku: body.sku });
} if (existing)
if (body.warehouseId === undefined) { throw new HttpError(409, 'conflict', `A StockLevel with sku ${body.sku} exists`);
res.status(400).json({ error: 'warehouseId is required' }); const row = await db.inventory.insert({ ...body, created_by: user.id });
return; log.info('StockLevel created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.inventory.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createStockLevel failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createStockLevel(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.sku === undefined) {
res.status(400).json({ error: 'sku is required' });
return;
}
if (body.warehouseId === undefined) {
res.status(400).json({ error: 'warehouseId is required' });
return;
}
db.inventory.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createStockLevel failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createStockLevel = handler({
method: 'POST',
path: '/inventory',
auth: 'user',
body: CreateStockLevelBody,
async run({ body, user, log }) {
const existing = await db.inventory.findOne({ sku: body.sku });
if (existing)
throw new HttpError(409, 'conflict', `A StockLevel with sku ${body.sku} exists`);
const row = await db.inventory.insert({ ...body, created_by: user.id });
log.info('StockLevel created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/inventory/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Inventory: delete one record.// Inventory: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { StockLevelParams } from '../../schemas/inventory';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { StockLevelParams } from '../../schemas/inventory';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
warehouseId: row.warehouseId, warehouseId: row.warehouseId,
onHand: row.onHand, onHand: row.onHand,
reserved: row.reserved, reserved: row.reserved,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteStockLevel(req, res, next) {export const deleteStockLevel = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/inventory/:id',
db.inventory.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: StockLevelParams,
log.error('deleteStockLevel failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.inventory.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'StockLevel not found');
if (!removed) return res.status(404).json({ error: 'StockLevel not found' }); log.info('StockLevel deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteStockLevel(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.inventory.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteStockLevel failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'StockLevel not found' });
res.status(204).end();
});
});
};
export const deleteStockLevel = handler({
method: 'DELETE',
path: '/inventory/:id',
auth: 'admin',
params: StockLevelParams,
async run({ params, user, log }) {
const removed = await db.inventory.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'StockLevel not found');
log.info('StockLevel deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/inventory/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Inventory: export every record as CSV or JSON.// Inventory: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportInventoryQuery } from '../../schemas/inventory';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportInventoryQuery } from '../../schemas/inventory';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
warehouseId: row.warehouseId, warehouseId: row.warehouseId,
onHand: row.onHand, onHand: row.onHand,
reserved: row.reserved, reserved: row.reserved,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportInventory(req, res, next) {export const exportInventory = handler({
db.inventory.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/inventory/export',
log.error('exportInventory failed', err); auth: 'admin',
return next(err); query: ExportInventoryQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.inventory.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('inventory exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'sku', 'warehouseId', 'onHand', 'reserved'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'sku', 'warehouseId', 'onHand', 'reserved']),
};
},
});
module.exports = function exportInventory(req, res, next) {
db.inventory.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportInventory failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'sku', 'warehouseId', 'onHand', 'reserved']));
});
};
export const exportInventory = handler({
method: 'GET',
path: '/inventory/export',
auth: 'admin',
query: ExportInventoryQuery,
async run({ query, log }) {
const rows = await db.inventory.findMany({ limit: query.limit });
log.info('inventory exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'sku', 'warehouseId', 'onHand', 'reserved']),
};
},
});
src/handlers/inventory/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Inventory: read one record.// Inventory: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { StockLevelParams } from '../../schemas/inventory';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { StockLevelParams } from '../../schemas/inventory';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
warehouseId: row.warehouseId, warehouseId: row.warehouseId,
onHand: row.onHand, onHand: row.onHand,
reserved: row.reserved, reserved: row.reserved,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getStockLevel(req, res, next) {export const getStockLevel = handler({
db.inventory.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/inventory/:id',
log.error('getStockLevel failed', err); auth: 'public',
return next(err); params: StockLevelParams,
} async run({ params }) {
if (!row) { const row = await db.inventory.findById(params.id);
res.status(404).json({ error: 'StockLevel not found' }); if (!row) throw new HttpError(404, 'not_found', 'StockLevel not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getStockLevel(req, res, next) {
db.inventory.findById(req.params.id, function (err, row) {
if (err) {
log.error('getStockLevel failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'StockLevel not found' });
return;
}
res.json(toResponse(row));
});
};
export const getStockLevel = handler({
method: 'GET',
path: '/inventory/:id',
auth: 'public',
params: StockLevelParams,
async run({ params }) {
const row = await db.inventory.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'StockLevel not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/inventory/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Inventory: list one page.// Inventory: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListInventoryQuery } from '../../schemas/inventory';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListInventoryQuery } from '../../schemas/inventory';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
warehouseId: row.warehouseId, warehouseId: row.warehouseId,
onHand: row.onHand, onHand: row.onHand,
reserved: row.reserved, reserved: row.reserved,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listInventory(req, res, next) {export const listInventory = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.inventory.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/inventory',
if (err) { auth: 'public',
log.error('listInventory failed', err); query: ListInventoryQuery,
return next(err); async run({ query }) {
} const rows = await db.inventory.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listInventory(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.inventory.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listInventory failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listInventory = handler({
method: 'GET',
path: '/inventory',
auth: 'public',
query: ListInventoryQuery,
async run({ query }) {
const rows = await db.inventory.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/inventory/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Inventory: search by text.// Inventory: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchInventoryQuery } from '../../schemas/inventory';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchInventoryQuery } from '../../schemas/inventory';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
warehouseId: row.warehouseId, warehouseId: row.warehouseId,
onHand: row.onHand, onHand: row.onHand,
reserved: row.reserved, reserved: row.reserved,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchInventory(req, res, next) {export const searchInventory = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/inventory/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchInventoryQuery,
} async run({ query }) {
db.inventory.search(q, { limit: 50 }, function (err, rows) { const rows = await db.inventory.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchInventory failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchInventory(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.inventory.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchInventory failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchInventory = handler({
method: 'GET',
path: '/inventory/search',
auth: 'public',
query: SearchInventoryQuery,
async run({ query }) {
const rows = await db.inventory.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/inventory/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Inventory: change the fields of one record.// Inventory: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { StockLevelParams, UpdateStockLevelBody } from '../../schemas/inventory';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { StockLevelParams, UpdateStockLevelBody } from '../../schemas/inventory';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
warehouseId: row.warehouseId, warehouseId: row.warehouseId,
onHand: row.onHand, onHand: row.onHand,
reserved: row.reserved, reserved: row.reserved,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateStockLevel(req, res, next) {export const updateStockLevel = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/inventory/:id',
db.inventory.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: StockLevelParams,
if (!row) return res.status(404).json({ error: 'StockLevel not found' }); body: UpdateStockLevelBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.sku !== undefined) changes.sku = req.body.sku; const updated = await db.inventory.update(params.id, { ...body, updated_by: user.id });
if (req.body.warehouseId !== undefined) changes.warehouseId = req.body.warehouseId; if (!updated) throw new HttpError(404, 'not_found', 'StockLevel not found');
if (req.body.onHand !== undefined) changes.onHand = req.body.onHand; log.info('StockLevel updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.reserved !== undefined) changes.reserved = req.body.reserved; return { status: 200, body: toResponse(updated) };
db.inventory.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updateStockLevel failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateStockLevel(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.inventory.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'StockLevel not found' });
const changes = {};
if (req.body.sku !== undefined) changes.sku = req.body.sku;
if (req.body.warehouseId !== undefined) changes.warehouseId = req.body.warehouseId;
if (req.body.onHand !== undefined) changes.onHand = req.body.onHand;
if (req.body.reserved !== undefined) changes.reserved = req.body.reserved;
db.inventory.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateStockLevel failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateStockLevel = handler({
method: 'PATCH',
path: '/inventory/:id',
auth: 'user',
params: StockLevelParams,
body: UpdateStockLevelBody,
async run({ params, body, user, log }) {
const updated = await db.inventory.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'StockLevel not found');
log.info('StockLevel updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/media/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Media: create one record.// Media: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateMediaAssetBody } from '../../schemas/media';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateMediaAssetBody } from '../../schemas/media';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
url: row.url, url: row.url,
altText: row.altText, altText: row.altText,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createMediaAsset(req, res, next) {export const createMediaAsset = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/media',
const body = req.body || {}; auth: 'user',
if (body.productId === undefined) { body: CreateMediaAssetBody,
res.status(400).json({ error: 'productId is required' }); async run({ body, user, log }) {
return; const row = await db.media.insert({ ...body, created_by: user.id });
} log.info('MediaAsset created', { id: row.id });
if (body.url === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'url is required' }); },
return;});
}
db.media.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createMediaAsset failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createMediaAsset(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.productId === undefined) {
res.status(400).json({ error: 'productId is required' });
return;
}
if (body.url === undefined) {
res.status(400).json({ error: 'url is required' });
return;
}
db.media.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createMediaAsset failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createMediaAsset = handler({
method: 'POST',
path: '/media',
auth: 'user',
body: CreateMediaAssetBody,
async run({ body, user, log }) {
const row = await db.media.insert({ ...body, created_by: user.id });
log.info('MediaAsset created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/media/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Media: delete one record.// Media: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { MediaAssetParams } from '../../schemas/media';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { MediaAssetParams } from '../../schemas/media';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
url: row.url, url: row.url,
altText: row.altText, altText: row.altText,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteMediaAsset(req, res, next) {export const deleteMediaAsset = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/media/:id',
db.media.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: MediaAssetParams,
log.error('deleteMediaAsset failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.media.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'MediaAsset not found');
if (!removed) return res.status(404).json({ error: 'MediaAsset not found' }); log.info('MediaAsset deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteMediaAsset(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.media.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteMediaAsset failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'MediaAsset not found' });
res.status(204).end();
});
});
};
export const deleteMediaAsset = handler({
method: 'DELETE',
path: '/media/:id',
auth: 'admin',
params: MediaAssetParams,
async run({ params, user, log }) {
const removed = await db.media.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'MediaAsset not found');
log.info('MediaAsset deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/media/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Media: export every record as CSV or JSON.// Media: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportMediaQuery } from '../../schemas/media';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportMediaQuery } from '../../schemas/media';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
url: row.url, url: row.url,
altText: row.altText, altText: row.altText,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportMedia(req, res, next) {export const exportMedia = handler({
db.media.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/media/export',
log.error('exportMedia failed', err); auth: 'admin',
return next(err); query: ExportMediaQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.media.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('media exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'productId', 'url', 'altText', 'position'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'productId', 'url', 'altText', 'position']),
};
},
});
module.exports = function exportMedia(req, res, next) {
db.media.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportMedia failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'productId', 'url', 'altText', 'position']));
});
};
export const exportMedia = handler({
method: 'GET',
path: '/media/export',
auth: 'admin',
query: ExportMediaQuery,
async run({ query, log }) {
const rows = await db.media.findMany({ limit: query.limit });
log.info('media exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'productId', 'url', 'altText', 'position']),
};
},
});
src/handlers/media/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Media: read one record.// Media: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { MediaAssetParams } from '../../schemas/media';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { MediaAssetParams } from '../../schemas/media';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
url: row.url, url: row.url,
altText: row.altText, altText: row.altText,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getMediaAsset(req, res, next) {export const getMediaAsset = handler({
db.media.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/media/:id',
log.error('getMediaAsset failed', err); auth: 'public',
return next(err); params: MediaAssetParams,
} async run({ params }) {
if (!row) { const row = await db.media.findById(params.id);
res.status(404).json({ error: 'MediaAsset not found' }); if (!row) throw new HttpError(404, 'not_found', 'MediaAsset not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getMediaAsset(req, res, next) {
db.media.findById(req.params.id, function (err, row) {
if (err) {
log.error('getMediaAsset failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'MediaAsset not found' });
return;
}
res.json(toResponse(row));
});
};
export const getMediaAsset = handler({
method: 'GET',
path: '/media/:id',
auth: 'public',
params: MediaAssetParams,
async run({ params }) {
const row = await db.media.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'MediaAsset not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/media/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Media: list one page.// Media: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListMediaQuery } from '../../schemas/media';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListMediaQuery } from '../../schemas/media';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
url: row.url, url: row.url,
altText: row.altText, altText: row.altText,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listMedia(req, res, next) {export const listMedia = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.media.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/media',
if (err) { auth: 'public',
log.error('listMedia failed', err); query: ListMediaQuery,
return next(err); async run({ query }) {
} const rows = await db.media.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listMedia(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.media.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listMedia failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listMedia = handler({
method: 'GET',
path: '/media',
auth: 'public',
query: ListMediaQuery,
async run({ query }) {
const rows = await db.media.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/media/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Media: search by text.// Media: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchMediaQuery } from '../../schemas/media';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchMediaQuery } from '../../schemas/media';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
url: row.url, url: row.url,
altText: row.altText, altText: row.altText,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchMedia(req, res, next) {export const searchMedia = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/media/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchMediaQuery,
} async run({ query }) {
db.media.search(q, { limit: 50 }, function (err, rows) { const rows = await db.media.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchMedia failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchMedia(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.media.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchMedia failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchMedia = handler({
method: 'GET',
path: '/media/search',
auth: 'public',
query: SearchMediaQuery,
async run({ query }) {
const rows = await db.media.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/media/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Media: change the fields of one record.// Media: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { MediaAssetParams, UpdateMediaAssetBody } from '../../schemas/media';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { MediaAssetParams, UpdateMediaAssetBody } from '../../schemas/media';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
url: row.url, url: row.url,
altText: row.altText, altText: row.altText,
position: row.position, position: row.position,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateMediaAsset(req, res, next) {export const updateMediaAsset = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/media/:id',
db.media.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: MediaAssetParams,
if (!row) return res.status(404).json({ error: 'MediaAsset not found' }); body: UpdateMediaAssetBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.productId !== undefined) changes.productId = req.body.productId; const updated = await db.media.update(params.id, { ...body, updated_by: user.id });
if (req.body.url !== undefined) changes.url = req.body.url; if (!updated) throw new HttpError(404, 'not_found', 'MediaAsset not found');
if (req.body.altText !== undefined) changes.altText = req.body.altText; log.info('MediaAsset updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.position !== undefined) changes.position = req.body.position; return { status: 200, body: toResponse(updated) };
db.media.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updateMediaAsset failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateMediaAsset(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.media.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'MediaAsset not found' });
const changes = {};
if (req.body.productId !== undefined) changes.productId = req.body.productId;
if (req.body.url !== undefined) changes.url = req.body.url;
if (req.body.altText !== undefined) changes.altText = req.body.altText;
if (req.body.position !== undefined) changes.position = req.body.position;
db.media.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateMediaAsset failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateMediaAsset = handler({
method: 'PATCH',
path: '/media/:id',
auth: 'user',
params: MediaAssetParams,
body: UpdateMediaAssetBody,
async run({ params, body, user, log }) {
const updated = await db.media.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'MediaAsset not found');
log.info('MediaAsset updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/prices/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Prices: create one record.// Prices: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreatePriceBody } from '../../schemas/prices';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreatePriceBody } from '../../schemas/prices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
currency: row.currency, currency: row.currency,
amountCents: row.amountCents, amountCents: row.amountCents,
validFrom: row.validFrom, validFrom: row.validFrom,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createPrice(req, res, next) {export const createPrice = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/prices',
const body = req.body || {}; auth: 'user',
if (body.productId === undefined) { body: CreatePriceBody,
res.status(400).json({ error: 'productId is required' }); async run({ body, user, log }) {
return; const existing = await db.prices.findOne({ productId: body.productId });
} if (existing)
if (body.currency === undefined) { throw new HttpError(409, 'conflict', `A Price with productId ${body.productId} exists`);
res.status(400).json({ error: 'currency is required' }); const row = await db.prices.insert({ ...body, created_by: user.id });
return; log.info('Price created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.prices.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createPrice failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createPrice(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.productId === undefined) {
res.status(400).json({ error: 'productId is required' });
return;
}
if (body.currency === undefined) {
res.status(400).json({ error: 'currency is required' });
return;
}
db.prices.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createPrice failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createPrice = handler({
method: 'POST',
path: '/prices',
auth: 'user',
body: CreatePriceBody,
async run({ body, user, log }) {
const existing = await db.prices.findOne({ productId: body.productId });
if (existing)
throw new HttpError(409, 'conflict', `A Price with productId ${body.productId} exists`);
const row = await db.prices.insert({ ...body, created_by: user.id });
log.info('Price created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/prices/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Prices: delete one record.// Prices: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { PriceParams } from '../../schemas/prices';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { PriceParams } from '../../schemas/prices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
currency: row.currency, currency: row.currency,
amountCents: row.amountCents, amountCents: row.amountCents,
validFrom: row.validFrom, validFrom: row.validFrom,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deletePrice(req, res, next) {export const deletePrice = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/prices/:id',
db.prices.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: PriceParams,
log.error('deletePrice failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.prices.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Price not found');
if (!removed) return res.status(404).json({ error: 'Price not found' }); log.info('Price deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deletePrice(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.prices.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deletePrice failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Price not found' });
res.status(204).end();
});
});
};
export const deletePrice = handler({
method: 'DELETE',
path: '/prices/:id',
auth: 'admin',
params: PriceParams,
async run({ params, user, log }) {
const removed = await db.prices.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Price not found');
log.info('Price deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/prices/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Prices: export every record as CSV or JSON.// Prices: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportPricesQuery } from '../../schemas/prices';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportPricesQuery } from '../../schemas/prices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
currency: row.currency, currency: row.currency,
amountCents: row.amountCents, amountCents: row.amountCents,
validFrom: row.validFrom, validFrom: row.validFrom,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportPrices(req, res, next) {export const exportPrices = handler({
db.prices.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/prices/export',
log.error('exportPrices failed', err); auth: 'admin',
return next(err); query: ExportPricesQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.prices.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('prices exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'productId', 'currency', 'amountCents', 'validFrom'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'productId', 'currency', 'amountCents', 'validFrom']),
};
},
});
module.exports = function exportPrices(req, res, next) {
db.prices.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportPrices failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'productId', 'currency', 'amountCents', 'validFrom']));
});
};
export const exportPrices = handler({
method: 'GET',
path: '/prices/export',
auth: 'admin',
query: ExportPricesQuery,
async run({ query, log }) {
const rows = await db.prices.findMany({ limit: query.limit });
log.info('prices exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'productId', 'currency', 'amountCents', 'validFrom']),
};
},
});
src/handlers/prices/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Prices: read one record.// Prices: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { PriceParams } from '../../schemas/prices';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { PriceParams } from '../../schemas/prices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
currency: row.currency, currency: row.currency,
amountCents: row.amountCents, amountCents: row.amountCents,
validFrom: row.validFrom, validFrom: row.validFrom,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getPrice(req, res, next) {export const getPrice = handler({
db.prices.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/prices/:id',
log.error('getPrice failed', err); auth: 'public',
return next(err); params: PriceParams,
} async run({ params }) {
if (!row) { const row = await db.prices.findById(params.id);
res.status(404).json({ error: 'Price not found' }); if (!row) throw new HttpError(404, 'not_found', 'Price not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getPrice(req, res, next) {
db.prices.findById(req.params.id, function (err, row) {
if (err) {
log.error('getPrice failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Price not found' });
return;
}
res.json(toResponse(row));
});
};
export const getPrice = handler({
method: 'GET',
path: '/prices/:id',
auth: 'public',
params: PriceParams,
async run({ params }) {
const row = await db.prices.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Price not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/prices/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Prices: list one page.// Prices: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListPricesQuery } from '../../schemas/prices';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListPricesQuery } from '../../schemas/prices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
currency: row.currency, currency: row.currency,
amountCents: row.amountCents, amountCents: row.amountCents,
validFrom: row.validFrom, validFrom: row.validFrom,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listPrices(req, res, next) {export const listPrices = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.prices.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/prices',
if (err) { auth: 'public',
log.error('listPrices failed', err); query: ListPricesQuery,
return next(err); async run({ query }) {
} const rows = await db.prices.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listPrices(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.prices.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listPrices failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listPrices = handler({
method: 'GET',
path: '/prices',
auth: 'public',
query: ListPricesQuery,
async run({ query }) {
const rows = await db.prices.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/prices/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Prices: search by text.// Prices: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchPricesQuery } from '../../schemas/prices';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchPricesQuery } from '../../schemas/prices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
currency: row.currency, currency: row.currency,
amountCents: row.amountCents, amountCents: row.amountCents,
validFrom: row.validFrom, validFrom: row.validFrom,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchPrices(req, res, next) {export const searchPrices = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/prices/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchPricesQuery,
} async run({ query }) {
db.prices.search(q, { limit: 50 }, function (err, rows) { const rows = await db.prices.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchPrices failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchPrices(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.prices.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchPrices failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchPrices = handler({
method: 'GET',
path: '/prices/search',
auth: 'public',
query: SearchPricesQuery,
async run({ query }) {
const rows = await db.prices.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/prices/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Prices: change the fields of one record.// Prices: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { PriceParams, UpdatePriceBody } from '../../schemas/prices';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { PriceParams, UpdatePriceBody } from '../../schemas/prices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
currency: row.currency, currency: row.currency,
amountCents: row.amountCents, amountCents: row.amountCents,
validFrom: row.validFrom, validFrom: row.validFrom,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updatePrice(req, res, next) {export const updatePrice = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/prices/:id',
db.prices.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: PriceParams,
if (!row) return res.status(404).json({ error: 'Price not found' }); body: UpdatePriceBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.productId !== undefined) changes.productId = req.body.productId; const updated = await db.prices.update(params.id, { ...body, updated_by: user.id });
if (req.body.currency !== undefined) changes.currency = req.body.currency; if (!updated) throw new HttpError(404, 'not_found', 'Price not found');
if (req.body.amountCents !== undefined) changes.amountCents = req.body.amountCents; log.info('Price updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.validFrom !== undefined) changes.validFrom = req.body.validFrom; return { status: 200, body: toResponse(updated) };
db.prices.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updatePrice failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updatePrice(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.prices.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Price not found' });
const changes = {};
if (req.body.productId !== undefined) changes.productId = req.body.productId;
if (req.body.currency !== undefined) changes.currency = req.body.currency;
if (req.body.amountCents !== undefined) changes.amountCents = req.body.amountCents;
if (req.body.validFrom !== undefined) changes.validFrom = req.body.validFrom;
db.prices.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updatePrice failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updatePrice = handler({
method: 'PATCH',
path: '/prices/:id',
auth: 'user',
params: PriceParams,
body: UpdatePriceBody,
async run({ params, body, user, log }) {
const updated = await db.prices.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Price not found');
log.info('Price updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/products/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Products: create one record.// Products: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateProductBody } from '../../schemas/products';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateProductBody } from '../../schemas/products';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
name: row.name, name: row.name,
priceCents: row.priceCents, priceCents: row.priceCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createProduct(req, res, next) {export const createProduct = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/products',
const body = req.body || {}; auth: 'user',
if (body.sku === undefined) { body: CreateProductBody,
res.status(400).json({ error: 'sku is required' }); async run({ body, user, log }) {
return; const existing = await db.products.findOne({ sku: body.sku });
} if (existing)
if (body.name === undefined) { throw new HttpError(409, 'conflict', `A Product with sku ${body.sku} exists`);
res.status(400).json({ error: 'name is required' }); const row = await db.products.insert({ ...body, created_by: user.id });
return; log.info('Product created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.products.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createProduct failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createProduct(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.sku === undefined) {
res.status(400).json({ error: 'sku is required' });
return;
}
if (body.name === undefined) {
res.status(400).json({ error: 'name is required' });
return;
}
db.products.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createProduct failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createProduct = handler({
method: 'POST',
path: '/products',
auth: 'user',
body: CreateProductBody,
async run({ body, user, log }) {
const existing = await db.products.findOne({ sku: body.sku });
if (existing)
throw new HttpError(409, 'conflict', `A Product with sku ${body.sku} exists`);
const row = await db.products.insert({ ...body, created_by: user.id });
log.info('Product created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/products/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Products: delete one record.// Products: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ProductParams } from '../../schemas/products';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ProductParams } from '../../schemas/products';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
name: row.name, name: row.name,
priceCents: row.priceCents, priceCents: row.priceCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteProduct(req, res, next) {export const deleteProduct = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/products/:id',
db.products.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: ProductParams,
log.error('deleteProduct failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.products.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Product not found');
if (!removed) return res.status(404).json({ error: 'Product not found' }); log.info('Product deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteProduct(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.products.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteProduct failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Product not found' });
res.status(204).end();
});
});
};
export const deleteProduct = handler({
method: 'DELETE',
path: '/products/:id',
auth: 'admin',
params: ProductParams,
async run({ params, user, log }) {
const removed = await db.products.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Product not found');
log.info('Product deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/products/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Products: export every record as CSV or JSON.// Products: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportProductsQuery } from '../../schemas/products';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportProductsQuery } from '../../schemas/products';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
name: row.name, name: row.name,
priceCents: row.priceCents, priceCents: row.priceCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportProducts(req, res, next) {export const exportProducts = handler({
db.products.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/products/export',
log.error('exportProducts failed', err); auth: 'admin',
return next(err); query: ExportProductsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.products.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('products exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'sku', 'name', 'priceCents', 'status'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'sku', 'name', 'priceCents', 'status']),
};
},
});
module.exports = function exportProducts(req, res, next) {
db.products.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportProducts failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'sku', 'name', 'priceCents', 'status']));
});
};
export const exportProducts = handler({
method: 'GET',
path: '/products/export',
auth: 'admin',
query: ExportProductsQuery,
async run({ query, log }) {
const rows = await db.products.findMany({ limit: query.limit });
log.info('products exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'sku', 'name', 'priceCents', 'status']),
};
},
});
src/handlers/products/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Products: read one record.// Products: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ProductParams } from '../../schemas/products';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ProductParams } from '../../schemas/products';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
name: row.name, name: row.name,
priceCents: row.priceCents, priceCents: row.priceCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getProduct(req, res, next) {export const getProduct = handler({
db.products.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/products/:id',
log.error('getProduct failed', err); auth: 'public',
return next(err); params: ProductParams,
} async run({ params }) {
if (!row) { const row = await db.products.findById(params.id);
res.status(404).json({ error: 'Product not found' }); if (!row) throw new HttpError(404, 'not_found', 'Product not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getProduct(req, res, next) {
db.products.findById(req.params.id, function (err, row) {
if (err) {
log.error('getProduct failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Product not found' });
return;
}
res.json(toResponse(row));
});
};
export const getProduct = handler({
method: 'GET',
path: '/products/:id',
auth: 'public',
params: ProductParams,
async run({ params }) {
const row = await db.products.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Product not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/products/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Products: list one page.// Products: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListProductsQuery } from '../../schemas/products';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListProductsQuery } from '../../schemas/products';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
name: row.name, name: row.name,
priceCents: row.priceCents, priceCents: row.priceCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listProducts(req, res, next) {export const listProducts = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.products.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/products',
if (err) { auth: 'public',
log.error('listProducts failed', err); query: ListProductsQuery,
return next(err); async run({ query }) {
} const rows = await db.products.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listProducts(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.products.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listProducts failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listProducts = handler({
method: 'GET',
path: '/products',
auth: 'public',
query: ListProductsQuery,
async run({ query }) {
const rows = await db.products.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/products/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Products: search by text.// Products: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchProductsQuery } from '../../schemas/products';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchProductsQuery } from '../../schemas/products';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
name: row.name, name: row.name,
priceCents: row.priceCents, priceCents: row.priceCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchProducts(req, res, next) {export const searchProducts = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/products/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchProductsQuery,
} async run({ query }) {
db.products.search(q, { limit: 50 }, function (err, rows) { const rows = await db.products.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchProducts failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchProducts(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.products.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchProducts failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchProducts = handler({
method: 'GET',
path: '/products/search',
auth: 'public',
query: SearchProductsQuery,
async run({ query }) {
const rows = await db.products.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/products/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Products: change the fields of one record.// Products: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ProductParams, UpdateProductBody } from '../../schemas/products';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ProductParams, UpdateProductBody } from '../../schemas/products';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
sku: row.sku, sku: row.sku,
name: row.name, name: row.name,
priceCents: row.priceCents, priceCents: row.priceCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateProduct(req, res, next) {export const updateProduct = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/products/:id',
db.products.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: ProductParams,
if (!row) return res.status(404).json({ error: 'Product not found' }); body: UpdateProductBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.sku !== undefined) changes.sku = req.body.sku; const updated = await db.products.update(params.id, { ...body, updated_by: user.id });
if (req.body.name !== undefined) changes.name = req.body.name; if (!updated) throw new HttpError(404, 'not_found', 'Product not found');
if (req.body.priceCents !== undefined) changes.priceCents = req.body.priceCents; log.info('Product updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.status !== undefined) changes.status = req.body.status; return { status: 200, body: toResponse(updated) };
db.products.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updateProduct failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateProduct(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.products.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Product not found' });
const changes = {};
if (req.body.sku !== undefined) changes.sku = req.body.sku;
if (req.body.name !== undefined) changes.name = req.body.name;
if (req.body.priceCents !== undefined) changes.priceCents = req.body.priceCents;
if (req.body.status !== undefined) changes.status = req.body.status;
db.products.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateProduct failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateProduct = handler({
method: 'PATCH',
path: '/products/:id',
auth: 'user',
params: ProductParams,
body: UpdateProductBody,
async run({ params, body, user, log }) {
const updated = await db.products.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Product not found');
log.info('Product updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/reviews/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Reviews: create one record.// Reviews: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateProductReviewBody } from '../../schemas/reviews';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateProductReviewBody } from '../../schemas/reviews';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
rating: row.rating, rating: row.rating,
title: row.title, title: row.title,
body: row.body, body: row.body,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createProductReview(req, res, next) {export const createProductReview = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/reviews',
const body = req.body || {}; auth: 'user',
if (body.productId === undefined) { body: CreateProductReviewBody,
res.status(400).json({ error: 'productId is required' }); async run({ body, user, log }) {
return; const row = await db.reviews.insert({ ...body, created_by: user.id });
} log.info('ProductReview created', { id: row.id });
if (body.rating === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'rating is required' }); },
return;});
}
db.reviews.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createProductReview failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createProductReview(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.productId === undefined) {
res.status(400).json({ error: 'productId is required' });
return;
}
if (body.rating === undefined) {
res.status(400).json({ error: 'rating is required' });
return;
}
db.reviews.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createProductReview failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createProductReview = handler({
method: 'POST',
path: '/reviews',
auth: 'user',
body: CreateProductReviewBody,
async run({ body, user, log }) {
const row = await db.reviews.insert({ ...body, created_by: user.id });
log.info('ProductReview created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/reviews/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Reviews: delete one record.// Reviews: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ProductReviewParams } from '../../schemas/reviews';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ProductReviewParams } from '../../schemas/reviews';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
rating: row.rating, rating: row.rating,
title: row.title, title: row.title,
body: row.body, body: row.body,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteProductReview(req, res, next) {export const deleteProductReview = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/reviews/:id',
db.reviews.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: ProductReviewParams,
log.error('deleteProductReview failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.reviews.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'ProductReview not found');
if (!removed) return res.status(404).json({ error: 'ProductReview not found' }); log.info('ProductReview deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteProductReview(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.reviews.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteProductReview failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'ProductReview not found' });
res.status(204).end();
});
});
};
export const deleteProductReview = handler({
method: 'DELETE',
path: '/reviews/:id',
auth: 'admin',
params: ProductReviewParams,
async run({ params, user, log }) {
const removed = await db.reviews.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'ProductReview not found');
log.info('ProductReview deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/reviews/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Reviews: export every record as CSV or JSON.// Reviews: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportReviewsQuery } from '../../schemas/reviews';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportReviewsQuery } from '../../schemas/reviews';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
rating: row.rating, rating: row.rating,
title: row.title, title: row.title,
body: row.body, body: row.body,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportReviews(req, res, next) {export const exportReviews = handler({
db.reviews.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/reviews/export',
log.error('exportReviews failed', err); auth: 'admin',
return next(err); query: ExportReviewsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.reviews.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('reviews exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'productId', 'rating', 'title', 'body'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'productId', 'rating', 'title', 'body']),
};
},
});
module.exports = function exportReviews(req, res, next) {
db.reviews.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportReviews failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'productId', 'rating', 'title', 'body']));
});
};
export const exportReviews = handler({
method: 'GET',
path: '/reviews/export',
auth: 'admin',
query: ExportReviewsQuery,
async run({ query, log }) {
const rows = await db.reviews.findMany({ limit: query.limit });
log.info('reviews exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'productId', 'rating', 'title', 'body']),
};
},
});
src/handlers/reviews/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Reviews: read one record.// Reviews: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ProductReviewParams } from '../../schemas/reviews';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ProductReviewParams } from '../../schemas/reviews';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
rating: row.rating, rating: row.rating,
title: row.title, title: row.title,
body: row.body, body: row.body,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getProductReview(req, res, next) {export const getProductReview = handler({
db.reviews.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/reviews/:id',
log.error('getProductReview failed', err); auth: 'public',
return next(err); params: ProductReviewParams,
} async run({ params }) {
if (!row) { const row = await db.reviews.findById(params.id);
res.status(404).json({ error: 'ProductReview not found' }); if (!row) throw new HttpError(404, 'not_found', 'ProductReview not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getProductReview(req, res, next) {
db.reviews.findById(req.params.id, function (err, row) {
if (err) {
log.error('getProductReview failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'ProductReview not found' });
return;
}
res.json(toResponse(row));
});
};
export const getProductReview = handler({
method: 'GET',
path: '/reviews/:id',
auth: 'public',
params: ProductReviewParams,
async run({ params }) {
const row = await db.reviews.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'ProductReview not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/reviews/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Reviews: list one page.// Reviews: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListReviewsQuery } from '../../schemas/reviews';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListReviewsQuery } from '../../schemas/reviews';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
rating: row.rating, rating: row.rating,
title: row.title, title: row.title,
body: row.body, body: row.body,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listReviews(req, res, next) {export const listReviews = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.reviews.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/reviews',
if (err) { auth: 'public',
log.error('listReviews failed', err); query: ListReviewsQuery,
return next(err); async run({ query }) {
} const rows = await db.reviews.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listReviews(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.reviews.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listReviews failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listReviews = handler({
method: 'GET',
path: '/reviews',
auth: 'public',
query: ListReviewsQuery,
async run({ query }) {
const rows = await db.reviews.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/reviews/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Reviews: search by text.// Reviews: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchReviewsQuery } from '../../schemas/reviews';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchReviewsQuery } from '../../schemas/reviews';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
rating: row.rating, rating: row.rating,
title: row.title, title: row.title,
body: row.body, body: row.body,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchReviews(req, res, next) {export const searchReviews = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/reviews/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchReviewsQuery,
} async run({ query }) {
db.reviews.search(q, { limit: 50 }, function (err, rows) { const rows = await db.reviews.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchReviews failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchReviews(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.reviews.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchReviews failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchReviews = handler({
method: 'GET',
path: '/reviews/search',
auth: 'public',
query: SearchReviewsQuery,
async run({ query }) {
const rows = await db.reviews.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/reviews/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Reviews: change the fields of one record.// Reviews: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ProductReviewParams, UpdateProductReviewBody } from '../../schemas/reviews';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ProductReviewParams, UpdateProductReviewBody } from '../../schemas/reviews';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
rating: row.rating, rating: row.rating,
title: row.title, title: row.title,
body: row.body, body: row.body,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateProductReview(req, res, next) {export const updateProductReview = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/reviews/:id',
db.reviews.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: ProductReviewParams,
if (!row) return res.status(404).json({ error: 'ProductReview not found' }); body: UpdateProductReviewBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.productId !== undefined) changes.productId = req.body.productId; const updated = await db.reviews.update(params.id, { ...body, updated_by: user.id });
if (req.body.rating !== undefined) changes.rating = req.body.rating; if (!updated) throw new HttpError(404, 'not_found', 'ProductReview not found');
if (req.body.title !== undefined) changes.title = req.body.title; log.info('ProductReview updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.body !== undefined) changes.body = req.body.body; return { status: 200, body: toResponse(updated) };
db.reviews.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updateProductReview failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateProductReview(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.reviews.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'ProductReview not found' });
const changes = {};
if (req.body.productId !== undefined) changes.productId = req.body.productId;
if (req.body.rating !== undefined) changes.rating = req.body.rating;
if (req.body.title !== undefined) changes.title = req.body.title;
if (req.body.body !== undefined) changes.body = req.body.body;
db.reviews.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateProductReview failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateProductReview = handler({
method: 'PATCH',
path: '/reviews/:id',
auth: 'user',
params: ProductReviewParams,
body: UpdateProductReviewBody,
async run({ params, body, user, log }) {
const updated = await db.reviews.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'ProductReview not found');
log.info('ProductReview updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/variants/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Variants: create one record.// Variants: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateVariantBody } from '../../schemas/variants';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateVariantBody } from '../../schemas/variants';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
sku: row.sku, sku: row.sku,
options: row.options, options: row.options,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createVariant(req, res, next) {export const createVariant = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/variants',
const body = req.body || {}; auth: 'user',
if (body.productId === undefined) { body: CreateVariantBody,
res.status(400).json({ error: 'productId is required' }); async run({ body, user, log }) {
return; const existing = await db.variants.findOne({ sku: body.sku });
} if (existing)
if (body.sku === undefined) { throw new HttpError(409, 'conflict', `A Variant with sku ${body.sku} exists`);
res.status(400).json({ error: 'sku is required' }); const row = await db.variants.insert({ ...body, created_by: user.id });
return; log.info('Variant created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.variants.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createVariant failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createVariant(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.productId === undefined) {
res.status(400).json({ error: 'productId is required' });
return;
}
if (body.sku === undefined) {
res.status(400).json({ error: 'sku is required' });
return;
}
db.variants.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createVariant failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createVariant = handler({
method: 'POST',
path: '/variants',
auth: 'user',
body: CreateVariantBody,
async run({ body, user, log }) {
const existing = await db.variants.findOne({ sku: body.sku });
if (existing)
throw new HttpError(409, 'conflict', `A Variant with sku ${body.sku} exists`);
const row = await db.variants.insert({ ...body, created_by: user.id });
log.info('Variant created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/variants/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Variants: delete one record.// Variants: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { VariantParams } from '../../schemas/variants';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { VariantParams } from '../../schemas/variants';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
sku: row.sku, sku: row.sku,
options: row.options, options: row.options,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteVariant(req, res, next) {export const deleteVariant = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/variants/:id',
db.variants.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: VariantParams,
log.error('deleteVariant failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.variants.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Variant not found');
if (!removed) return res.status(404).json({ error: 'Variant not found' }); log.info('Variant deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteVariant(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.variants.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteVariant failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Variant not found' });
res.status(204).end();
});
});
};
export const deleteVariant = handler({
method: 'DELETE',
path: '/variants/:id',
auth: 'admin',
params: VariantParams,
async run({ params, user, log }) {
const removed = await db.variants.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Variant not found');
log.info('Variant deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/variants/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Variants: export every record as CSV or JSON.// Variants: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportVariantsQuery } from '../../schemas/variants';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportVariantsQuery } from '../../schemas/variants';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
sku: row.sku, sku: row.sku,
options: row.options, options: row.options,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportVariants(req, res, next) {export const exportVariants = handler({
db.variants.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/variants/export',
log.error('exportVariants failed', err); auth: 'admin',
return next(err); query: ExportVariantsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.variants.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('variants exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'productId', 'sku', 'options'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'productId', 'sku', 'options']),
};
},
});
module.exports = function exportVariants(req, res, next) {
db.variants.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportVariants failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'productId', 'sku', 'options']));
});
};
export const exportVariants = handler({
method: 'GET',
path: '/variants/export',
auth: 'admin',
query: ExportVariantsQuery,
async run({ query, log }) {
const rows = await db.variants.findMany({ limit: query.limit });
log.info('variants exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'productId', 'sku', 'options']),
};
},
});
src/handlers/variants/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Variants: read one record.// Variants: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { VariantParams } from '../../schemas/variants';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { VariantParams } from '../../schemas/variants';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
sku: row.sku, sku: row.sku,
options: row.options, options: row.options,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getVariant(req, res, next) {export const getVariant = handler({
db.variants.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/variants/:id',
log.error('getVariant failed', err); auth: 'public',
return next(err); params: VariantParams,
} async run({ params }) {
if (!row) { const row = await db.variants.findById(params.id);
res.status(404).json({ error: 'Variant not found' }); if (!row) throw new HttpError(404, 'not_found', 'Variant not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getVariant(req, res, next) {
db.variants.findById(req.params.id, function (err, row) {
if (err) {
log.error('getVariant failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Variant not found' });
return;
}
res.json(toResponse(row));
});
};
export const getVariant = handler({
method: 'GET',
path: '/variants/:id',
auth: 'public',
params: VariantParams,
async run({ params }) {
const row = await db.variants.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Variant not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/variants/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Variants: list one page.// Variants: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListVariantsQuery } from '../../schemas/variants';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListVariantsQuery } from '../../schemas/variants';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
sku: row.sku, sku: row.sku,
options: row.options, options: row.options,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listVariants(req, res, next) {export const listVariants = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.variants.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/variants',
if (err) { auth: 'public',
log.error('listVariants failed', err); query: ListVariantsQuery,
return next(err); async run({ query }) {
} const rows = await db.variants.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listVariants(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.variants.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listVariants failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listVariants = handler({
method: 'GET',
path: '/variants',
auth: 'public',
query: ListVariantsQuery,
async run({ query }) {
const rows = await db.variants.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/variants/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Variants: search by text.// Variants: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchVariantsQuery } from '../../schemas/variants';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchVariantsQuery } from '../../schemas/variants';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
sku: row.sku, sku: row.sku,
options: row.options, options: row.options,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchVariants(req, res, next) {export const searchVariants = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/variants/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchVariantsQuery,
} async run({ query }) {
db.variants.search(q, { limit: 50 }, function (err, rows) { const rows = await db.variants.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchVariants failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchVariants(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.variants.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchVariants failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchVariants = handler({
method: 'GET',
path: '/variants/search',
auth: 'public',
query: SearchVariantsQuery,
async run({ query }) {
const rows = await db.variants.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/variants/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Variants: change the fields of one record.// Variants: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { VariantParams, UpdateVariantBody } from '../../schemas/variants';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { VariantParams, UpdateVariantBody } from '../../schemas/variants';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
productId: row.productId, productId: row.productId,
sku: row.sku, sku: row.sku,
options: row.options, options: row.options,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateVariant(req, res, next) {export const updateVariant = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/variants/:id',
db.variants.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: VariantParams,
if (!row) return res.status(404).json({ error: 'Variant not found' }); body: UpdateVariantBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.productId !== undefined) changes.productId = req.body.productId; const updated = await db.variants.update(params.id, { ...body, updated_by: user.id });
if (req.body.sku !== undefined) changes.sku = req.body.sku; if (!updated) throw new HttpError(404, 'not_found', 'Variant not found');
if (req.body.options !== undefined) changes.options = req.body.options; log.info('Variant updated', { id: updated.id, fields: Object.keys(body) });
db.variants.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateVariant failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateVariant(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.variants.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Variant not found' });
const changes = {};
if (req.body.productId !== undefined) changes.productId = req.body.productId;
if (req.body.sku !== undefined) changes.sku = req.body.sku;
if (req.body.options !== undefined) changes.options = req.body.options;
db.variants.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateVariant failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateVariant = handler({
method: 'PATCH',
path: '/variants/:id',
auth: 'user',
params: VariantParams,
body: UpdateVariantBody,
async run({ params, body, user, log }) {
const updated = await db.variants.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Variant not found');
log.info('Variant updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});

Order and payment handlers

The handlers of carts, orders, payments, refunds, shipments, invoices, coupons and returns move to the typed form, with the same three behaviour changes as the catalog.

src/tax/rates.ts holds the tax rate of each region and category for each financial year. Checkout read it from the finance service for every order; now the table ships with the API and finance updates it once a year. Its rows are data: check the shape and taxRate, not each rate.

src/handlers/carts/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Carts: create one record.// Carts: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateCartBody } from '../../schemas/carts';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateCartBody } from '../../schemas/carts';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
currency: row.currency, currency: row.currency,
lines: row.lines, lines: row.lines,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createCart(req, res, next) {export const createCart = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/carts',
const body = req.body || {}; auth: 'user',
if (body.customerId === undefined) { body: CreateCartBody,
res.status(400).json({ error: 'customerId is required' }); async run({ body, user, log }) {
return; const row = await db.carts.insert({ ...body, created_by: user.id });
} log.info('Cart created', { id: row.id });
if (body.currency === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'currency is required' }); },
return;});
}
db.carts.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createCart failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createCart(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
if (body.currency === undefined) {
res.status(400).json({ error: 'currency is required' });
return;
}
db.carts.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createCart failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createCart = handler({
method: 'POST',
path: '/carts',
auth: 'user',
body: CreateCartBody,
async run({ body, user, log }) {
const row = await db.carts.insert({ ...body, created_by: user.id });
log.info('Cart created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/carts/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Carts: delete one record.// Carts: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CartParams } from '../../schemas/carts';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CartParams } from '../../schemas/carts';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
currency: row.currency, currency: row.currency,
lines: row.lines, lines: row.lines,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteCart(req, res, next) {export const deleteCart = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/carts/:id',
db.carts.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: CartParams,
log.error('deleteCart failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.carts.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Cart not found');
if (!removed) return res.status(404).json({ error: 'Cart not found' }); log.info('Cart deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteCart(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.carts.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteCart failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Cart not found' });
res.status(204).end();
});
});
};
export const deleteCart = handler({
method: 'DELETE',
path: '/carts/:id',
auth: 'admin',
params: CartParams,
async run({ params, user, log }) {
const removed = await db.carts.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Cart not found');
log.info('Cart deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/carts/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Carts: export every record as CSV or JSON.// Carts: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportCartsQuery } from '../../schemas/carts';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportCartsQuery } from '../../schemas/carts';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
currency: row.currency, currency: row.currency,
lines: row.lines, lines: row.lines,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportCarts(req, res, next) {export const exportCarts = handler({
db.carts.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/carts/export',
log.error('exportCarts failed', err); auth: 'admin',
return next(err); query: ExportCartsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.carts.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('carts exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'currency', 'lines'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'currency', 'lines']),
};
},
});
module.exports = function exportCarts(req, res, next) {
db.carts.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportCarts failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'currency', 'lines']));
});
};
export const exportCarts = handler({
method: 'GET',
path: '/carts/export',
auth: 'admin',
query: ExportCartsQuery,
async run({ query, log }) {
const rows = await db.carts.findMany({ limit: query.limit });
log.info('carts exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'currency', 'lines']),
};
},
});
src/handlers/carts/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Carts: read one record.// Carts: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CartParams } from '../../schemas/carts';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CartParams } from '../../schemas/carts';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
currency: row.currency, currency: row.currency,
lines: row.lines, lines: row.lines,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getCart(req, res, next) {export const getCart = handler({
db.carts.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/carts/:id',
log.error('getCart failed', err); auth: 'public',
return next(err); params: CartParams,
} async run({ params }) {
if (!row) { const row = await db.carts.findById(params.id);
res.status(404).json({ error: 'Cart not found' }); if (!row) throw new HttpError(404, 'not_found', 'Cart not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getCart(req, res, next) {
db.carts.findById(req.params.id, function (err, row) {
if (err) {
log.error('getCart failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Cart not found' });
return;
}
res.json(toResponse(row));
});
};
export const getCart = handler({
method: 'GET',
path: '/carts/:id',
auth: 'public',
params: CartParams,
async run({ params }) {
const row = await db.carts.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Cart not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/carts/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Carts: list one page.// Carts: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListCartsQuery } from '../../schemas/carts';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListCartsQuery } from '../../schemas/carts';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
currency: row.currency, currency: row.currency,
lines: row.lines, lines: row.lines,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listCarts(req, res, next) {export const listCarts = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.carts.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/carts',
if (err) { auth: 'public',
log.error('listCarts failed', err); query: ListCartsQuery,
return next(err); async run({ query }) {
} const rows = await db.carts.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listCarts(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.carts.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listCarts failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listCarts = handler({
method: 'GET',
path: '/carts',
auth: 'public',
query: ListCartsQuery,
async run({ query }) {
const rows = await db.carts.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/carts/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Carts: search by text.// Carts: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchCartsQuery } from '../../schemas/carts';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchCartsQuery } from '../../schemas/carts';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
currency: row.currency, currency: row.currency,
lines: row.lines, lines: row.lines,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchCarts(req, res, next) {export const searchCarts = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/carts/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchCartsQuery,
} async run({ query }) {
db.carts.search(q, { limit: 50 }, function (err, rows) { const rows = await db.carts.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchCarts failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchCarts(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.carts.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchCarts failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchCarts = handler({
method: 'GET',
path: '/carts/search',
auth: 'public',
query: SearchCartsQuery,
async run({ query }) {
const rows = await db.carts.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/carts/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Carts: change the fields of one record.// Carts: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CartParams, UpdateCartBody } from '../../schemas/carts';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CartParams, UpdateCartBody } from '../../schemas/carts';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
currency: row.currency, currency: row.currency,
lines: row.lines, lines: row.lines,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateCart(req, res, next) {export const updateCart = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/carts/:id',
db.carts.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: CartParams,
if (!row) return res.status(404).json({ error: 'Cart not found' }); body: UpdateCartBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; const updated = await db.carts.update(params.id, { ...body, updated_by: user.id });
if (req.body.currency !== undefined) changes.currency = req.body.currency; if (!updated) throw new HttpError(404, 'not_found', 'Cart not found');
if (req.body.lines !== undefined) changes.lines = req.body.lines; log.info('Cart updated', { id: updated.id, fields: Object.keys(body) });
db.carts.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateCart failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateCart(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.carts.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Cart not found' });
const changes = {};
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.currency !== undefined) changes.currency = req.body.currency;
if (req.body.lines !== undefined) changes.lines = req.body.lines;
db.carts.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateCart failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateCart = handler({
method: 'PATCH',
path: '/carts/:id',
auth: 'user',
params: CartParams,
body: UpdateCartBody,
async run({ params, body, user, log }) {
const updated = await db.carts.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Cart not found');
log.info('Cart updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/coupons/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Coupons: create one record.// Coupons: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateCouponBody } from '../../schemas/coupons';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateCouponBody } from '../../schemas/coupons';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
percentOff: row.percentOff, percentOff: row.percentOff,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createCoupon(req, res, next) {export const createCoupon = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/coupons',
const body = req.body || {}; auth: 'user',
if (body.code === undefined) { body: CreateCouponBody,
res.status(400).json({ error: 'code is required' }); async run({ body, user, log }) {
return; const existing = await db.coupons.findOne({ code: body.code });
} if (existing)
if (body.percentOff === undefined) { throw new HttpError(409, 'conflict', `A Coupon with code ${body.code} exists`);
res.status(400).json({ error: 'percentOff is required' }); const row = await db.coupons.insert({ ...body, created_by: user.id });
return; log.info('Coupon created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.coupons.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createCoupon failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createCoupon(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.code === undefined) {
res.status(400).json({ error: 'code is required' });
return;
}
if (body.percentOff === undefined) {
res.status(400).json({ error: 'percentOff is required' });
return;
}
db.coupons.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createCoupon failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createCoupon = handler({
method: 'POST',
path: '/coupons',
auth: 'user',
body: CreateCouponBody,
async run({ body, user, log }) {
const existing = await db.coupons.findOne({ code: body.code });
if (existing)
throw new HttpError(409, 'conflict', `A Coupon with code ${body.code} exists`);
const row = await db.coupons.insert({ ...body, created_by: user.id });
log.info('Coupon created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/coupons/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Coupons: delete one record.// Coupons: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CouponParams } from '../../schemas/coupons';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CouponParams } from '../../schemas/coupons';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
percentOff: row.percentOff, percentOff: row.percentOff,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteCoupon(req, res, next) {export const deleteCoupon = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/coupons/:id',
db.coupons.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: CouponParams,
log.error('deleteCoupon failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.coupons.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Coupon not found');
if (!removed) return res.status(404).json({ error: 'Coupon not found' }); log.info('Coupon deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteCoupon(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.coupons.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteCoupon failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Coupon not found' });
res.status(204).end();
});
});
};
export const deleteCoupon = handler({
method: 'DELETE',
path: '/coupons/:id',
auth: 'admin',
params: CouponParams,
async run({ params, user, log }) {
const removed = await db.coupons.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Coupon not found');
log.info('Coupon deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/coupons/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Coupons: export every record as CSV or JSON.// Coupons: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportCouponsQuery } from '../../schemas/coupons';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportCouponsQuery } from '../../schemas/coupons';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
percentOff: row.percentOff, percentOff: row.percentOff,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportCoupons(req, res, next) {export const exportCoupons = handler({
db.coupons.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/coupons/export',
log.error('exportCoupons failed', err); auth: 'admin',
return next(err); query: ExportCouponsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.coupons.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('coupons exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'code', 'percentOff', 'expiresAt'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'code', 'percentOff', 'expiresAt']),
};
},
});
module.exports = function exportCoupons(req, res, next) {
db.coupons.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportCoupons failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'code', 'percentOff', 'expiresAt']));
});
};
export const exportCoupons = handler({
method: 'GET',
path: '/coupons/export',
auth: 'admin',
query: ExportCouponsQuery,
async run({ query, log }) {
const rows = await db.coupons.findMany({ limit: query.limit });
log.info('coupons exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'code', 'percentOff', 'expiresAt']),
};
},
});
src/handlers/coupons/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Coupons: read one record.// Coupons: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CouponParams } from '../../schemas/coupons';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CouponParams } from '../../schemas/coupons';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
percentOff: row.percentOff, percentOff: row.percentOff,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getCoupon(req, res, next) {export const getCoupon = handler({
db.coupons.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/coupons/:id',
log.error('getCoupon failed', err); auth: 'public',
return next(err); params: CouponParams,
} async run({ params }) {
if (!row) { const row = await db.coupons.findById(params.id);
res.status(404).json({ error: 'Coupon not found' }); if (!row) throw new HttpError(404, 'not_found', 'Coupon not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getCoupon(req, res, next) {
db.coupons.findById(req.params.id, function (err, row) {
if (err) {
log.error('getCoupon failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Coupon not found' });
return;
}
res.json(toResponse(row));
});
};
export const getCoupon = handler({
method: 'GET',
path: '/coupons/:id',
auth: 'public',
params: CouponParams,
async run({ params }) {
const row = await db.coupons.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Coupon not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/coupons/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Coupons: list one page.// Coupons: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListCouponsQuery } from '../../schemas/coupons';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListCouponsQuery } from '../../schemas/coupons';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
percentOff: row.percentOff, percentOff: row.percentOff,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listCoupons(req, res, next) {export const listCoupons = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.coupons.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/coupons',
if (err) { auth: 'public',
log.error('listCoupons failed', err); query: ListCouponsQuery,
return next(err); async run({ query }) {
} const rows = await db.coupons.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listCoupons(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.coupons.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listCoupons failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listCoupons = handler({
method: 'GET',
path: '/coupons',
auth: 'public',
query: ListCouponsQuery,
async run({ query }) {
const rows = await db.coupons.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/coupons/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Coupons: search by text.// Coupons: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchCouponsQuery } from '../../schemas/coupons';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchCouponsQuery } from '../../schemas/coupons';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
percentOff: row.percentOff, percentOff: row.percentOff,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchCoupons(req, res, next) {export const searchCoupons = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/coupons/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchCouponsQuery,
} async run({ query }) {
db.coupons.search(q, { limit: 50 }, function (err, rows) { const rows = await db.coupons.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchCoupons failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchCoupons(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.coupons.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchCoupons failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchCoupons = handler({
method: 'GET',
path: '/coupons/search',
auth: 'public',
query: SearchCouponsQuery,
async run({ query }) {
const rows = await db.coupons.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/coupons/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Coupons: change the fields of one record.// Coupons: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CouponParams, UpdateCouponBody } from '../../schemas/coupons';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CouponParams, UpdateCouponBody } from '../../schemas/coupons';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
percentOff: row.percentOff, percentOff: row.percentOff,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateCoupon(req, res, next) {export const updateCoupon = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/coupons/:id',
db.coupons.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: CouponParams,
if (!row) return res.status(404).json({ error: 'Coupon not found' }); body: UpdateCouponBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.code !== undefined) changes.code = req.body.code; const updated = await db.coupons.update(params.id, { ...body, updated_by: user.id });
if (req.body.percentOff !== undefined) changes.percentOff = req.body.percentOff; if (!updated) throw new HttpError(404, 'not_found', 'Coupon not found');
if (req.body.expiresAt !== undefined) changes.expiresAt = req.body.expiresAt; log.info('Coupon updated', { id: updated.id, fields: Object.keys(body) });
db.coupons.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateCoupon failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateCoupon(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.coupons.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Coupon not found' });
const changes = {};
if (req.body.code !== undefined) changes.code = req.body.code;
if (req.body.percentOff !== undefined) changes.percentOff = req.body.percentOff;
if (req.body.expiresAt !== undefined) changes.expiresAt = req.body.expiresAt;
db.coupons.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateCoupon failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateCoupon = handler({
method: 'PATCH',
path: '/coupons/:id',
auth: 'user',
params: CouponParams,
body: UpdateCouponBody,
async run({ params, body, user, log }) {
const updated = await db.coupons.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Coupon not found');
log.info('Coupon updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/giftCards/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// GiftCards: create one record.// GiftCards: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateGiftCardBody } from '../../schemas/giftCards';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateGiftCardBody } from '../../schemas/giftCards';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
balanceCents: row.balanceCents, balanceCents: row.balanceCents,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createGiftCard(req, res, next) {export const createGiftCard = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/giftCards',
const body = req.body || {}; auth: 'user',
if (body.code === undefined) { body: CreateGiftCardBody,
res.status(400).json({ error: 'code is required' }); async run({ body, user, log }) {
return; const existing = await db.giftCards.findOne({ code: body.code });
} if (existing)
if (body.balanceCents === undefined) { throw new HttpError(409, 'conflict', `A GiftCard with code ${body.code} exists`);
res.status(400).json({ error: 'balanceCents is required' }); const row = await db.giftCards.insert({ ...body, created_by: user.id });
return; log.info('GiftCard created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.giftCards.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createGiftCard failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createGiftCard(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.code === undefined) {
res.status(400).json({ error: 'code is required' });
return;
}
if (body.balanceCents === undefined) {
res.status(400).json({ error: 'balanceCents is required' });
return;
}
db.giftCards.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createGiftCard failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createGiftCard = handler({
method: 'POST',
path: '/giftCards',
auth: 'user',
body: CreateGiftCardBody,
async run({ body, user, log }) {
const existing = await db.giftCards.findOne({ code: body.code });
if (existing)
throw new HttpError(409, 'conflict', `A GiftCard with code ${body.code} exists`);
const row = await db.giftCards.insert({ ...body, created_by: user.id });
log.info('GiftCard created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/giftCards/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// GiftCards: delete one record.// GiftCards: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { GiftCardParams } from '../../schemas/giftCards';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { GiftCardParams } from '../../schemas/giftCards';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
balanceCents: row.balanceCents, balanceCents: row.balanceCents,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteGiftCard(req, res, next) {export const deleteGiftCard = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/giftCards/:id',
db.giftCards.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: GiftCardParams,
log.error('deleteGiftCard failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.giftCards.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'GiftCard not found');
if (!removed) return res.status(404).json({ error: 'GiftCard not found' }); log.info('GiftCard deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteGiftCard(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.giftCards.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteGiftCard failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'GiftCard not found' });
res.status(204).end();
});
});
};
export const deleteGiftCard = handler({
method: 'DELETE',
path: '/giftCards/:id',
auth: 'admin',
params: GiftCardParams,
async run({ params, user, log }) {
const removed = await db.giftCards.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'GiftCard not found');
log.info('GiftCard deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/giftCards/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// GiftCards: export every record as CSV or JSON.// GiftCards: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportGiftCardsQuery } from '../../schemas/giftCards';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportGiftCardsQuery } from '../../schemas/giftCards';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
balanceCents: row.balanceCents, balanceCents: row.balanceCents,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportGiftCards(req, res, next) {export const exportGiftCards = handler({
db.giftCards.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/giftCards/export',
log.error('exportGiftCards failed', err); auth: 'admin',
return next(err); query: ExportGiftCardsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.giftCards.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('giftCards exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'code', 'balanceCents', 'currency'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'code', 'balanceCents', 'currency']),
};
},
});
module.exports = function exportGiftCards(req, res, next) {
db.giftCards.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportGiftCards failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'code', 'balanceCents', 'currency']));
});
};
export const exportGiftCards = handler({
method: 'GET',
path: '/giftCards/export',
auth: 'admin',
query: ExportGiftCardsQuery,
async run({ query, log }) {
const rows = await db.giftCards.findMany({ limit: query.limit });
log.info('giftCards exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'code', 'balanceCents', 'currency']),
};
},
});
src/handlers/giftCards/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// GiftCards: read one record.// GiftCards: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { GiftCardParams } from '../../schemas/giftCards';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { GiftCardParams } from '../../schemas/giftCards';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
balanceCents: row.balanceCents, balanceCents: row.balanceCents,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getGiftCard(req, res, next) {export const getGiftCard = handler({
db.giftCards.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/giftCards/:id',
log.error('getGiftCard failed', err); auth: 'public',
return next(err); params: GiftCardParams,
} async run({ params }) {
if (!row) { const row = await db.giftCards.findById(params.id);
res.status(404).json({ error: 'GiftCard not found' }); if (!row) throw new HttpError(404, 'not_found', 'GiftCard not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getGiftCard(req, res, next) {
db.giftCards.findById(req.params.id, function (err, row) {
if (err) {
log.error('getGiftCard failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'GiftCard not found' });
return;
}
res.json(toResponse(row));
});
};
export const getGiftCard = handler({
method: 'GET',
path: '/giftCards/:id',
auth: 'public',
params: GiftCardParams,
async run({ params }) {
const row = await db.giftCards.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'GiftCard not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/giftCards/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// GiftCards: list one page.// GiftCards: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListGiftCardsQuery } from '../../schemas/giftCards';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListGiftCardsQuery } from '../../schemas/giftCards';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
balanceCents: row.balanceCents, balanceCents: row.balanceCents,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listGiftCards(req, res, next) {export const listGiftCards = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.giftCards.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/giftCards',
if (err) { auth: 'public',
log.error('listGiftCards failed', err); query: ListGiftCardsQuery,
return next(err); async run({ query }) {
} const rows = await db.giftCards.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listGiftCards(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.giftCards.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listGiftCards failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listGiftCards = handler({
method: 'GET',
path: '/giftCards',
auth: 'public',
query: ListGiftCardsQuery,
async run({ query }) {
const rows = await db.giftCards.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/giftCards/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// GiftCards: search by text.// GiftCards: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchGiftCardsQuery } from '../../schemas/giftCards';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchGiftCardsQuery } from '../../schemas/giftCards';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
balanceCents: row.balanceCents, balanceCents: row.balanceCents,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchGiftCards(req, res, next) {export const searchGiftCards = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/giftCards/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchGiftCardsQuery,
} async run({ query }) {
db.giftCards.search(q, { limit: 50 }, function (err, rows) { const rows = await db.giftCards.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchGiftCards failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchGiftCards(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.giftCards.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchGiftCards failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchGiftCards = handler({
method: 'GET',
path: '/giftCards/search',
auth: 'public',
query: SearchGiftCardsQuery,
async run({ query }) {
const rows = await db.giftCards.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/giftCards/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// GiftCards: change the fields of one record.// GiftCards: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { GiftCardParams, UpdateGiftCardBody } from '../../schemas/giftCards';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { GiftCardParams, UpdateGiftCardBody } from '../../schemas/giftCards';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
code: row.code, code: row.code,
balanceCents: row.balanceCents, balanceCents: row.balanceCents,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateGiftCard(req, res, next) {export const updateGiftCard = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/giftCards/:id',
db.giftCards.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: GiftCardParams,
if (!row) return res.status(404).json({ error: 'GiftCard not found' }); body: UpdateGiftCardBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.code !== undefined) changes.code = req.body.code; const updated = await db.giftCards.update(params.id, { ...body, updated_by: user.id });
if (req.body.balanceCents !== undefined) changes.balanceCents = req.body.balanceCents; if (!updated) throw new HttpError(404, 'not_found', 'GiftCard not found');
if (req.body.currency !== undefined) changes.currency = req.body.currency; log.info('GiftCard updated', { id: updated.id, fields: Object.keys(body) });
db.giftCards.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateGiftCard failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateGiftCard(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.giftCards.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'GiftCard not found' });
const changes = {};
if (req.body.code !== undefined) changes.code = req.body.code;
if (req.body.balanceCents !== undefined) changes.balanceCents = req.body.balanceCents;
if (req.body.currency !== undefined) changes.currency = req.body.currency;
db.giftCards.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateGiftCard failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateGiftCard = handler({
method: 'PATCH',
path: '/giftCards/:id',
auth: 'user',
params: GiftCardParams,
body: UpdateGiftCardBody,
async run({ params, body, user, log }) {
const updated = await db.giftCards.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'GiftCard not found');
log.info('GiftCard updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/invoices/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Invoices: create one record.// Invoices: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateInvoiceBody } from '../../schemas/invoices';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateInvoiceBody } from '../../schemas/invoices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
orderId: row.orderId, orderId: row.orderId,
dueAt: row.dueAt, dueAt: row.dueAt,
totalCents: row.totalCents, totalCents: row.totalCents,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createInvoice(req, res, next) {export const createInvoice = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/invoices',
const body = req.body || {}; auth: 'user',
if (body.number === undefined) { body: CreateInvoiceBody,
res.status(400).json({ error: 'number is required' }); async run({ body, user, log }) {
return; const existing = await db.invoices.findOne({ number: body.number });
} if (existing)
if (body.orderId === undefined) { throw new HttpError(409, 'conflict', `A Invoice with number ${body.number} exists`);
res.status(400).json({ error: 'orderId is required' }); const row = await db.invoices.insert({ ...body, created_by: user.id });
return; log.info('Invoice created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.invoices.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createInvoice failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createInvoice(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.number === undefined) {
res.status(400).json({ error: 'number is required' });
return;
}
if (body.orderId === undefined) {
res.status(400).json({ error: 'orderId is required' });
return;
}
db.invoices.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createInvoice failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createInvoice = handler({
method: 'POST',
path: '/invoices',
auth: 'user',
body: CreateInvoiceBody,
async run({ body, user, log }) {
const existing = await db.invoices.findOne({ number: body.number });
if (existing)
throw new HttpError(409, 'conflict', `A Invoice with number ${body.number} exists`);
const row = await db.invoices.insert({ ...body, created_by: user.id });
log.info('Invoice created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/invoices/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Invoices: delete one record.// Invoices: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { InvoiceParams } from '../../schemas/invoices';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { InvoiceParams } from '../../schemas/invoices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
orderId: row.orderId, orderId: row.orderId,
dueAt: row.dueAt, dueAt: row.dueAt,
totalCents: row.totalCents, totalCents: row.totalCents,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteInvoice(req, res, next) {export const deleteInvoice = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/invoices/:id',
db.invoices.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: InvoiceParams,
log.error('deleteInvoice failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.invoices.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Invoice not found');
if (!removed) return res.status(404).json({ error: 'Invoice not found' }); log.info('Invoice deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteInvoice(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.invoices.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteInvoice failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Invoice not found' });
res.status(204).end();
});
});
};
export const deleteInvoice = handler({
method: 'DELETE',
path: '/invoices/:id',
auth: 'admin',
params: InvoiceParams,
async run({ params, user, log }) {
const removed = await db.invoices.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Invoice not found');
log.info('Invoice deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/invoices/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Invoices: export every record as CSV or JSON.// Invoices: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportInvoicesQuery } from '../../schemas/invoices';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportInvoicesQuery } from '../../schemas/invoices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
orderId: row.orderId, orderId: row.orderId,
dueAt: row.dueAt, dueAt: row.dueAt,
totalCents: row.totalCents, totalCents: row.totalCents,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportInvoices(req, res, next) {export const exportInvoices = handler({
db.invoices.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/invoices/export',
log.error('exportInvoices failed', err); auth: 'admin',
return next(err); query: ExportInvoicesQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.invoices.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('invoices exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'number', 'orderId', 'dueAt', 'totalCents'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'number', 'orderId', 'dueAt', 'totalCents']),
};
},
});
module.exports = function exportInvoices(req, res, next) {
db.invoices.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportInvoices failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'number', 'orderId', 'dueAt', 'totalCents']));
});
};
export const exportInvoices = handler({
method: 'GET',
path: '/invoices/export',
auth: 'admin',
query: ExportInvoicesQuery,
async run({ query, log }) {
const rows = await db.invoices.findMany({ limit: query.limit });
log.info('invoices exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'number', 'orderId', 'dueAt', 'totalCents']),
};
},
});
src/handlers/invoices/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Invoices: read one record.// Invoices: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { InvoiceParams } from '../../schemas/invoices';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { InvoiceParams } from '../../schemas/invoices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
orderId: row.orderId, orderId: row.orderId,
dueAt: row.dueAt, dueAt: row.dueAt,
totalCents: row.totalCents, totalCents: row.totalCents,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getInvoice(req, res, next) {export const getInvoice = handler({
db.invoices.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/invoices/:id',
log.error('getInvoice failed', err); auth: 'public',
return next(err); params: InvoiceParams,
} async run({ params }) {
if (!row) { const row = await db.invoices.findById(params.id);
res.status(404).json({ error: 'Invoice not found' }); if (!row) throw new HttpError(404, 'not_found', 'Invoice not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getInvoice(req, res, next) {
db.invoices.findById(req.params.id, function (err, row) {
if (err) {
log.error('getInvoice failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Invoice not found' });
return;
}
res.json(toResponse(row));
});
};
export const getInvoice = handler({
method: 'GET',
path: '/invoices/:id',
auth: 'public',
params: InvoiceParams,
async run({ params }) {
const row = await db.invoices.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Invoice not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/invoices/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Invoices: list one page.// Invoices: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListInvoicesQuery } from '../../schemas/invoices';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListInvoicesQuery } from '../../schemas/invoices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
orderId: row.orderId, orderId: row.orderId,
dueAt: row.dueAt, dueAt: row.dueAt,
totalCents: row.totalCents, totalCents: row.totalCents,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listInvoices(req, res, next) {export const listInvoices = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.invoices.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/invoices',
if (err) { auth: 'public',
log.error('listInvoices failed', err); query: ListInvoicesQuery,
return next(err); async run({ query }) {
} const rows = await db.invoices.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listInvoices(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.invoices.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listInvoices failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listInvoices = handler({
method: 'GET',
path: '/invoices',
auth: 'public',
query: ListInvoicesQuery,
async run({ query }) {
const rows = await db.invoices.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/invoices/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Invoices: search by text.// Invoices: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchInvoicesQuery } from '../../schemas/invoices';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchInvoicesQuery } from '../../schemas/invoices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
orderId: row.orderId, orderId: row.orderId,
dueAt: row.dueAt, dueAt: row.dueAt,
totalCents: row.totalCents, totalCents: row.totalCents,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchInvoices(req, res, next) {export const searchInvoices = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/invoices/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchInvoicesQuery,
} async run({ query }) {
db.invoices.search(q, { limit: 50 }, function (err, rows) { const rows = await db.invoices.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchInvoices failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchInvoices(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.invoices.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchInvoices failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchInvoices = handler({
method: 'GET',
path: '/invoices/search',
auth: 'public',
query: SearchInvoicesQuery,
async run({ query }) {
const rows = await db.invoices.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/invoices/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Invoices: change the fields of one record.// Invoices: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { InvoiceParams, UpdateInvoiceBody } from '../../schemas/invoices';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { InvoiceParams, UpdateInvoiceBody } from '../../schemas/invoices';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
orderId: row.orderId, orderId: row.orderId,
dueAt: row.dueAt, dueAt: row.dueAt,
totalCents: row.totalCents, totalCents: row.totalCents,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateInvoice(req, res, next) {export const updateInvoice = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/invoices/:id',
db.invoices.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: InvoiceParams,
if (!row) return res.status(404).json({ error: 'Invoice not found' }); body: UpdateInvoiceBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.number !== undefined) changes.number = req.body.number; const updated = await db.invoices.update(params.id, { ...body, updated_by: user.id });
if (req.body.orderId !== undefined) changes.orderId = req.body.orderId; if (!updated) throw new HttpError(404, 'not_found', 'Invoice not found');
if (req.body.dueAt !== undefined) changes.dueAt = req.body.dueAt; log.info('Invoice updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.totalCents !== undefined) changes.totalCents = req.body.totalCents; return { status: 200, body: toResponse(updated) };
db.invoices.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updateInvoice failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateInvoice(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.invoices.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Invoice not found' });
const changes = {};
if (req.body.number !== undefined) changes.number = req.body.number;
if (req.body.orderId !== undefined) changes.orderId = req.body.orderId;
if (req.body.dueAt !== undefined) changes.dueAt = req.body.dueAt;
if (req.body.totalCents !== undefined) changes.totalCents = req.body.totalCents;
db.invoices.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateInvoice failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateInvoice = handler({
method: 'PATCH',
path: '/invoices/:id',
auth: 'user',
params: InvoiceParams,
body: UpdateInvoiceBody,
async run({ params, body, user, log }) {
const updated = await db.invoices.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Invoice not found');
log.info('Invoice updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/orders/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Orders: create one record.// Orders: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateOrderBody } from '../../schemas/orders';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateOrderBody } from '../../schemas/orders';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
totalCents: row.totalCents, totalCents: row.totalCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createOrder(req, res, next) {export const createOrder = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/orders',
const body = req.body || {}; auth: 'user',
if (body.number === undefined) { body: CreateOrderBody,
res.status(400).json({ error: 'number is required' }); async run({ body, user, log }) {
return; const existing = await db.orders.findOne({ number: body.number });
} if (existing)
if (body.customerId === undefined) { throw new HttpError(409, 'conflict', `A Order with number ${body.number} exists`);
res.status(400).json({ error: 'customerId is required' }); const row = await db.orders.insert({ ...body, created_by: user.id });
return; log.info('Order created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.orders.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createOrder failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createOrder(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.number === undefined) {
res.status(400).json({ error: 'number is required' });
return;
}
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
db.orders.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createOrder failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createOrder = handler({
method: 'POST',
path: '/orders',
auth: 'user',
body: CreateOrderBody,
async run({ body, user, log }) {
const existing = await db.orders.findOne({ number: body.number });
if (existing)
throw new HttpError(409, 'conflict', `A Order with number ${body.number} exists`);
const row = await db.orders.insert({ ...body, created_by: user.id });
log.info('Order created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/orders/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Orders: delete one record.// Orders: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { OrderParams } from '../../schemas/orders';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { OrderParams } from '../../schemas/orders';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
totalCents: row.totalCents, totalCents: row.totalCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteOrder(req, res, next) {export const deleteOrder = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/orders/:id',
db.orders.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: OrderParams,
log.error('deleteOrder failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.orders.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Order not found');
if (!removed) return res.status(404).json({ error: 'Order not found' }); log.info('Order deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteOrder(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.orders.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteOrder failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Order not found' });
res.status(204).end();
});
});
};
export const deleteOrder = handler({
method: 'DELETE',
path: '/orders/:id',
auth: 'admin',
params: OrderParams,
async run({ params, user, log }) {
const removed = await db.orders.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Order not found');
log.info('Order deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/orders/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Orders: export every record as CSV or JSON.// Orders: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportOrdersQuery } from '../../schemas/orders';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportOrdersQuery } from '../../schemas/orders';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
totalCents: row.totalCents, totalCents: row.totalCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportOrders(req, res, next) {export const exportOrders = handler({
db.orders.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/orders/export',
log.error('exportOrders failed', err); auth: 'admin',
return next(err); query: ExportOrdersQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.orders.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('orders exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'number', 'customerId', 'totalCents', 'status'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'number', 'customerId', 'totalCents', 'status']),
};
},
});
module.exports = function exportOrders(req, res, next) {
db.orders.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportOrders failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'number', 'customerId', 'totalCents', 'status']));
});
};
export const exportOrders = handler({
method: 'GET',
path: '/orders/export',
auth: 'admin',
query: ExportOrdersQuery,
async run({ query, log }) {
const rows = await db.orders.findMany({ limit: query.limit });
log.info('orders exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'number', 'customerId', 'totalCents', 'status']),
};
},
});
src/handlers/orders/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Orders: read one record.// Orders: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { OrderParams } from '../../schemas/orders';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { OrderParams } from '../../schemas/orders';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
totalCents: row.totalCents, totalCents: row.totalCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getOrder(req, res, next) {export const getOrder = handler({
db.orders.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/orders/:id',
log.error('getOrder failed', err); auth: 'public',
return next(err); params: OrderParams,
} async run({ params }) {
if (!row) { const row = await db.orders.findById(params.id);
res.status(404).json({ error: 'Order not found' }); if (!row) throw new HttpError(404, 'not_found', 'Order not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getOrder(req, res, next) {
db.orders.findById(req.params.id, function (err, row) {
if (err) {
log.error('getOrder failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Order not found' });
return;
}
res.json(toResponse(row));
});
};
export const getOrder = handler({
method: 'GET',
path: '/orders/:id',
auth: 'public',
params: OrderParams,
async run({ params }) {
const row = await db.orders.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Order not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/orders/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Orders: list one page.// Orders: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListOrdersQuery } from '../../schemas/orders';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListOrdersQuery } from '../../schemas/orders';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
totalCents: row.totalCents, totalCents: row.totalCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listOrders(req, res, next) {export const listOrders = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.orders.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/orders',
if (err) { auth: 'public',
log.error('listOrders failed', err); query: ListOrdersQuery,
return next(err); async run({ query }) {
} const rows = await db.orders.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listOrders(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.orders.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listOrders failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listOrders = handler({
method: 'GET',
path: '/orders',
auth: 'public',
query: ListOrdersQuery,
async run({ query }) {
const rows = await db.orders.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/orders/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Orders: search by text.// Orders: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchOrdersQuery } from '../../schemas/orders';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchOrdersQuery } from '../../schemas/orders';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
totalCents: row.totalCents, totalCents: row.totalCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchOrders(req, res, next) {export const searchOrders = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/orders/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchOrdersQuery,
} async run({ query }) {
db.orders.search(q, { limit: 50 }, function (err, rows) { const rows = await db.orders.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchOrders failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchOrders(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.orders.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchOrders failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchOrders = handler({
method: 'GET',
path: '/orders/search',
auth: 'public',
query: SearchOrdersQuery,
async run({ query }) {
const rows = await db.orders.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/orders/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Orders: change the fields of one record.// Orders: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { OrderParams, UpdateOrderBody } from '../../schemas/orders';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { OrderParams, UpdateOrderBody } from '../../schemas/orders';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
totalCents: row.totalCents, totalCents: row.totalCents,
status: row.status, status: row.status,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateOrder(req, res, next) {export const updateOrder = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/orders/:id',
db.orders.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: OrderParams,
if (!row) return res.status(404).json({ error: 'Order not found' }); body: UpdateOrderBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.number !== undefined) changes.number = req.body.number; const updated = await db.orders.update(params.id, { ...body, updated_by: user.id });
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; if (!updated) throw new HttpError(404, 'not_found', 'Order not found');
if (req.body.totalCents !== undefined) changes.totalCents = req.body.totalCents; log.info('Order updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.status !== undefined) changes.status = req.body.status; return { status: 200, body: toResponse(updated) };
db.orders.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updateOrder failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateOrder(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.orders.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Order not found' });
const changes = {};
if (req.body.number !== undefined) changes.number = req.body.number;
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.totalCents !== undefined) changes.totalCents = req.body.totalCents;
if (req.body.status !== undefined) changes.status = req.body.status;
db.orders.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateOrder failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateOrder = handler({
method: 'PATCH',
path: '/orders/:id',
auth: 'user',
params: OrderParams,
body: UpdateOrderBody,
async run({ params, body, user, log }) {
const updated = await db.orders.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Order not found');
log.info('Order updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/payments/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Payments: create one record.// Payments: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreatePaymentBody } from '../../schemas/payments';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreatePaymentBody } from '../../schemas/payments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
provider: row.provider, provider: row.provider,
amountCents: row.amountCents, amountCents: row.amountCents,
reference: row.reference, reference: row.reference,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createPayment(req, res, next) {export const createPayment = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/payments',
const body = req.body || {}; auth: 'user',
if (body.orderId === undefined) { body: CreatePaymentBody,
res.status(400).json({ error: 'orderId is required' }); async run({ body, user, log }) {
return; const row = await db.payments.insert({ ...body, created_by: user.id });
} log.info('Payment created', { id: row.id });
if (body.provider === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'provider is required' }); },
return;});
}
db.payments.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createPayment failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createPayment(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.orderId === undefined) {
res.status(400).json({ error: 'orderId is required' });
return;
}
if (body.provider === undefined) {
res.status(400).json({ error: 'provider is required' });
return;
}
db.payments.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createPayment failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createPayment = handler({
method: 'POST',
path: '/payments',
auth: 'user',
body: CreatePaymentBody,
async run({ body, user, log }) {
const row = await db.payments.insert({ ...body, created_by: user.id });
log.info('Payment created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/payments/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Payments: delete one record.// Payments: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { PaymentParams } from '../../schemas/payments';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { PaymentParams } from '../../schemas/payments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
provider: row.provider, provider: row.provider,
amountCents: row.amountCents, amountCents: row.amountCents,
reference: row.reference, reference: row.reference,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deletePayment(req, res, next) {export const deletePayment = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/payments/:id',
db.payments.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: PaymentParams,
log.error('deletePayment failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.payments.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Payment not found');
if (!removed) return res.status(404).json({ error: 'Payment not found' }); log.info('Payment deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deletePayment(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.payments.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deletePayment failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Payment not found' });
res.status(204).end();
});
});
};
export const deletePayment = handler({
method: 'DELETE',
path: '/payments/:id',
auth: 'admin',
params: PaymentParams,
async run({ params, user, log }) {
const removed = await db.payments.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Payment not found');
log.info('Payment deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/payments/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Payments: export every record as CSV or JSON.// Payments: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportPaymentsQuery } from '../../schemas/payments';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportPaymentsQuery } from '../../schemas/payments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
provider: row.provider, provider: row.provider,
amountCents: row.amountCents, amountCents: row.amountCents,
reference: row.reference, reference: row.reference,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportPayments(req, res, next) {export const exportPayments = handler({
db.payments.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/payments/export',
log.error('exportPayments failed', err); auth: 'admin',
return next(err); query: ExportPaymentsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.payments.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('payments exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'orderId', 'provider', 'amountCents', 'reference'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'orderId', 'provider', 'amountCents', 'reference']),
};
},
});
module.exports = function exportPayments(req, res, next) {
db.payments.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportPayments failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'orderId', 'provider', 'amountCents', 'reference']));
});
};
export const exportPayments = handler({
method: 'GET',
path: '/payments/export',
auth: 'admin',
query: ExportPaymentsQuery,
async run({ query, log }) {
const rows = await db.payments.findMany({ limit: query.limit });
log.info('payments exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'orderId', 'provider', 'amountCents', 'reference']),
};
},
});
src/handlers/payments/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Payments: read one record.// Payments: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { PaymentParams } from '../../schemas/payments';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { PaymentParams } from '../../schemas/payments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
provider: row.provider, provider: row.provider,
amountCents: row.amountCents, amountCents: row.amountCents,
reference: row.reference, reference: row.reference,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getPayment(req, res, next) {export const getPayment = handler({
db.payments.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/payments/:id',
log.error('getPayment failed', err); auth: 'public',
return next(err); params: PaymentParams,
} async run({ params }) {
if (!row) { const row = await db.payments.findById(params.id);
res.status(404).json({ error: 'Payment not found' }); if (!row) throw new HttpError(404, 'not_found', 'Payment not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getPayment(req, res, next) {
db.payments.findById(req.params.id, function (err, row) {
if (err) {
log.error('getPayment failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Payment not found' });
return;
}
res.json(toResponse(row));
});
};
export const getPayment = handler({
method: 'GET',
path: '/payments/:id',
auth: 'public',
params: PaymentParams,
async run({ params }) {
const row = await db.payments.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Payment not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/payments/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Payments: list one page.// Payments: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListPaymentsQuery } from '../../schemas/payments';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListPaymentsQuery } from '../../schemas/payments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
provider: row.provider, provider: row.provider,
amountCents: row.amountCents, amountCents: row.amountCents,
reference: row.reference, reference: row.reference,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listPayments(req, res, next) {export const listPayments = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.payments.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/payments',
if (err) { auth: 'public',
log.error('listPayments failed', err); query: ListPaymentsQuery,
return next(err); async run({ query }) {
} const rows = await db.payments.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listPayments(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.payments.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listPayments failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listPayments = handler({
method: 'GET',
path: '/payments',
auth: 'public',
query: ListPaymentsQuery,
async run({ query }) {
const rows = await db.payments.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/payments/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Payments: search by text.// Payments: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchPaymentsQuery } from '../../schemas/payments';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchPaymentsQuery } from '../../schemas/payments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
provider: row.provider, provider: row.provider,
amountCents: row.amountCents, amountCents: row.amountCents,
reference: row.reference, reference: row.reference,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchPayments(req, res, next) {export const searchPayments = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/payments/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchPaymentsQuery,
} async run({ query }) {
db.payments.search(q, { limit: 50 }, function (err, rows) { const rows = await db.payments.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchPayments failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchPayments(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.payments.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchPayments failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchPayments = handler({
method: 'GET',
path: '/payments/search',
auth: 'public',
query: SearchPaymentsQuery,
async run({ query }) {
const rows = await db.payments.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/payments/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Payments: change the fields of one record.// Payments: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { PaymentParams, UpdatePaymentBody } from '../../schemas/payments';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { PaymentParams, UpdatePaymentBody } from '../../schemas/payments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
provider: row.provider, provider: row.provider,
amountCents: row.amountCents, amountCents: row.amountCents,
reference: row.reference, reference: row.reference,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updatePayment(req, res, next) {export const updatePayment = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/payments/:id',
db.payments.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: PaymentParams,
if (!row) return res.status(404).json({ error: 'Payment not found' }); body: UpdatePaymentBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.orderId !== undefined) changes.orderId = req.body.orderId; const updated = await db.payments.update(params.id, { ...body, updated_by: user.id });
if (req.body.provider !== undefined) changes.provider = req.body.provider; if (!updated) throw new HttpError(404, 'not_found', 'Payment not found');
if (req.body.amountCents !== undefined) changes.amountCents = req.body.amountCents; log.info('Payment updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.reference !== undefined) changes.reference = req.body.reference; return { status: 200, body: toResponse(updated) };
db.payments.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updatePayment failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updatePayment(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.payments.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Payment not found' });
const changes = {};
if (req.body.orderId !== undefined) changes.orderId = req.body.orderId;
if (req.body.provider !== undefined) changes.provider = req.body.provider;
if (req.body.amountCents !== undefined) changes.amountCents = req.body.amountCents;
if (req.body.reference !== undefined) changes.reference = req.body.reference;
db.payments.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updatePayment failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updatePayment = handler({
method: 'PATCH',
path: '/payments/:id',
auth: 'user',
params: PaymentParams,
body: UpdatePaymentBody,
async run({ params, body, user, log }) {
const updated = await db.payments.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Payment not found');
log.info('Payment updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/quotes/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Quotes: create one record.// Quotes: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateQuoteBody } from '../../schemas/quotes';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateQuoteBody } from '../../schemas/quotes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
validUntil: row.validUntil, validUntil: row.validUntil,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createQuote(req, res, next) {export const createQuote = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/quotes',
const body = req.body || {}; auth: 'user',
if (body.number === undefined) { body: CreateQuoteBody,
res.status(400).json({ error: 'number is required' }); async run({ body, user, log }) {
return; const existing = await db.quotes.findOne({ number: body.number });
} if (existing)
if (body.customerId === undefined) { throw new HttpError(409, 'conflict', `A Quote with number ${body.number} exists`);
res.status(400).json({ error: 'customerId is required' }); const row = await db.quotes.insert({ ...body, created_by: user.id });
return; log.info('Quote created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.quotes.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createQuote failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createQuote(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.number === undefined) {
res.status(400).json({ error: 'number is required' });
return;
}
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
db.quotes.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createQuote failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createQuote = handler({
method: 'POST',
path: '/quotes',
auth: 'user',
body: CreateQuoteBody,
async run({ body, user, log }) {
const existing = await db.quotes.findOne({ number: body.number });
if (existing)
throw new HttpError(409, 'conflict', `A Quote with number ${body.number} exists`);
const row = await db.quotes.insert({ ...body, created_by: user.id });
log.info('Quote created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/quotes/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Quotes: delete one record.// Quotes: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { QuoteParams } from '../../schemas/quotes';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { QuoteParams } from '../../schemas/quotes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
validUntil: row.validUntil, validUntil: row.validUntil,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteQuote(req, res, next) {export const deleteQuote = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/quotes/:id',
db.quotes.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: QuoteParams,
log.error('deleteQuote failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.quotes.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Quote not found');
if (!removed) return res.status(404).json({ error: 'Quote not found' }); log.info('Quote deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteQuote(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.quotes.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteQuote failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Quote not found' });
res.status(204).end();
});
});
};
export const deleteQuote = handler({
method: 'DELETE',
path: '/quotes/:id',
auth: 'admin',
params: QuoteParams,
async run({ params, user, log }) {
const removed = await db.quotes.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Quote not found');
log.info('Quote deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/quotes/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Quotes: export every record as CSV or JSON.// Quotes: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportQuotesQuery } from '../../schemas/quotes';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportQuotesQuery } from '../../schemas/quotes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
validUntil: row.validUntil, validUntil: row.validUntil,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportQuotes(req, res, next) {export const exportQuotes = handler({
db.quotes.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/quotes/export',
log.error('exportQuotes failed', err); auth: 'admin',
return next(err); query: ExportQuotesQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.quotes.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('quotes exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'number', 'customerId', 'validUntil'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'number', 'customerId', 'validUntil']),
};
},
});
module.exports = function exportQuotes(req, res, next) {
db.quotes.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportQuotes failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'number', 'customerId', 'validUntil']));
});
};
export const exportQuotes = handler({
method: 'GET',
path: '/quotes/export',
auth: 'admin',
query: ExportQuotesQuery,
async run({ query, log }) {
const rows = await db.quotes.findMany({ limit: query.limit });
log.info('quotes exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'number', 'customerId', 'validUntil']),
};
},
});
src/handlers/quotes/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Quotes: read one record.// Quotes: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { QuoteParams } from '../../schemas/quotes';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { QuoteParams } from '../../schemas/quotes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
validUntil: row.validUntil, validUntil: row.validUntil,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getQuote(req, res, next) {export const getQuote = handler({
db.quotes.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/quotes/:id',
log.error('getQuote failed', err); auth: 'public',
return next(err); params: QuoteParams,
} async run({ params }) {
if (!row) { const row = await db.quotes.findById(params.id);
res.status(404).json({ error: 'Quote not found' }); if (!row) throw new HttpError(404, 'not_found', 'Quote not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getQuote(req, res, next) {
db.quotes.findById(req.params.id, function (err, row) {
if (err) {
log.error('getQuote failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Quote not found' });
return;
}
res.json(toResponse(row));
});
};
export const getQuote = handler({
method: 'GET',
path: '/quotes/:id',
auth: 'public',
params: QuoteParams,
async run({ params }) {
const row = await db.quotes.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Quote not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/quotes/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Quotes: list one page.// Quotes: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListQuotesQuery } from '../../schemas/quotes';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListQuotesQuery } from '../../schemas/quotes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
validUntil: row.validUntil, validUntil: row.validUntil,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listQuotes(req, res, next) {export const listQuotes = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.quotes.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/quotes',
if (err) { auth: 'public',
log.error('listQuotes failed', err); query: ListQuotesQuery,
return next(err); async run({ query }) {
} const rows = await db.quotes.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listQuotes(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.quotes.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listQuotes failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listQuotes = handler({
method: 'GET',
path: '/quotes',
auth: 'public',
query: ListQuotesQuery,
async run({ query }) {
const rows = await db.quotes.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/quotes/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Quotes: search by text.// Quotes: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchQuotesQuery } from '../../schemas/quotes';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchQuotesQuery } from '../../schemas/quotes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
validUntil: row.validUntil, validUntil: row.validUntil,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchQuotes(req, res, next) {export const searchQuotes = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/quotes/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchQuotesQuery,
} async run({ query }) {
db.quotes.search(q, { limit: 50 }, function (err, rows) { const rows = await db.quotes.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchQuotes failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchQuotes(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.quotes.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchQuotes failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchQuotes = handler({
method: 'GET',
path: '/quotes/search',
auth: 'public',
query: SearchQuotesQuery,
async run({ query }) {
const rows = await db.quotes.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/quotes/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Quotes: change the fields of one record.// Quotes: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { QuoteParams, UpdateQuoteBody } from '../../schemas/quotes';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { QuoteParams, UpdateQuoteBody } from '../../schemas/quotes';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
number: row.number, number: row.number,
customerId: row.customerId, customerId: row.customerId,
validUntil: row.validUntil, validUntil: row.validUntil,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateQuote(req, res, next) {export const updateQuote = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/quotes/:id',
db.quotes.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: QuoteParams,
if (!row) return res.status(404).json({ error: 'Quote not found' }); body: UpdateQuoteBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.number !== undefined) changes.number = req.body.number; const updated = await db.quotes.update(params.id, { ...body, updated_by: user.id });
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; if (!updated) throw new HttpError(404, 'not_found', 'Quote not found');
if (req.body.validUntil !== undefined) changes.validUntil = req.body.validUntil; log.info('Quote updated', { id: updated.id, fields: Object.keys(body) });
db.quotes.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateQuote failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateQuote(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.quotes.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Quote not found' });
const changes = {};
if (req.body.number !== undefined) changes.number = req.body.number;
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.validUntil !== undefined) changes.validUntil = req.body.validUntil;
db.quotes.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateQuote failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateQuote = handler({
method: 'PATCH',
path: '/quotes/:id',
auth: 'user',
params: QuoteParams,
body: UpdateQuoteBody,
async run({ params, body, user, log }) {
const updated = await db.quotes.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Quote not found');
log.info('Quote updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/refunds/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Refunds: create one record.// Refunds: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateRefundBody } from '../../schemas/refunds';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateRefundBody } from '../../schemas/refunds';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
paymentId: row.paymentId, paymentId: row.paymentId,
amountCents: row.amountCents, amountCents: row.amountCents,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createRefund(req, res, next) {export const createRefund = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/refunds',
const body = req.body || {}; auth: 'user',
if (body.paymentId === undefined) { body: CreateRefundBody,
res.status(400).json({ error: 'paymentId is required' }); async run({ body, user, log }) {
return; const row = await db.refunds.insert({ ...body, created_by: user.id });
} log.info('Refund created', { id: row.id });
if (body.amountCents === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'amountCents is required' }); },
return;});
}
db.refunds.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createRefund failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createRefund(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.paymentId === undefined) {
res.status(400).json({ error: 'paymentId is required' });
return;
}
if (body.amountCents === undefined) {
res.status(400).json({ error: 'amountCents is required' });
return;
}
db.refunds.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createRefund failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createRefund = handler({
method: 'POST',
path: '/refunds',
auth: 'user',
body: CreateRefundBody,
async run({ body, user, log }) {
const row = await db.refunds.insert({ ...body, created_by: user.id });
log.info('Refund created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/refunds/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Refunds: delete one record.// Refunds: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { RefundParams } from '../../schemas/refunds';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { RefundParams } from '../../schemas/refunds';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
paymentId: row.paymentId, paymentId: row.paymentId,
amountCents: row.amountCents, amountCents: row.amountCents,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteRefund(req, res, next) {export const deleteRefund = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/refunds/:id',
db.refunds.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: RefundParams,
log.error('deleteRefund failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.refunds.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Refund not found');
if (!removed) return res.status(404).json({ error: 'Refund not found' }); log.info('Refund deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteRefund(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.refunds.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteRefund failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Refund not found' });
res.status(204).end();
});
});
};
export const deleteRefund = handler({
method: 'DELETE',
path: '/refunds/:id',
auth: 'admin',
params: RefundParams,
async run({ params, user, log }) {
const removed = await db.refunds.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Refund not found');
log.info('Refund deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/refunds/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Refunds: export every record as CSV or JSON.// Refunds: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportRefundsQuery } from '../../schemas/refunds';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportRefundsQuery } from '../../schemas/refunds';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
paymentId: row.paymentId, paymentId: row.paymentId,
amountCents: row.amountCents, amountCents: row.amountCents,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportRefunds(req, res, next) {export const exportRefunds = handler({
db.refunds.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/refunds/export',
log.error('exportRefunds failed', err); auth: 'admin',
return next(err); query: ExportRefundsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.refunds.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('refunds exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'paymentId', 'amountCents', 'reason'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'paymentId', 'amountCents', 'reason']),
};
},
});
module.exports = function exportRefunds(req, res, next) {
db.refunds.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportRefunds failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'paymentId', 'amountCents', 'reason']));
});
};
export const exportRefunds = handler({
method: 'GET',
path: '/refunds/export',
auth: 'admin',
query: ExportRefundsQuery,
async run({ query, log }) {
const rows = await db.refunds.findMany({ limit: query.limit });
log.info('refunds exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'paymentId', 'amountCents', 'reason']),
};
},
});
src/handlers/refunds/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Refunds: read one record.// Refunds: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { RefundParams } from '../../schemas/refunds';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { RefundParams } from '../../schemas/refunds';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
paymentId: row.paymentId, paymentId: row.paymentId,
amountCents: row.amountCents, amountCents: row.amountCents,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getRefund(req, res, next) {export const getRefund = handler({
db.refunds.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/refunds/:id',
log.error('getRefund failed', err); auth: 'public',
return next(err); params: RefundParams,
} async run({ params }) {
if (!row) { const row = await db.refunds.findById(params.id);
res.status(404).json({ error: 'Refund not found' }); if (!row) throw new HttpError(404, 'not_found', 'Refund not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getRefund(req, res, next) {
db.refunds.findById(req.params.id, function (err, row) {
if (err) {
log.error('getRefund failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Refund not found' });
return;
}
res.json(toResponse(row));
});
};
export const getRefund = handler({
method: 'GET',
path: '/refunds/:id',
auth: 'public',
params: RefundParams,
async run({ params }) {
const row = await db.refunds.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Refund not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/refunds/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Refunds: list one page.// Refunds: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListRefundsQuery } from '../../schemas/refunds';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListRefundsQuery } from '../../schemas/refunds';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
paymentId: row.paymentId, paymentId: row.paymentId,
amountCents: row.amountCents, amountCents: row.amountCents,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listRefunds(req, res, next) {export const listRefunds = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.refunds.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/refunds',
if (err) { auth: 'public',
log.error('listRefunds failed', err); query: ListRefundsQuery,
return next(err); async run({ query }) {
} const rows = await db.refunds.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listRefunds(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.refunds.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listRefunds failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listRefunds = handler({
method: 'GET',
path: '/refunds',
auth: 'public',
query: ListRefundsQuery,
async run({ query }) {
const rows = await db.refunds.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/refunds/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Refunds: search by text.// Refunds: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchRefundsQuery } from '../../schemas/refunds';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchRefundsQuery } from '../../schemas/refunds';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
paymentId: row.paymentId, paymentId: row.paymentId,
amountCents: row.amountCents, amountCents: row.amountCents,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchRefunds(req, res, next) {export const searchRefunds = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/refunds/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchRefundsQuery,
} async run({ query }) {
db.refunds.search(q, { limit: 50 }, function (err, rows) { const rows = await db.refunds.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchRefunds failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchRefunds(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.refunds.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchRefunds failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchRefunds = handler({
method: 'GET',
path: '/refunds/search',
auth: 'public',
query: SearchRefundsQuery,
async run({ query }) {
const rows = await db.refunds.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/refunds/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Refunds: change the fields of one record.// Refunds: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { RefundParams, UpdateRefundBody } from '../../schemas/refunds';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { RefundParams, UpdateRefundBody } from '../../schemas/refunds';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
paymentId: row.paymentId, paymentId: row.paymentId,
amountCents: row.amountCents, amountCents: row.amountCents,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateRefund(req, res, next) {export const updateRefund = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/refunds/:id',
db.refunds.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: RefundParams,
if (!row) return res.status(404).json({ error: 'Refund not found' }); body: UpdateRefundBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.paymentId !== undefined) changes.paymentId = req.body.paymentId; const updated = await db.refunds.update(params.id, { ...body, updated_by: user.id });
if (req.body.amountCents !== undefined) changes.amountCents = req.body.amountCents; if (!updated) throw new HttpError(404, 'not_found', 'Refund not found');
if (req.body.reason !== undefined) changes.reason = req.body.reason; log.info('Refund updated', { id: updated.id, fields: Object.keys(body) });
db.refunds.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateRefund failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateRefund(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.refunds.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Refund not found' });
const changes = {};
if (req.body.paymentId !== undefined) changes.paymentId = req.body.paymentId;
if (req.body.amountCents !== undefined) changes.amountCents = req.body.amountCents;
if (req.body.reason !== undefined) changes.reason = req.body.reason;
db.refunds.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateRefund failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateRefund = handler({
method: 'PATCH',
path: '/refunds/:id',
auth: 'user',
params: RefundParams,
body: UpdateRefundBody,
async run({ params, body, user, log }) {
const updated = await db.refunds.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Refund not found');
log.info('Refund updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/returns/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Returns: create one record.// Returns: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateReturnRequestBody } from '../../schemas/returns';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateReturnRequestBody } from '../../schemas/returns';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
lineIds: row.lineIds, lineIds: row.lineIds,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createReturnRequest(req, res, next) {export const createReturnRequest = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/returns',
const body = req.body || {}; auth: 'user',
if (body.orderId === undefined) { body: CreateReturnRequestBody,
res.status(400).json({ error: 'orderId is required' }); async run({ body, user, log }) {
return; const row = await db.returns.insert({ ...body, created_by: user.id });
} log.info('ReturnRequest created', { id: row.id });
if (body.lineIds === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'lineIds is required' }); },
return;});
}
db.returns.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createReturnRequest failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createReturnRequest(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.orderId === undefined) {
res.status(400).json({ error: 'orderId is required' });
return;
}
if (body.lineIds === undefined) {
res.status(400).json({ error: 'lineIds is required' });
return;
}
db.returns.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createReturnRequest failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createReturnRequest = handler({
method: 'POST',
path: '/returns',
auth: 'user',
body: CreateReturnRequestBody,
async run({ body, user, log }) {
const row = await db.returns.insert({ ...body, created_by: user.id });
log.info('ReturnRequest created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/returns/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Returns: delete one record.// Returns: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ReturnRequestParams } from '../../schemas/returns';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ReturnRequestParams } from '../../schemas/returns';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
lineIds: row.lineIds, lineIds: row.lineIds,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteReturnRequest(req, res, next) {export const deleteReturnRequest = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/returns/:id',
db.returns.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: ReturnRequestParams,
log.error('deleteReturnRequest failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.returns.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'ReturnRequest not found');
if (!removed) return res.status(404).json({ error: 'ReturnRequest not found' }); log.info('ReturnRequest deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteReturnRequest(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.returns.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteReturnRequest failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'ReturnRequest not found' });
res.status(204).end();
});
});
};
export const deleteReturnRequest = handler({
method: 'DELETE',
path: '/returns/:id',
auth: 'admin',
params: ReturnRequestParams,
async run({ params, user, log }) {
const removed = await db.returns.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'ReturnRequest not found');
log.info('ReturnRequest deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/returns/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Returns: export every record as CSV or JSON.// Returns: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportReturnsQuery } from '../../schemas/returns';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportReturnsQuery } from '../../schemas/returns';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
lineIds: row.lineIds, lineIds: row.lineIds,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportReturns(req, res, next) {export const exportReturns = handler({
db.returns.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/returns/export',
log.error('exportReturns failed', err); auth: 'admin',
return next(err); query: ExportReturnsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.returns.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('returns exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'orderId', 'lineIds', 'reason'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'orderId', 'lineIds', 'reason']),
};
},
});
module.exports = function exportReturns(req, res, next) {
db.returns.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportReturns failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'orderId', 'lineIds', 'reason']));
});
};
export const exportReturns = handler({
method: 'GET',
path: '/returns/export',
auth: 'admin',
query: ExportReturnsQuery,
async run({ query, log }) {
const rows = await db.returns.findMany({ limit: query.limit });
log.info('returns exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'orderId', 'lineIds', 'reason']),
};
},
});
src/handlers/returns/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Returns: read one record.// Returns: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ReturnRequestParams } from '../../schemas/returns';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ReturnRequestParams } from '../../schemas/returns';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
lineIds: row.lineIds, lineIds: row.lineIds,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getReturnRequest(req, res, next) {export const getReturnRequest = handler({
db.returns.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/returns/:id',
log.error('getReturnRequest failed', err); auth: 'public',
return next(err); params: ReturnRequestParams,
} async run({ params }) {
if (!row) { const row = await db.returns.findById(params.id);
res.status(404).json({ error: 'ReturnRequest not found' }); if (!row) throw new HttpError(404, 'not_found', 'ReturnRequest not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getReturnRequest(req, res, next) {
db.returns.findById(req.params.id, function (err, row) {
if (err) {
log.error('getReturnRequest failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'ReturnRequest not found' });
return;
}
res.json(toResponse(row));
});
};
export const getReturnRequest = handler({
method: 'GET',
path: '/returns/:id',
auth: 'public',
params: ReturnRequestParams,
async run({ params }) {
const row = await db.returns.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'ReturnRequest not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/returns/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Returns: list one page.// Returns: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListReturnsQuery } from '../../schemas/returns';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListReturnsQuery } from '../../schemas/returns';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
lineIds: row.lineIds, lineIds: row.lineIds,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listReturns(req, res, next) {export const listReturns = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.returns.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/returns',
if (err) { auth: 'public',
log.error('listReturns failed', err); query: ListReturnsQuery,
return next(err); async run({ query }) {
} const rows = await db.returns.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listReturns(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.returns.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listReturns failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listReturns = handler({
method: 'GET',
path: '/returns',
auth: 'public',
query: ListReturnsQuery,
async run({ query }) {
const rows = await db.returns.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/returns/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Returns: search by text.// Returns: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchReturnsQuery } from '../../schemas/returns';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchReturnsQuery } from '../../schemas/returns';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
lineIds: row.lineIds, lineIds: row.lineIds,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchReturns(req, res, next) {export const searchReturns = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/returns/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchReturnsQuery,
} async run({ query }) {
db.returns.search(q, { limit: 50 }, function (err, rows) { const rows = await db.returns.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchReturns failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchReturns(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.returns.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchReturns failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchReturns = handler({
method: 'GET',
path: '/returns/search',
auth: 'public',
query: SearchReturnsQuery,
async run({ query }) {
const rows = await db.returns.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/returns/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Returns: change the fields of one record.// Returns: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ReturnRequestParams, UpdateReturnRequestBody } from '../../schemas/returns';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ReturnRequestParams, UpdateReturnRequestBody } from '../../schemas/returns';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
lineIds: row.lineIds, lineIds: row.lineIds,
reason: row.reason, reason: row.reason,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateReturnRequest(req, res, next) {export const updateReturnRequest = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/returns/:id',
db.returns.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: ReturnRequestParams,
if (!row) return res.status(404).json({ error: 'ReturnRequest not found' }); body: UpdateReturnRequestBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.orderId !== undefined) changes.orderId = req.body.orderId; const updated = await db.returns.update(params.id, { ...body, updated_by: user.id });
if (req.body.lineIds !== undefined) changes.lineIds = req.body.lineIds; if (!updated) throw new HttpError(404, 'not_found', 'ReturnRequest not found');
if (req.body.reason !== undefined) changes.reason = req.body.reason; log.info('ReturnRequest updated', { id: updated.id, fields: Object.keys(body) });
db.returns.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateReturnRequest failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateReturnRequest(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.returns.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'ReturnRequest not found' });
const changes = {};
if (req.body.orderId !== undefined) changes.orderId = req.body.orderId;
if (req.body.lineIds !== undefined) changes.lineIds = req.body.lineIds;
if (req.body.reason !== undefined) changes.reason = req.body.reason;
db.returns.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateReturnRequest failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateReturnRequest = handler({
method: 'PATCH',
path: '/returns/:id',
auth: 'user',
params: ReturnRequestParams,
body: UpdateReturnRequestBody,
async run({ params, body, user, log }) {
const updated = await db.returns.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'ReturnRequest not found');
log.info('ReturnRequest updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/shipments/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Shipments: create one record.// Shipments: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateShipmentBody } from '../../schemas/shipments';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateShipmentBody } from '../../schemas/shipments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
carrier: row.carrier, carrier: row.carrier,
trackingNumber: row.trackingNumber, trackingNumber: row.trackingNumber,
shippedAt: row.shippedAt, shippedAt: row.shippedAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createShipment(req, res, next) {export const createShipment = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/shipments',
const body = req.body || {}; auth: 'user',
if (body.orderId === undefined) { body: CreateShipmentBody,
res.status(400).json({ error: 'orderId is required' }); async run({ body, user, log }) {
return; const existing = await db.shipments.findOne({ trackingNumber: body.trackingNumber });
} if (existing)
if (body.carrier === undefined) { throw new HttpError(409, 'conflict', `A Shipment with trackingNumber ${body.trackingNumber} exists`);
res.status(400).json({ error: 'carrier is required' }); const row = await db.shipments.insert({ ...body, created_by: user.id });
return; log.info('Shipment created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.shipments.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createShipment failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createShipment(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.orderId === undefined) {
res.status(400).json({ error: 'orderId is required' });
return;
}
if (body.carrier === undefined) {
res.status(400).json({ error: 'carrier is required' });
return;
}
db.shipments.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createShipment failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createShipment = handler({
method: 'POST',
path: '/shipments',
auth: 'user',
body: CreateShipmentBody,
async run({ body, user, log }) {
const existing = await db.shipments.findOne({ trackingNumber: body.trackingNumber });
if (existing)
throw new HttpError(409, 'conflict', `A Shipment with trackingNumber ${body.trackingNumber} exists`);
const row = await db.shipments.insert({ ...body, created_by: user.id });
log.info('Shipment created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/shipments/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Shipments: delete one record.// Shipments: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ShipmentParams } from '../../schemas/shipments';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ShipmentParams } from '../../schemas/shipments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
carrier: row.carrier, carrier: row.carrier,
trackingNumber: row.trackingNumber, trackingNumber: row.trackingNumber,
shippedAt: row.shippedAt, shippedAt: row.shippedAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteShipment(req, res, next) {export const deleteShipment = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/shipments/:id',
db.shipments.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: ShipmentParams,
log.error('deleteShipment failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.shipments.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Shipment not found');
if (!removed) return res.status(404).json({ error: 'Shipment not found' }); log.info('Shipment deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteShipment(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.shipments.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteShipment failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Shipment not found' });
res.status(204).end();
});
});
};
export const deleteShipment = handler({
method: 'DELETE',
path: '/shipments/:id',
auth: 'admin',
params: ShipmentParams,
async run({ params, user, log }) {
const removed = await db.shipments.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Shipment not found');
log.info('Shipment deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/shipments/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Shipments: export every record as CSV or JSON.// Shipments: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportShipmentsQuery } from '../../schemas/shipments';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportShipmentsQuery } from '../../schemas/shipments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
carrier: row.carrier, carrier: row.carrier,
trackingNumber: row.trackingNumber, trackingNumber: row.trackingNumber,
shippedAt: row.shippedAt, shippedAt: row.shippedAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportShipments(req, res, next) {export const exportShipments = handler({
db.shipments.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/shipments/export',
log.error('exportShipments failed', err); auth: 'admin',
return next(err); query: ExportShipmentsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.shipments.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('shipments exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'orderId', 'carrier', 'trackingNumber', 'shippedAt'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'orderId', 'carrier', 'trackingNumber', 'shippedAt']),
};
},
});
module.exports = function exportShipments(req, res, next) {
db.shipments.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportShipments failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'orderId', 'carrier', 'trackingNumber', 'shippedAt']));
});
};
export const exportShipments = handler({
method: 'GET',
path: '/shipments/export',
auth: 'admin',
query: ExportShipmentsQuery,
async run({ query, log }) {
const rows = await db.shipments.findMany({ limit: query.limit });
log.info('shipments exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'orderId', 'carrier', 'trackingNumber', 'shippedAt']),
};
},
});
src/handlers/shipments/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Shipments: read one record.// Shipments: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ShipmentParams } from '../../schemas/shipments';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ShipmentParams } from '../../schemas/shipments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
carrier: row.carrier, carrier: row.carrier,
trackingNumber: row.trackingNumber, trackingNumber: row.trackingNumber,
shippedAt: row.shippedAt, shippedAt: row.shippedAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getShipment(req, res, next) {export const getShipment = handler({
db.shipments.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/shipments/:id',
log.error('getShipment failed', err); auth: 'public',
return next(err); params: ShipmentParams,
} async run({ params }) {
if (!row) { const row = await db.shipments.findById(params.id);
res.status(404).json({ error: 'Shipment not found' }); if (!row) throw new HttpError(404, 'not_found', 'Shipment not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getShipment(req, res, next) {
db.shipments.findById(req.params.id, function (err, row) {
if (err) {
log.error('getShipment failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Shipment not found' });
return;
}
res.json(toResponse(row));
});
};
export const getShipment = handler({
method: 'GET',
path: '/shipments/:id',
auth: 'public',
params: ShipmentParams,
async run({ params }) {
const row = await db.shipments.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Shipment not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/shipments/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Shipments: list one page.// Shipments: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListShipmentsQuery } from '../../schemas/shipments';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListShipmentsQuery } from '../../schemas/shipments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
carrier: row.carrier, carrier: row.carrier,
trackingNumber: row.trackingNumber, trackingNumber: row.trackingNumber,
shippedAt: row.shippedAt, shippedAt: row.shippedAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listShipments(req, res, next) {export const listShipments = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.shipments.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/shipments',
if (err) { auth: 'public',
log.error('listShipments failed', err); query: ListShipmentsQuery,
return next(err); async run({ query }) {
} const rows = await db.shipments.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listShipments(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.shipments.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listShipments failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listShipments = handler({
method: 'GET',
path: '/shipments',
auth: 'public',
query: ListShipmentsQuery,
async run({ query }) {
const rows = await db.shipments.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/shipments/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Shipments: search by text.// Shipments: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchShipmentsQuery } from '../../schemas/shipments';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchShipmentsQuery } from '../../schemas/shipments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
carrier: row.carrier, carrier: row.carrier,
trackingNumber: row.trackingNumber, trackingNumber: row.trackingNumber,
shippedAt: row.shippedAt, shippedAt: row.shippedAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchShipments(req, res, next) {export const searchShipments = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/shipments/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchShipmentsQuery,
} async run({ query }) {
db.shipments.search(q, { limit: 50 }, function (err, rows) { const rows = await db.shipments.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchShipments failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchShipments(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.shipments.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchShipments failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchShipments = handler({
method: 'GET',
path: '/shipments/search',
auth: 'public',
query: SearchShipmentsQuery,
async run({ query }) {
const rows = await db.shipments.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/shipments/update.ts
+17 -26
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Shipments: change the fields of one record.// Shipments: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ShipmentParams, UpdateShipmentBody } from '../../schemas/shipments';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ShipmentParams, UpdateShipmentBody } from '../../schemas/shipments';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
orderId: row.orderId, orderId: row.orderId,
carrier: row.carrier, carrier: row.carrier,
trackingNumber: row.trackingNumber, trackingNumber: row.trackingNumber,
shippedAt: row.shippedAt, shippedAt: row.shippedAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateShipment(req, res, next) {export const updateShipment = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/shipments/:id',
db.shipments.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: ShipmentParams,
if (!row) return res.status(404).json({ error: 'Shipment not found' }); body: UpdateShipmentBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.orderId !== undefined) changes.orderId = req.body.orderId; const updated = await db.shipments.update(params.id, { ...body, updated_by: user.id });
if (req.body.carrier !== undefined) changes.carrier = req.body.carrier; if (!updated) throw new HttpError(404, 'not_found', 'Shipment not found');
if (req.body.trackingNumber !== undefined) changes.trackingNumber = req.body.trackingNumber; log.info('Shipment updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.shippedAt !== undefined) changes.shippedAt = req.body.shippedAt; return { status: 200, body: toResponse(updated) };
db.shipments.update(row.id, changes, function (err, updated) { },
if (err) {});
log.error('updateShipment failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateShipment(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.shipments.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Shipment not found' });
const changes = {};
if (req.body.orderId !== undefined) changes.orderId = req.body.orderId;
if (req.body.carrier !== undefined) changes.carrier = req.body.carrier;
if (req.body.trackingNumber !== undefined) changes.trackingNumber = req.body.trackingNumber;
if (req.body.shippedAt !== undefined) changes.shippedAt = req.body.shippedAt;
db.shipments.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateShipment failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateShipment = handler({
method: 'PATCH',
path: '/shipments/:id',
auth: 'user',
params: ShipmentParams,
body: UpdateShipmentBody,
async run({ params, body, user, log }) {
const updated = await db.shipments.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Shipment not found');
log.info('Shipment updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/tax/rates.ts
+1407 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

Account handlers

The handlers of customers, addresses, sessions, wishlists, notifications, subscriptions, loyalty accounts and consents move to the typed form.

A customer email is now the key of a create, so a second account with the same email answers 409.

src/handlers/addresses/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Addresses: create one record.// Addresses: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateAddressBody } from '../../schemas/addresses';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateAddressBody } from '../../schemas/addresses';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
line1: row.line1, line1: row.line1,
city: row.city, city: row.city,
postcode: row.postcode, postcode: row.postcode,
country: row.country, country: row.country,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createAddress(req, res, next) {export const createAddress = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/addresses',
const body = req.body || {}; auth: 'user',
if (body.customerId === undefined) { body: CreateAddressBody,
res.status(400).json({ error: 'customerId is required' }); async run({ body, user, log }) {
return; const row = await db.addresses.insert({ ...body, created_by: user.id });
} log.info('Address created', { id: row.id });
if (body.line1 === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'line1 is required' }); },
return;});
}
db.addresses.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createAddress failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createAddress(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
if (body.line1 === undefined) {
res.status(400).json({ error: 'line1 is required' });
return;
}
db.addresses.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createAddress failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createAddress = handler({
method: 'POST',
path: '/addresses',
auth: 'user',
body: CreateAddressBody,
async run({ body, user, log }) {
const row = await db.addresses.insert({ ...body, created_by: user.id });
log.info('Address created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/addresses/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Addresses: delete one record.// Addresses: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { AddressParams } from '../../schemas/addresses';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { AddressParams } from '../../schemas/addresses';
function toResponse(row) {function toResponse(row) {
return { return {
}; };
}}
module.exports = function deleteAddress(req, res, next) {export const deleteAddress = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/addresses/:id',
db.addresses.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: AddressParams,
log.error('deleteAddress failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.addresses.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Address not found');
if (!removed) return res.status(404).json({ error: 'Address not found' }); log.info('Address deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteAddress(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.addresses.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteAddress failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Address not found' });
res.status(204).end();
});
});
};
export const deleteAddress = handler({
method: 'DELETE',
path: '/addresses/:id',
auth: 'admin',
params: AddressParams,
async run({ params, user, log }) {
const removed = await db.addresses.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Address not found');
log.info('Address deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/addresses/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Addresses: export every record as CSV or JSON.// Addresses: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportAddressesQuery } from '../../schemas/addresses';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportAddressesQuery } from '../../schemas/addresses';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
line1: row.line1, line1: row.line1,
city: row.city, city: row.city,
postcode: row.postcode, postcode: row.postcode,
country: row.country, country: row.country,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportAddresses(req, res, next) {export const exportAddresses = handler({
db.addresses.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/addresses/export',
log.error('exportAddresses failed', err); auth: 'admin',
return next(err); query: ExportAddressesQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.addresses.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('addresses exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'line1', 'city', 'postcode', 'country'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'line1', 'city', 'postcode', 'country']),
};
},
});
module.exports = function exportAddresses(req, res, next) {
db.addresses.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportAddresses failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'line1', 'city', 'postcode', 'country']));
});
};
export const exportAddresses = handler({
method: 'GET',
path: '/addresses/export',
auth: 'admin',
query: ExportAddressesQuery,
async run({ query, log }) {
const rows = await db.addresses.findMany({ limit: query.limit });
log.info('addresses exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'line1', 'city', 'postcode', 'country']),
};
},
});
src/handlers/addresses/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Addresses: read one record.// Addresses: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { AddressParams } from '../../schemas/addresses';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { AddressParams } from '../../schemas/addresses';
function toResponse(row) {function toResponse(row) {
return { return {
}; };
}}
module.exports = function getAddress(req, res, next) {export const getAddress = handler({
db.addresses.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/addresses/:id',
log.error('getAddress failed', err); auth: 'public',
return next(err); params: AddressParams,
} async run({ params }) {
if (!row) { const row = await db.addresses.findById(params.id);
res.status(404).json({ error: 'Address not found' }); if (!row) throw new HttpError(404, 'not_found', 'Address not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getAddress(req, res, next) {
db.addresses.findById(req.params.id, function (err, row) {
if (err) {
log.error('getAddress failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Address not found' });
return;
}
res.json(toResponse(row));
});
};
export const getAddress = handler({
method: 'GET',
path: '/addresses/:id',
auth: 'public',
params: AddressParams,
async run({ params }) {
const row = await db.addresses.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Address not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/addresses/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Addresses: list one page.// Addresses: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListAddressesQuery } from '../../schemas/addresses';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListAddressesQuery } from '../../schemas/addresses';
function toResponse(row) {function toResponse(row) {
return { return {
}; };
}}
module.exports = function listAddresses(req, res, next) {export const listAddresses = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.addresses.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/addresses',
if (err) { auth: 'public',
log.error('listAddresses failed', err); query: ListAddressesQuery,
return next(err); async run({ query }) {
} const rows = await db.addresses.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listAddresses(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.addresses.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listAddresses failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listAddresses = handler({
method: 'GET',
path: '/addresses',
auth: 'public',
query: ListAddressesQuery,
async run({ query }) {
const rows = await db.addresses.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/addresses/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Addresses: search by text.// Addresses: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchAddressesQuery } from '../../schemas/addresses';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchAddressesQuery } from '../../schemas/addresses';
function toResponse(row) {function toResponse(row) {
return { return {
}; };
}}
module.exports = function searchAddresses(req, res, next) {export const searchAddresses = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/addresses/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchAddressesQuery,
} async run({ query }) {
db.addresses.search(q, { limit: 50 }, function (err, rows) { const rows = await db.addresses.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchAddresses failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchAddresses(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.addresses.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchAddresses failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchAddresses = handler({
method: 'GET',
path: '/addresses/search',
auth: 'public',
query: SearchAddressesQuery,
async run({ query }) {
const rows = await db.addresses.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/addresses/update.ts
+17 -27
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Addresses: change the fields of one record.// Addresses: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { AddressParams, UpdateAddressBody } from '../../schemas/addresses';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { AddressParams, UpdateAddressBody } from '../../schemas/addresses';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
line1: row.line1, line1: row.line1,
city: row.city, city: row.city,
postcode: row.postcode, postcode: row.postcode,
country: row.country, country: row.country,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateAddress(req, res, next) {export const updateAddress = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/addresses/:id',
db.addresses.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: AddressParams,
if (!row) return res.status(404).json({ error: 'Address not found' }); body: UpdateAddressBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; const updated = await db.addresses.update(params.id, { ...body, updated_by: user.id });
if (req.body.line1 !== undefined) changes.line1 = req.body.line1; if (!updated) throw new HttpError(404, 'not_found', 'Address not found');
if (req.body.city !== undefined) changes.city = req.body.city; log.info('Address updated', { id: updated.id, fields: Object.keys(body) });
if (req.body.postcode !== undefined) changes.postcode = req.body.postcode; return { status: 200, body: toResponse(updated) };
if (req.body.country !== undefined) changes.country = req.body.country; },
db.addresses.update(row.id, changes, function (err, updated) {});
if (err) {
log.error('updateAddress failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateAddress(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.addresses.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Address not found' });
const changes = {};
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.line1 !== undefined) changes.line1 = req.body.line1;
if (req.body.city !== undefined) changes.city = req.body.city;
if (req.body.postcode !== undefined) changes.postcode = req.body.postcode;
if (req.body.country !== undefined) changes.country = req.body.country;
db.addresses.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateAddress failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateAddress = handler({
method: 'PATCH',
path: '/addresses/:id',
auth: 'user',
params: AddressParams,
body: UpdateAddressBody,
async run({ params, body, user, log }) {
const updated = await db.addresses.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Address not found');
log.info('Address updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/apiKeys/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// ApiKeys: create one record.// ApiKeys: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateApiKeyBody } from '../../schemas/apiKeys';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateApiKeyBody } from '../../schemas/apiKeys';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
teamId: row.teamId, teamId: row.teamId,
label: row.label, label: row.label,
scopes: row.scopes, scopes: row.scopes,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createApiKey(req, res, next) {export const createApiKey = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/apiKeys',
const body = req.body || {}; auth: 'user',
if (body.teamId === undefined) { body: CreateApiKeyBody,
res.status(400).json({ error: 'teamId is required' }); async run({ body, user, log }) {
return; const row = await db.apiKeys.insert({ ...body, created_by: user.id });
} log.info('ApiKey created', { id: row.id });
if (body.label === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'label is required' }); },
return;});
}
db.apiKeys.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createApiKey failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createApiKey(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.teamId === undefined) {
res.status(400).json({ error: 'teamId is required' });
return;
}
if (body.label === undefined) {
res.status(400).json({ error: 'label is required' });
return;
}
db.apiKeys.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createApiKey failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createApiKey = handler({
method: 'POST',
path: '/apiKeys',
auth: 'user',
body: CreateApiKeyBody,
async run({ body, user, log }) {
const row = await db.apiKeys.insert({ ...body, created_by: user.id });
log.info('ApiKey created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/apiKeys/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// ApiKeys: delete one record.// ApiKeys: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ApiKeyParams } from '../../schemas/apiKeys';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ApiKeyParams } from '../../schemas/apiKeys';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
teamId: row.teamId, teamId: row.teamId,
label: row.label, label: row.label,
scopes: row.scopes, scopes: row.scopes,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteApiKey(req, res, next) {export const deleteApiKey = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/apiKeys/:id',
db.apiKeys.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: ApiKeyParams,
log.error('deleteApiKey failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.apiKeys.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'ApiKey not found');
if (!removed) return res.status(404).json({ error: 'ApiKey not found' }); log.info('ApiKey deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteApiKey(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.apiKeys.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteApiKey failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'ApiKey not found' });
res.status(204).end();
});
});
};
export const deleteApiKey = handler({
method: 'DELETE',
path: '/apiKeys/:id',
auth: 'admin',
params: ApiKeyParams,
async run({ params, user, log }) {
const removed = await db.apiKeys.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'ApiKey not found');
log.info('ApiKey deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/apiKeys/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// ApiKeys: export every record as CSV or JSON.// ApiKeys: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportApiKeysQuery } from '../../schemas/apiKeys';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportApiKeysQuery } from '../../schemas/apiKeys';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
teamId: row.teamId, teamId: row.teamId,
label: row.label, label: row.label,
scopes: row.scopes, scopes: row.scopes,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportApiKeys(req, res, next) {export const exportApiKeys = handler({
db.apiKeys.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/apiKeys/export',
log.error('exportApiKeys failed', err); auth: 'admin',
return next(err); query: ExportApiKeysQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.apiKeys.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('apiKeys exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'teamId', 'label', 'scopes'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'teamId', 'label', 'scopes']),
};
},
});
module.exports = function exportApiKeys(req, res, next) {
db.apiKeys.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportApiKeys failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'teamId', 'label', 'scopes']));
});
};
export const exportApiKeys = handler({
method: 'GET',
path: '/apiKeys/export',
auth: 'admin',
query: ExportApiKeysQuery,
async run({ query, log }) {
const rows = await db.apiKeys.findMany({ limit: query.limit });
log.info('apiKeys exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'teamId', 'label', 'scopes']),
};
},
});
src/handlers/apiKeys/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// ApiKeys: read one record.// ApiKeys: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ApiKeyParams } from '../../schemas/apiKeys';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ApiKeyParams } from '../../schemas/apiKeys';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
teamId: row.teamId, teamId: row.teamId,
label: row.label, label: row.label,
scopes: row.scopes, scopes: row.scopes,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getApiKey(req, res, next) {export const getApiKey = handler({
db.apiKeys.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/apiKeys/:id',
log.error('getApiKey failed', err); auth: 'public',
return next(err); params: ApiKeyParams,
} async run({ params }) {
if (!row) { const row = await db.apiKeys.findById(params.id);
res.status(404).json({ error: 'ApiKey not found' }); if (!row) throw new HttpError(404, 'not_found', 'ApiKey not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getApiKey(req, res, next) {
db.apiKeys.findById(req.params.id, function (err, row) {
if (err) {
log.error('getApiKey failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'ApiKey not found' });
return;
}
res.json(toResponse(row));
});
};
export const getApiKey = handler({
method: 'GET',
path: '/apiKeys/:id',
auth: 'public',
params: ApiKeyParams,
async run({ params }) {
const row = await db.apiKeys.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'ApiKey not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/apiKeys/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// ApiKeys: list one page.// ApiKeys: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListApiKeysQuery } from '../../schemas/apiKeys';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListApiKeysQuery } from '../../schemas/apiKeys';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
teamId: row.teamId, teamId: row.teamId,
label: row.label, label: row.label,
scopes: row.scopes, scopes: row.scopes,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listApiKeys(req, res, next) {export const listApiKeys = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.apiKeys.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/apiKeys',
if (err) { auth: 'public',
log.error('listApiKeys failed', err); query: ListApiKeysQuery,
return next(err); async run({ query }) {
} const rows = await db.apiKeys.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listApiKeys(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.apiKeys.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listApiKeys failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listApiKeys = handler({
method: 'GET',
path: '/apiKeys',
auth: 'public',
query: ListApiKeysQuery,
async run({ query }) {
const rows = await db.apiKeys.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/apiKeys/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// ApiKeys: search by text.// ApiKeys: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchApiKeysQuery } from '../../schemas/apiKeys';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchApiKeysQuery } from '../../schemas/apiKeys';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
teamId: row.teamId, teamId: row.teamId,
label: row.label, label: row.label,
scopes: row.scopes, scopes: row.scopes,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchApiKeys(req, res, next) {export const searchApiKeys = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/apiKeys/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchApiKeysQuery,
} async run({ query }) {
db.apiKeys.search(q, { limit: 50 }, function (err, rows) { const rows = await db.apiKeys.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchApiKeys failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchApiKeys(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.apiKeys.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchApiKeys failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchApiKeys = handler({
method: 'GET',
path: '/apiKeys/search',
auth: 'public',
query: SearchApiKeysQuery,
async run({ query }) {
const rows = await db.apiKeys.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/apiKeys/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// ApiKeys: change the fields of one record.// ApiKeys: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ApiKeyParams, UpdateApiKeyBody } from '../../schemas/apiKeys';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ApiKeyParams, UpdateApiKeyBody } from '../../schemas/apiKeys';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
teamId: row.teamId, teamId: row.teamId,
label: row.label, label: row.label,
scopes: row.scopes, scopes: row.scopes,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateApiKey(req, res, next) {export const updateApiKey = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/apiKeys/:id',
db.apiKeys.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: ApiKeyParams,
if (!row) return res.status(404).json({ error: 'ApiKey not found' }); body: UpdateApiKeyBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.teamId !== undefined) changes.teamId = req.body.teamId; const updated = await db.apiKeys.update(params.id, { ...body, updated_by: user.id });
if (req.body.label !== undefined) changes.label = req.body.label; if (!updated) throw new HttpError(404, 'not_found', 'ApiKey not found');
if (req.body.scopes !== undefined) changes.scopes = req.body.scopes; log.info('ApiKey updated', { id: updated.id, fields: Object.keys(body) });
db.apiKeys.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateApiKey failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateApiKey(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.apiKeys.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'ApiKey not found' });
const changes = {};
if (req.body.teamId !== undefined) changes.teamId = req.body.teamId;
if (req.body.label !== undefined) changes.label = req.body.label;
if (req.body.scopes !== undefined) changes.scopes = req.body.scopes;
db.apiKeys.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateApiKey failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateApiKey = handler({
method: 'PATCH',
path: '/apiKeys/:id',
auth: 'user',
params: ApiKeyParams,
body: UpdateApiKeyBody,
async run({ params, body, user, log }) {
const updated = await db.apiKeys.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'ApiKey not found');
log.info('ApiKey updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/consents/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Consents: create one record.// Consents: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateConsentBody } from '../../schemas/consents';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateConsentBody } from '../../schemas/consents';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
purpose: row.purpose, purpose: row.purpose,
granted: row.granted, granted: row.granted,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createConsent(req, res, next) {export const createConsent = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/consents',
const body = req.body || {}; auth: 'user',
if (body.customerId === undefined) { body: CreateConsentBody,
res.status(400).json({ error: 'customerId is required' }); async run({ body, user, log }) {
return; const row = await db.consents.insert({ ...body, created_by: user.id });
} log.info('Consent created', { id: row.id });
if (body.purpose === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'purpose is required' }); },
return;});
}
db.consents.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createConsent failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createConsent(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
if (body.purpose === undefined) {
res.status(400).json({ error: 'purpose is required' });
return;
}
db.consents.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createConsent failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createConsent = handler({
method: 'POST',
path: '/consents',
auth: 'user',
body: CreateConsentBody,
async run({ body, user, log }) {
const row = await db.consents.insert({ ...body, created_by: user.id });
log.info('Consent created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/consents/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Consents: delete one record.// Consents: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ConsentParams } from '../../schemas/consents';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ConsentParams } from '../../schemas/consents';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
purpose: row.purpose, purpose: row.purpose,
granted: row.granted, granted: row.granted,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteConsent(req, res, next) {export const deleteConsent = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/consents/:id',
db.consents.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: ConsentParams,
log.error('deleteConsent failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.consents.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Consent not found');
if (!removed) return res.status(404).json({ error: 'Consent not found' }); log.info('Consent deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteConsent(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.consents.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteConsent failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Consent not found' });
res.status(204).end();
});
});
};
export const deleteConsent = handler({
method: 'DELETE',
path: '/consents/:id',
auth: 'admin',
params: ConsentParams,
async run({ params, user, log }) {
const removed = await db.consents.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Consent not found');
log.info('Consent deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/consents/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Consents: export every record as CSV or JSON.// Consents: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportConsentsQuery } from '../../schemas/consents';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportConsentsQuery } from '../../schemas/consents';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
purpose: row.purpose, purpose: row.purpose,
granted: row.granted, granted: row.granted,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportConsents(req, res, next) {export const exportConsents = handler({
db.consents.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/consents/export',
log.error('exportConsents failed', err); auth: 'admin',
return next(err); query: ExportConsentsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.consents.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('consents exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'purpose', 'granted'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'purpose', 'granted']),
};
},
});
module.exports = function exportConsents(req, res, next) {
db.consents.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportConsents failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'purpose', 'granted']));
});
};
export const exportConsents = handler({
method: 'GET',
path: '/consents/export',
auth: 'admin',
query: ExportConsentsQuery,
async run({ query, log }) {
const rows = await db.consents.findMany({ limit: query.limit });
log.info('consents exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'purpose', 'granted']),
};
},
});
src/handlers/consents/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Consents: read one record.// Consents: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ConsentParams } from '../../schemas/consents';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ConsentParams } from '../../schemas/consents';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
purpose: row.purpose, purpose: row.purpose,
granted: row.granted, granted: row.granted,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getConsent(req, res, next) {export const getConsent = handler({
db.consents.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/consents/:id',
log.error('getConsent failed', err); auth: 'public',
return next(err); params: ConsentParams,
} async run({ params }) {
if (!row) { const row = await db.consents.findById(params.id);
res.status(404).json({ error: 'Consent not found' }); if (!row) throw new HttpError(404, 'not_found', 'Consent not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getConsent(req, res, next) {
db.consents.findById(req.params.id, function (err, row) {
if (err) {
log.error('getConsent failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Consent not found' });
return;
}
res.json(toResponse(row));
});
};
export const getConsent = handler({
method: 'GET',
path: '/consents/:id',
auth: 'public',
params: ConsentParams,
async run({ params }) {
const row = await db.consents.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Consent not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/consents/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Consents: list one page.// Consents: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListConsentsQuery } from '../../schemas/consents';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListConsentsQuery } from '../../schemas/consents';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
purpose: row.purpose, purpose: row.purpose,
granted: row.granted, granted: row.granted,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listConsents(req, res, next) {export const listConsents = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.consents.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/consents',
if (err) { auth: 'public',
log.error('listConsents failed', err); query: ListConsentsQuery,
return next(err); async run({ query }) {
} const rows = await db.consents.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listConsents(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.consents.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listConsents failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listConsents = handler({
method: 'GET',
path: '/consents',
auth: 'public',
query: ListConsentsQuery,
async run({ query }) {
const rows = await db.consents.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/consents/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Consents: search by text.// Consents: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchConsentsQuery } from '../../schemas/consents';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchConsentsQuery } from '../../schemas/consents';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
purpose: row.purpose, purpose: row.purpose,
granted: row.granted, granted: row.granted,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchConsents(req, res, next) {export const searchConsents = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/consents/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchConsentsQuery,
} async run({ query }) {
db.consents.search(q, { limit: 50 }, function (err, rows) { const rows = await db.consents.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchConsents failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchConsents(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.consents.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchConsents failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchConsents = handler({
method: 'GET',
path: '/consents/search',
auth: 'public',
query: SearchConsentsQuery,
async run({ query }) {
const rows = await db.consents.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/consents/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Consents: change the fields of one record.// Consents: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ConsentParams, UpdateConsentBody } from '../../schemas/consents';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { ConsentParams, UpdateConsentBody } from '../../schemas/consents';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
purpose: row.purpose, purpose: row.purpose,
granted: row.granted, granted: row.granted,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateConsent(req, res, next) {export const updateConsent = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/consents/:id',
db.consents.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: ConsentParams,
if (!row) return res.status(404).json({ error: 'Consent not found' }); body: UpdateConsentBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; const updated = await db.consents.update(params.id, { ...body, updated_by: user.id });
if (req.body.purpose !== undefined) changes.purpose = req.body.purpose; if (!updated) throw new HttpError(404, 'not_found', 'Consent not found');
if (req.body.granted !== undefined) changes.granted = req.body.granted; log.info('Consent updated', { id: updated.id, fields: Object.keys(body) });
db.consents.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateConsent failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateConsent(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.consents.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Consent not found' });
const changes = {};
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.purpose !== undefined) changes.purpose = req.body.purpose;
if (req.body.granted !== undefined) changes.granted = req.body.granted;
db.consents.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateConsent failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateConsent = handler({
method: 'PATCH',
path: '/consents/:id',
auth: 'user',
params: ConsentParams,
body: UpdateConsentBody,
async run({ params, body, user, log }) {
const updated = await db.consents.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Consent not found');
log.info('Consent updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/customers/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Customers: create one record.// Customers: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateCustomerBody } from '../../schemas/customers';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateCustomerBody } from '../../schemas/customers';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
email: row.email, email: row.email,
name: row.name, name: row.name,
marketingOptIn: row.marketingOptIn, marketingOptIn: row.marketingOptIn,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createCustomer(req, res, next) {export const createCustomer = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/customers',
const body = req.body || {}; auth: 'user',
if (body.email === undefined) { body: CreateCustomerBody,
res.status(400).json({ error: 'email is required' }); async run({ body, user, log }) {
return; const existing = await db.customers.findOne({ email: body.email });
} if (existing)
if (body.name === undefined) { throw new HttpError(409, 'conflict', `A Customer with email ${body.email} exists`);
res.status(400).json({ error: 'name is required' }); const row = await db.customers.insert({ ...body, created_by: user.id });
return; log.info('Customer created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.customers.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createCustomer failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createCustomer(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.email === undefined) {
res.status(400).json({ error: 'email is required' });
return;
}
if (body.name === undefined) {
res.status(400).json({ error: 'name is required' });
return;
}
db.customers.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createCustomer failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createCustomer = handler({
method: 'POST',
path: '/customers',
auth: 'user',
body: CreateCustomerBody,
async run({ body, user, log }) {
const existing = await db.customers.findOne({ email: body.email });
if (existing)
throw new HttpError(409, 'conflict', `A Customer with email ${body.email} exists`);
const row = await db.customers.insert({ ...body, created_by: user.id });
log.info('Customer created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/customers/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Customers: delete one record.// Customers: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CustomerParams } from '../../schemas/customers';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CustomerParams } from '../../schemas/customers';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
email: row.email, email: row.email,
name: row.name, name: row.name,
marketingOptIn: row.marketingOptIn, marketingOptIn: row.marketingOptIn,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteCustomer(req, res, next) {export const deleteCustomer = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/customers/:id',
db.customers.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: CustomerParams,
log.error('deleteCustomer failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.customers.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Customer not found');
if (!removed) return res.status(404).json({ error: 'Customer not found' }); log.info('Customer deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteCustomer(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.customers.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteCustomer failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Customer not found' });
res.status(204).end();
});
});
};
export const deleteCustomer = handler({
method: 'DELETE',
path: '/customers/:id',
auth: 'admin',
params: CustomerParams,
async run({ params, user, log }) {
const removed = await db.customers.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Customer not found');
log.info('Customer deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/customers/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Customers: export every record as CSV or JSON.// Customers: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportCustomersQuery } from '../../schemas/customers';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportCustomersQuery } from '../../schemas/customers';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
email: row.email, email: row.email,
name: row.name, name: row.name,
marketingOptIn: row.marketingOptIn, marketingOptIn: row.marketingOptIn,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportCustomers(req, res, next) {export const exportCustomers = handler({
db.customers.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/customers/export',
log.error('exportCustomers failed', err); auth: 'admin',
return next(err); query: ExportCustomersQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.customers.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('customers exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'email', 'name', 'marketingOptIn'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'email', 'name', 'marketingOptIn']),
};
},
});
module.exports = function exportCustomers(req, res, next) {
db.customers.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportCustomers failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'email', 'name', 'marketingOptIn']));
});
};
export const exportCustomers = handler({
method: 'GET',
path: '/customers/export',
auth: 'admin',
query: ExportCustomersQuery,
async run({ query, log }) {
const rows = await db.customers.findMany({ limit: query.limit });
log.info('customers exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'email', 'name', 'marketingOptIn']),
};
},
});
src/handlers/customers/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Customers: read one record.// Customers: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CustomerParams } from '../../schemas/customers';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CustomerParams } from '../../schemas/customers';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
email: row.email, email: row.email,
name: row.name, name: row.name,
marketingOptIn: row.marketingOptIn, marketingOptIn: row.marketingOptIn,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getCustomer(req, res, next) {export const getCustomer = handler({
db.customers.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/customers/:id',
log.error('getCustomer failed', err); auth: 'public',
return next(err); params: CustomerParams,
} async run({ params }) {
if (!row) { const row = await db.customers.findById(params.id);
res.status(404).json({ error: 'Customer not found' }); if (!row) throw new HttpError(404, 'not_found', 'Customer not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getCustomer(req, res, next) {
db.customers.findById(req.params.id, function (err, row) {
if (err) {
log.error('getCustomer failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Customer not found' });
return;
}
res.json(toResponse(row));
});
};
export const getCustomer = handler({
method: 'GET',
path: '/customers/:id',
auth: 'public',
params: CustomerParams,
async run({ params }) {
const row = await db.customers.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Customer not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/customers/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Customers: list one page.// Customers: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListCustomersQuery } from '../../schemas/customers';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListCustomersQuery } from '../../schemas/customers';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
email: row.email, email: row.email,
name: row.name, name: row.name,
marketingOptIn: row.marketingOptIn, marketingOptIn: row.marketingOptIn,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listCustomers(req, res, next) {export const listCustomers = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.customers.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/customers',
if (err) { auth: 'public',
log.error('listCustomers failed', err); query: ListCustomersQuery,
return next(err); async run({ query }) {
} const rows = await db.customers.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listCustomers(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.customers.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listCustomers failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listCustomers = handler({
method: 'GET',
path: '/customers',
auth: 'public',
query: ListCustomersQuery,
async run({ query }) {
const rows = await db.customers.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/customers/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Customers: search by text.// Customers: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchCustomersQuery } from '../../schemas/customers';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchCustomersQuery } from '../../schemas/customers';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
email: row.email, email: row.email,
name: row.name, name: row.name,
marketingOptIn: row.marketingOptIn, marketingOptIn: row.marketingOptIn,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchCustomers(req, res, next) {export const searchCustomers = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/customers/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchCustomersQuery,
} async run({ query }) {
db.customers.search(q, { limit: 50 }, function (err, rows) { const rows = await db.customers.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchCustomers failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchCustomers(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.customers.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchCustomers failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchCustomers = handler({
method: 'GET',
path: '/customers/search',
auth: 'public',
query: SearchCustomersQuery,
async run({ query }) {
const rows = await db.customers.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/customers/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Customers: change the fields of one record.// Customers: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CustomerParams, UpdateCustomerBody } from '../../schemas/customers';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CustomerParams, UpdateCustomerBody } from '../../schemas/customers';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
email: row.email, email: row.email,
name: row.name, name: row.name,
marketingOptIn: row.marketingOptIn, marketingOptIn: row.marketingOptIn,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateCustomer(req, res, next) {export const updateCustomer = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/customers/:id',
db.customers.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: CustomerParams,
if (!row) return res.status(404).json({ error: 'Customer not found' }); body: UpdateCustomerBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.email !== undefined) changes.email = req.body.email; const updated = await db.customers.update(params.id, { ...body, updated_by: user.id });
if (req.body.name !== undefined) changes.name = req.body.name; if (!updated) throw new HttpError(404, 'not_found', 'Customer not found');
if (req.body.marketingOptIn !== undefined) changes.marketingOptIn = req.body.marketingOptIn; log.info('Customer updated', { id: updated.id, fields: Object.keys(body) });
db.customers.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateCustomer failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateCustomer(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.customers.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Customer not found' });
const changes = {};
if (req.body.email !== undefined) changes.email = req.body.email;
if (req.body.name !== undefined) changes.name = req.body.name;
if (req.body.marketingOptIn !== undefined) changes.marketingOptIn = req.body.marketingOptIn;
db.customers.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateCustomer failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateCustomer = handler({
method: 'PATCH',
path: '/customers/:id',
auth: 'user',
params: CustomerParams,
body: UpdateCustomerBody,
async run({ params, body, user, log }) {
const updated = await db.customers.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Customer not found');
log.info('Customer updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/loyalty/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Loyalty: create one record.// Loyalty: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateLoyaltyAccountBody } from '../../schemas/loyalty';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateLoyaltyAccountBody } from '../../schemas/loyalty';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
points: row.points, points: row.points,
tier: row.tier, tier: row.tier,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createLoyaltyAccount(req, res, next) {export const createLoyaltyAccount = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/loyalty',
const body = req.body || {}; auth: 'user',
if (body.customerId === undefined) { body: CreateLoyaltyAccountBody,
res.status(400).json({ error: 'customerId is required' }); async run({ body, user, log }) {
return; const existing = await db.loyalty.findOne({ customerId: body.customerId });
} if (existing)
if (body.points === undefined) { throw new HttpError(409, 'conflict', `A LoyaltyAccount with customerId ${body.customerId} exists`);
res.status(400).json({ error: 'points is required' }); const row = await db.loyalty.insert({ ...body, created_by: user.id });
return; log.info('LoyaltyAccount created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.loyalty.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createLoyaltyAccount failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createLoyaltyAccount(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
if (body.points === undefined) {
res.status(400).json({ error: 'points is required' });
return;
}
db.loyalty.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createLoyaltyAccount failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createLoyaltyAccount = handler({
method: 'POST',
path: '/loyalty',
auth: 'user',
body: CreateLoyaltyAccountBody,
async run({ body, user, log }) {
const existing = await db.loyalty.findOne({ customerId: body.customerId });
if (existing)
throw new HttpError(409, 'conflict', `A LoyaltyAccount with customerId ${body.customerId} exists`);
const row = await db.loyalty.insert({ ...body, created_by: user.id });
log.info('LoyaltyAccount created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/loyalty/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Loyalty: delete one record.// Loyalty: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { LoyaltyAccountParams } from '../../schemas/loyalty';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { LoyaltyAccountParams } from '../../schemas/loyalty';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
points: row.points, points: row.points,
tier: row.tier, tier: row.tier,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteLoyaltyAccount(req, res, next) {export const deleteLoyaltyAccount = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/loyalty/:id',
db.loyalty.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: LoyaltyAccountParams,
log.error('deleteLoyaltyAccount failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.loyalty.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'LoyaltyAccount not found');
if (!removed) return res.status(404).json({ error: 'LoyaltyAccount not found' }); log.info('LoyaltyAccount deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteLoyaltyAccount(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.loyalty.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteLoyaltyAccount failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'LoyaltyAccount not found' });
res.status(204).end();
});
});
};
export const deleteLoyaltyAccount = handler({
method: 'DELETE',
path: '/loyalty/:id',
auth: 'admin',
params: LoyaltyAccountParams,
async run({ params, user, log }) {
const removed = await db.loyalty.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'LoyaltyAccount not found');
log.info('LoyaltyAccount deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/loyalty/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Loyalty: export every record as CSV or JSON.// Loyalty: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportLoyaltyQuery } from '../../schemas/loyalty';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportLoyaltyQuery } from '../../schemas/loyalty';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
points: row.points, points: row.points,
tier: row.tier, tier: row.tier,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportLoyalty(req, res, next) {export const exportLoyalty = handler({
db.loyalty.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/loyalty/export',
log.error('exportLoyalty failed', err); auth: 'admin',
return next(err); query: ExportLoyaltyQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.loyalty.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('loyalty exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'points', 'tier'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'points', 'tier']),
};
},
});
module.exports = function exportLoyalty(req, res, next) {
db.loyalty.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportLoyalty failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'points', 'tier']));
});
};
export const exportLoyalty = handler({
method: 'GET',
path: '/loyalty/export',
auth: 'admin',
query: ExportLoyaltyQuery,
async run({ query, log }) {
const rows = await db.loyalty.findMany({ limit: query.limit });
log.info('loyalty exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'points', 'tier']),
};
},
});
src/handlers/loyalty/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Loyalty: read one record.// Loyalty: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { LoyaltyAccountParams } from '../../schemas/loyalty';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { LoyaltyAccountParams } from '../../schemas/loyalty';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
points: row.points, points: row.points,
tier: row.tier, tier: row.tier,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getLoyaltyAccount(req, res, next) {export const getLoyaltyAccount = handler({
db.loyalty.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/loyalty/:id',
log.error('getLoyaltyAccount failed', err); auth: 'public',
return next(err); params: LoyaltyAccountParams,
} async run({ params }) {
if (!row) { const row = await db.loyalty.findById(params.id);
res.status(404).json({ error: 'LoyaltyAccount not found' }); if (!row) throw new HttpError(404, 'not_found', 'LoyaltyAccount not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getLoyaltyAccount(req, res, next) {
db.loyalty.findById(req.params.id, function (err, row) {
if (err) {
log.error('getLoyaltyAccount failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'LoyaltyAccount not found' });
return;
}
res.json(toResponse(row));
});
};
export const getLoyaltyAccount = handler({
method: 'GET',
path: '/loyalty/:id',
auth: 'public',
params: LoyaltyAccountParams,
async run({ params }) {
const row = await db.loyalty.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'LoyaltyAccount not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/loyalty/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Loyalty: list one page.// Loyalty: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListLoyaltyQuery } from '../../schemas/loyalty';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListLoyaltyQuery } from '../../schemas/loyalty';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
points: row.points, points: row.points,
tier: row.tier, tier: row.tier,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listLoyalty(req, res, next) {export const listLoyalty = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.loyalty.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/loyalty',
if (err) { auth: 'public',
log.error('listLoyalty failed', err); query: ListLoyaltyQuery,
return next(err); async run({ query }) {
} const rows = await db.loyalty.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listLoyalty(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.loyalty.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listLoyalty failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listLoyalty = handler({
method: 'GET',
path: '/loyalty',
auth: 'public',
query: ListLoyaltyQuery,
async run({ query }) {
const rows = await db.loyalty.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/loyalty/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Loyalty: search by text.// Loyalty: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchLoyaltyQuery } from '../../schemas/loyalty';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchLoyaltyQuery } from '../../schemas/loyalty';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
points: row.points, points: row.points,
tier: row.tier, tier: row.tier,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchLoyalty(req, res, next) {export const searchLoyalty = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/loyalty/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchLoyaltyQuery,
} async run({ query }) {
db.loyalty.search(q, { limit: 50 }, function (err, rows) { const rows = await db.loyalty.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchLoyalty failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchLoyalty(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.loyalty.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchLoyalty failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchLoyalty = handler({
method: 'GET',
path: '/loyalty/search',
auth: 'public',
query: SearchLoyaltyQuery,
async run({ query }) {
const rows = await db.loyalty.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/loyalty/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Loyalty: change the fields of one record.// Loyalty: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { LoyaltyAccountParams, UpdateLoyaltyAccountBody } from '../../schemas/loyalty';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { LoyaltyAccountParams, UpdateLoyaltyAccountBody } from '../../schemas/loyalty';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
points: row.points, points: row.points,
tier: row.tier, tier: row.tier,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateLoyaltyAccount(req, res, next) {export const updateLoyaltyAccount = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/loyalty/:id',
db.loyalty.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: LoyaltyAccountParams,
if (!row) return res.status(404).json({ error: 'LoyaltyAccount not found' }); body: UpdateLoyaltyAccountBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; const updated = await db.loyalty.update(params.id, { ...body, updated_by: user.id });
if (req.body.points !== undefined) changes.points = req.body.points; if (!updated) throw new HttpError(404, 'not_found', 'LoyaltyAccount not found');
if (req.body.tier !== undefined) changes.tier = req.body.tier; log.info('LoyaltyAccount updated', { id: updated.id, fields: Object.keys(body) });
db.loyalty.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateLoyaltyAccount failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateLoyaltyAccount(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.loyalty.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'LoyaltyAccount not found' });
const changes = {};
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.points !== undefined) changes.points = req.body.points;
if (req.body.tier !== undefined) changes.tier = req.body.tier;
db.loyalty.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateLoyaltyAccount failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateLoyaltyAccount = handler({
method: 'PATCH',
path: '/loyalty/:id',
auth: 'user',
params: LoyaltyAccountParams,
body: UpdateLoyaltyAccountBody,
async run({ params, body, user, log }) {
const updated = await db.loyalty.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'LoyaltyAccount not found');
log.info('LoyaltyAccount updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/notifications/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Notifications: create one record.// Notifications: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateNotificationBody } from '../../schemas/notifications';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateNotificationBody } from '../../schemas/notifications';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
channel: row.channel, channel: row.channel,
template: row.template, template: row.template,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createNotification(req, res, next) {export const createNotification = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/notifications',
const body = req.body || {}; auth: 'user',
if (body.customerId === undefined) { body: CreateNotificationBody,
res.status(400).json({ error: 'customerId is required' }); async run({ body, user, log }) {
return; const row = await db.notifications.insert({ ...body, created_by: user.id });
} log.info('Notification created', { id: row.id });
if (body.channel === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'channel is required' }); },
return;});
}
db.notifications.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createNotification failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createNotification(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
if (body.channel === undefined) {
res.status(400).json({ error: 'channel is required' });
return;
}
db.notifications.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createNotification failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createNotification = handler({
method: 'POST',
path: '/notifications',
auth: 'user',
body: CreateNotificationBody,
async run({ body, user, log }) {
const row = await db.notifications.insert({ ...body, created_by: user.id });
log.info('Notification created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/notifications/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Notifications: delete one record.// Notifications: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { NotificationParams } from '../../schemas/notifications';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { NotificationParams } from '../../schemas/notifications';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
channel: row.channel, channel: row.channel,
template: row.template, template: row.template,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteNotification(req, res, next) {export const deleteNotification = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/notifications/:id',
db.notifications.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: NotificationParams,
log.error('deleteNotification failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.notifications.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Notification not found');
if (!removed) return res.status(404).json({ error: 'Notification not found' }); log.info('Notification deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteNotification(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.notifications.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteNotification failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Notification not found' });
res.status(204).end();
});
});
};
export const deleteNotification = handler({
method: 'DELETE',
path: '/notifications/:id',
auth: 'admin',
params: NotificationParams,
async run({ params, user, log }) {
const removed = await db.notifications.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Notification not found');
log.info('Notification deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/notifications/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Notifications: export every record as CSV or JSON.// Notifications: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportNotificationsQuery } from '../../schemas/notifications';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportNotificationsQuery } from '../../schemas/notifications';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
channel: row.channel, channel: row.channel,
template: row.template, template: row.template,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportNotifications(req, res, next) {export const exportNotifications = handler({
db.notifications.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/notifications/export',
log.error('exportNotifications failed', err); auth: 'admin',
return next(err); query: ExportNotificationsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.notifications.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('notifications exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'channel', 'template'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'channel', 'template']),
};
},
});
module.exports = function exportNotifications(req, res, next) {
db.notifications.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportNotifications failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'channel', 'template']));
});
};
export const exportNotifications = handler({
method: 'GET',
path: '/notifications/export',
auth: 'admin',
query: ExportNotificationsQuery,
async run({ query, log }) {
const rows = await db.notifications.findMany({ limit: query.limit });
log.info('notifications exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'channel', 'template']),
};
},
});
src/handlers/notifications/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Notifications: read one record.// Notifications: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { NotificationParams } from '../../schemas/notifications';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { NotificationParams } from '../../schemas/notifications';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
channel: row.channel, channel: row.channel,
template: row.template, template: row.template,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getNotification(req, res, next) {export const getNotification = handler({
db.notifications.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/notifications/:id',
log.error('getNotification failed', err); auth: 'public',
return next(err); params: NotificationParams,
} async run({ params }) {
if (!row) { const row = await db.notifications.findById(params.id);
res.status(404).json({ error: 'Notification not found' }); if (!row) throw new HttpError(404, 'not_found', 'Notification not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getNotification(req, res, next) {
db.notifications.findById(req.params.id, function (err, row) {
if (err) {
log.error('getNotification failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Notification not found' });
return;
}
res.json(toResponse(row));
});
};
export const getNotification = handler({
method: 'GET',
path: '/notifications/:id',
auth: 'public',
params: NotificationParams,
async run({ params }) {
const row = await db.notifications.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Notification not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/notifications/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Notifications: list one page.// Notifications: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListNotificationsQuery } from '../../schemas/notifications';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListNotificationsQuery } from '../../schemas/notifications';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
channel: row.channel, channel: row.channel,
template: row.template, template: row.template,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listNotifications(req, res, next) {export const listNotifications = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.notifications.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/notifications',
if (err) { auth: 'public',
log.error('listNotifications failed', err); query: ListNotificationsQuery,
return next(err); async run({ query }) {
} const rows = await db.notifications.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listNotifications(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.notifications.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listNotifications failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listNotifications = handler({
method: 'GET',
path: '/notifications',
auth: 'public',
query: ListNotificationsQuery,
async run({ query }) {
const rows = await db.notifications.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/notifications/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Notifications: search by text.// Notifications: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchNotificationsQuery } from '../../schemas/notifications';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchNotificationsQuery } from '../../schemas/notifications';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
channel: row.channel, channel: row.channel,
template: row.template, template: row.template,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchNotifications(req, res, next) {export const searchNotifications = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/notifications/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchNotificationsQuery,
} async run({ query }) {
db.notifications.search(q, { limit: 50 }, function (err, rows) { const rows = await db.notifications.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchNotifications failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchNotifications(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.notifications.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchNotifications failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchNotifications = handler({
method: 'GET',
path: '/notifications/search',
auth: 'public',
query: SearchNotificationsQuery,
async run({ query }) {
const rows = await db.notifications.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/notifications/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Notifications: change the fields of one record.// Notifications: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { NotificationParams, UpdateNotificationBody } from '../../schemas/notifications';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { NotificationParams, UpdateNotificationBody } from '../../schemas/notifications';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
channel: row.channel, channel: row.channel,
template: row.template, template: row.template,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateNotification(req, res, next) {export const updateNotification = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/notifications/:id',
db.notifications.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: NotificationParams,
if (!row) return res.status(404).json({ error: 'Notification not found' }); body: UpdateNotificationBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; const updated = await db.notifications.update(params.id, { ...body, updated_by: user.id });
if (req.body.channel !== undefined) changes.channel = req.body.channel; if (!updated) throw new HttpError(404, 'not_found', 'Notification not found');
if (req.body.template !== undefined) changes.template = req.body.template; log.info('Notification updated', { id: updated.id, fields: Object.keys(body) });
db.notifications.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateNotification failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateNotification(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.notifications.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Notification not found' });
const changes = {};
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.channel !== undefined) changes.channel = req.body.channel;
if (req.body.template !== undefined) changes.template = req.body.template;
db.notifications.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateNotification failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateNotification = handler({
method: 'PATCH',
path: '/notifications/:id',
auth: 'user',
params: NotificationParams,
body: UpdateNotificationBody,
async run({ params, body, user, log }) {
const updated = await db.notifications.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Notification not found');
log.info('Notification updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/preferences/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Preferences: create one record.// Preferences: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreatePreferenceBody } from '../../schemas/preferences';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreatePreferenceBody } from '../../schemas/preferences';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
locale: row.locale, locale: row.locale,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createPreference(req, res, next) {export const createPreference = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/preferences',
const body = req.body || {}; auth: 'user',
if (body.customerId === undefined) { body: CreatePreferenceBody,
res.status(400).json({ error: 'customerId is required' }); async run({ body, user, log }) {
return; const existing = await db.preferences.findOne({ customerId: body.customerId });
} if (existing)
if (body.locale === undefined) { throw new HttpError(409, 'conflict', `A Preference with customerId ${body.customerId} exists`);
res.status(400).json({ error: 'locale is required' }); const row = await db.preferences.insert({ ...body, created_by: user.id });
return; log.info('Preference created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.preferences.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createPreference failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createPreference(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
if (body.locale === undefined) {
res.status(400).json({ error: 'locale is required' });
return;
}
db.preferences.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createPreference failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createPreference = handler({
method: 'POST',
path: '/preferences',
auth: 'user',
body: CreatePreferenceBody,
async run({ body, user, log }) {
const existing = await db.preferences.findOne({ customerId: body.customerId });
if (existing)
throw new HttpError(409, 'conflict', `A Preference with customerId ${body.customerId} exists`);
const row = await db.preferences.insert({ ...body, created_by: user.id });
log.info('Preference created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/preferences/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Preferences: delete one record.// Preferences: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { PreferenceParams } from '../../schemas/preferences';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { PreferenceParams } from '../../schemas/preferences';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
locale: row.locale, locale: row.locale,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deletePreference(req, res, next) {export const deletePreference = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/preferences/:id',
db.preferences.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: PreferenceParams,
log.error('deletePreference failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.preferences.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Preference not found');
if (!removed) return res.status(404).json({ error: 'Preference not found' }); log.info('Preference deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deletePreference(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.preferences.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deletePreference failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Preference not found' });
res.status(204).end();
});
});
};
export const deletePreference = handler({
method: 'DELETE',
path: '/preferences/:id',
auth: 'admin',
params: PreferenceParams,
async run({ params, user, log }) {
const removed = await db.preferences.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Preference not found');
log.info('Preference deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/preferences/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Preferences: export every record as CSV or JSON.// Preferences: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportPreferencesQuery } from '../../schemas/preferences';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportPreferencesQuery } from '../../schemas/preferences';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
locale: row.locale, locale: row.locale,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportPreferences(req, res, next) {export const exportPreferences = handler({
db.preferences.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/preferences/export',
log.error('exportPreferences failed', err); auth: 'admin',
return next(err); query: ExportPreferencesQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.preferences.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('preferences exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'locale', 'currency'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'locale', 'currency']),
};
},
});
module.exports = function exportPreferences(req, res, next) {
db.preferences.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportPreferences failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'locale', 'currency']));
});
};
export const exportPreferences = handler({
method: 'GET',
path: '/preferences/export',
auth: 'admin',
query: ExportPreferencesQuery,
async run({ query, log }) {
const rows = await db.preferences.findMany({ limit: query.limit });
log.info('preferences exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'locale', 'currency']),
};
},
});
src/handlers/preferences/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Preferences: read one record.// Preferences: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { PreferenceParams } from '../../schemas/preferences';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { PreferenceParams } from '../../schemas/preferences';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
locale: row.locale, locale: row.locale,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getPreference(req, res, next) {export const getPreference = handler({
db.preferences.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/preferences/:id',
log.error('getPreference failed', err); auth: 'public',
return next(err); params: PreferenceParams,
} async run({ params }) {
if (!row) { const row = await db.preferences.findById(params.id);
res.status(404).json({ error: 'Preference not found' }); if (!row) throw new HttpError(404, 'not_found', 'Preference not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getPreference(req, res, next) {
db.preferences.findById(req.params.id, function (err, row) {
if (err) {
log.error('getPreference failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Preference not found' });
return;
}
res.json(toResponse(row));
});
};
export const getPreference = handler({
method: 'GET',
path: '/preferences/:id',
auth: 'public',
params: PreferenceParams,
async run({ params }) {
const row = await db.preferences.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Preference not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/preferences/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Preferences: list one page.// Preferences: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListPreferencesQuery } from '../../schemas/preferences';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListPreferencesQuery } from '../../schemas/preferences';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
locale: row.locale, locale: row.locale,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listPreferences(req, res, next) {export const listPreferences = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.preferences.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/preferences',
if (err) { auth: 'public',
log.error('listPreferences failed', err); query: ListPreferencesQuery,
return next(err); async run({ query }) {
} const rows = await db.preferences.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listPreferences(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.preferences.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listPreferences failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listPreferences = handler({
method: 'GET',
path: '/preferences',
auth: 'public',
query: ListPreferencesQuery,
async run({ query }) {
const rows = await db.preferences.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/preferences/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Preferences: search by text.// Preferences: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchPreferencesQuery } from '../../schemas/preferences';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchPreferencesQuery } from '../../schemas/preferences';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
locale: row.locale, locale: row.locale,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchPreferences(req, res, next) {export const searchPreferences = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/preferences/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchPreferencesQuery,
} async run({ query }) {
db.preferences.search(q, { limit: 50 }, function (err, rows) { const rows = await db.preferences.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchPreferences failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchPreferences(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.preferences.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchPreferences failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchPreferences = handler({
method: 'GET',
path: '/preferences/search',
auth: 'public',
query: SearchPreferencesQuery,
async run({ query }) {
const rows = await db.preferences.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/preferences/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Preferences: change the fields of one record.// Preferences: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { PreferenceParams, UpdatePreferenceBody } from '../../schemas/preferences';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { PreferenceParams, UpdatePreferenceBody } from '../../schemas/preferences';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
locale: row.locale, locale: row.locale,
currency: row.currency, currency: row.currency,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updatePreference(req, res, next) {export const updatePreference = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/preferences/:id',
db.preferences.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: PreferenceParams,
if (!row) return res.status(404).json({ error: 'Preference not found' }); body: UpdatePreferenceBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; const updated = await db.preferences.update(params.id, { ...body, updated_by: user.id });
if (req.body.locale !== undefined) changes.locale = req.body.locale; if (!updated) throw new HttpError(404, 'not_found', 'Preference not found');
if (req.body.currency !== undefined) changes.currency = req.body.currency; log.info('Preference updated', { id: updated.id, fields: Object.keys(body) });
db.preferences.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updatePreference failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updatePreference(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.preferences.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Preference not found' });
const changes = {};
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.locale !== undefined) changes.locale = req.body.locale;
if (req.body.currency !== undefined) changes.currency = req.body.currency;
db.preferences.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updatePreference failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updatePreference = handler({
method: 'PATCH',
path: '/preferences/:id',
auth: 'user',
params: PreferenceParams,
body: UpdatePreferenceBody,
async run({ params, body, user, log }) {
const updated = await db.preferences.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Preference not found');
log.info('Preference updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/sessions/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Sessions: create one record.// Sessions: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateSessionBody } from '../../schemas/sessions';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateSessionBody } from '../../schemas/sessions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
userAgent: row.userAgent, userAgent: row.userAgent,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createSession(req, res, next) {export const createSession = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/sessions',
const body = req.body || {}; auth: 'user',
if (body.customerId === undefined) { body: CreateSessionBody,
res.status(400).json({ error: 'customerId is required' }); async run({ body, user, log }) {
return; const row = await db.sessions.insert({ ...body, created_by: user.id });
} log.info('Session created', { id: row.id });
if (body.userAgent === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'userAgent is required' }); },
return;});
}
db.sessions.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createSession failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createSession(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
if (body.userAgent === undefined) {
res.status(400).json({ error: 'userAgent is required' });
return;
}
db.sessions.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createSession failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createSession = handler({
method: 'POST',
path: '/sessions',
auth: 'user',
body: CreateSessionBody,
async run({ body, user, log }) {
const row = await db.sessions.insert({ ...body, created_by: user.id });
log.info('Session created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/sessions/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Sessions: delete one record.// Sessions: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { SessionParams } from '../../schemas/sessions';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { SessionParams } from '../../schemas/sessions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
userAgent: row.userAgent, userAgent: row.userAgent,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteSession(req, res, next) {export const deleteSession = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/sessions/:id',
db.sessions.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: SessionParams,
log.error('deleteSession failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.sessions.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Session not found');
if (!removed) return res.status(404).json({ error: 'Session not found' }); log.info('Session deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteSession(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.sessions.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteSession failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Session not found' });
res.status(204).end();
});
});
};
export const deleteSession = handler({
method: 'DELETE',
path: '/sessions/:id',
auth: 'admin',
params: SessionParams,
async run({ params, user, log }) {
const removed = await db.sessions.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Session not found');
log.info('Session deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/sessions/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Sessions: export every record as CSV or JSON.// Sessions: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportSessionsQuery } from '../../schemas/sessions';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportSessionsQuery } from '../../schemas/sessions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
userAgent: row.userAgent, userAgent: row.userAgent,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportSessions(req, res, next) {export const exportSessions = handler({
db.sessions.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/sessions/export',
log.error('exportSessions failed', err); auth: 'admin',
return next(err); query: ExportSessionsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.sessions.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('sessions exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'userAgent', 'expiresAt'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'userAgent', 'expiresAt']),
};
},
});
module.exports = function exportSessions(req, res, next) {
db.sessions.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportSessions failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'userAgent', 'expiresAt']));
});
};
export const exportSessions = handler({
method: 'GET',
path: '/sessions/export',
auth: 'admin',
query: ExportSessionsQuery,
async run({ query, log }) {
const rows = await db.sessions.findMany({ limit: query.limit });
log.info('sessions exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'userAgent', 'expiresAt']),
};
},
});
src/handlers/sessions/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Sessions: read one record.// Sessions: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { SessionParams } from '../../schemas/sessions';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { SessionParams } from '../../schemas/sessions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
userAgent: row.userAgent, userAgent: row.userAgent,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getSession(req, res, next) {export const getSession = handler({
db.sessions.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/sessions/:id',
log.error('getSession failed', err); auth: 'public',
return next(err); params: SessionParams,
} async run({ params }) {
if (!row) { const row = await db.sessions.findById(params.id);
res.status(404).json({ error: 'Session not found' }); if (!row) throw new HttpError(404, 'not_found', 'Session not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getSession(req, res, next) {
db.sessions.findById(req.params.id, function (err, row) {
if (err) {
log.error('getSession failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Session not found' });
return;
}
res.json(toResponse(row));
});
};
export const getSession = handler({
method: 'GET',
path: '/sessions/:id',
auth: 'public',
params: SessionParams,
async run({ params }) {
const row = await db.sessions.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Session not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/sessions/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Sessions: list one page.// Sessions: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListSessionsQuery } from '../../schemas/sessions';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListSessionsQuery } from '../../schemas/sessions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
userAgent: row.userAgent, userAgent: row.userAgent,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listSessions(req, res, next) {export const listSessions = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.sessions.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/sessions',
if (err) { auth: 'public',
log.error('listSessions failed', err); query: ListSessionsQuery,
return next(err); async run({ query }) {
} const rows = await db.sessions.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listSessions(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.sessions.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listSessions failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listSessions = handler({
method: 'GET',
path: '/sessions',
auth: 'public',
query: ListSessionsQuery,
async run({ query }) {
const rows = await db.sessions.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/sessions/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Sessions: search by text.// Sessions: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchSessionsQuery } from '../../schemas/sessions';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchSessionsQuery } from '../../schemas/sessions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
userAgent: row.userAgent, userAgent: row.userAgent,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchSessions(req, res, next) {export const searchSessions = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/sessions/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchSessionsQuery,
} async run({ query }) {
db.sessions.search(q, { limit: 50 }, function (err, rows) { const rows = await db.sessions.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchSessions failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchSessions(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.sessions.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchSessions failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchSessions = handler({
method: 'GET',
path: '/sessions/search',
auth: 'public',
query: SearchSessionsQuery,
async run({ query }) {
const rows = await db.sessions.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/sessions/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Sessions: change the fields of one record.// Sessions: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { SessionParams, UpdateSessionBody } from '../../schemas/sessions';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { SessionParams, UpdateSessionBody } from '../../schemas/sessions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
userAgent: row.userAgent, userAgent: row.userAgent,
expiresAt: row.expiresAt, expiresAt: row.expiresAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateSession(req, res, next) {export const updateSession = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/sessions/:id',
db.sessions.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: SessionParams,
if (!row) return res.status(404).json({ error: 'Session not found' }); body: UpdateSessionBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; const updated = await db.sessions.update(params.id, { ...body, updated_by: user.id });
if (req.body.userAgent !== undefined) changes.userAgent = req.body.userAgent; if (!updated) throw new HttpError(404, 'not_found', 'Session not found');
if (req.body.expiresAt !== undefined) changes.expiresAt = req.body.expiresAt; log.info('Session updated', { id: updated.id, fields: Object.keys(body) });
db.sessions.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateSession failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateSession(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.sessions.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Session not found' });
const changes = {};
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.userAgent !== undefined) changes.userAgent = req.body.userAgent;
if (req.body.expiresAt !== undefined) changes.expiresAt = req.body.expiresAt;
db.sessions.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateSession failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateSession = handler({
method: 'PATCH',
path: '/sessions/:id',
auth: 'user',
params: SessionParams,
body: UpdateSessionBody,
async run({ params, body, user, log }) {
const updated = await db.sessions.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Session not found');
log.info('Session updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/subscriptions/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Subscriptions: create one record.// Subscriptions: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateSubscriptionBody } from '../../schemas/subscriptions';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateSubscriptionBody } from '../../schemas/subscriptions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
plan: row.plan, plan: row.plan,
renewsAt: row.renewsAt, renewsAt: row.renewsAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createSubscription(req, res, next) {export const createSubscription = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/subscriptions',
const body = req.body || {}; auth: 'user',
if (body.customerId === undefined) { body: CreateSubscriptionBody,
res.status(400).json({ error: 'customerId is required' }); async run({ body, user, log }) {
return; const row = await db.subscriptions.insert({ ...body, created_by: user.id });
} log.info('Subscription created', { id: row.id });
if (body.plan === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'plan is required' }); },
return;});
}
db.subscriptions.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createSubscription failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createSubscription(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
if (body.plan === undefined) {
res.status(400).json({ error: 'plan is required' });
return;
}
db.subscriptions.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createSubscription failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createSubscription = handler({
method: 'POST',
path: '/subscriptions',
auth: 'user',
body: CreateSubscriptionBody,
async run({ body, user, log }) {
const row = await db.subscriptions.insert({ ...body, created_by: user.id });
log.info('Subscription created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/subscriptions/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Subscriptions: delete one record.// Subscriptions: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { SubscriptionParams } from '../../schemas/subscriptions';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { SubscriptionParams } from '../../schemas/subscriptions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
plan: row.plan, plan: row.plan,
renewsAt: row.renewsAt, renewsAt: row.renewsAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteSubscription(req, res, next) {export const deleteSubscription = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/subscriptions/:id',
db.subscriptions.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: SubscriptionParams,
log.error('deleteSubscription failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.subscriptions.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Subscription not found');
if (!removed) return res.status(404).json({ error: 'Subscription not found' }); log.info('Subscription deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteSubscription(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.subscriptions.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteSubscription failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Subscription not found' });
res.status(204).end();
});
});
};
export const deleteSubscription = handler({
method: 'DELETE',
path: '/subscriptions/:id',
auth: 'admin',
params: SubscriptionParams,
async run({ params, user, log }) {
const removed = await db.subscriptions.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Subscription not found');
log.info('Subscription deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/subscriptions/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Subscriptions: export every record as CSV or JSON.// Subscriptions: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportSubscriptionsQuery } from '../../schemas/subscriptions';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportSubscriptionsQuery } from '../../schemas/subscriptions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
plan: row.plan, plan: row.plan,
renewsAt: row.renewsAt, renewsAt: row.renewsAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportSubscriptions(req, res, next) {export const exportSubscriptions = handler({
db.subscriptions.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/subscriptions/export',
log.error('exportSubscriptions failed', err); auth: 'admin',
return next(err); query: ExportSubscriptionsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.subscriptions.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('subscriptions exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'plan', 'renewsAt'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'plan', 'renewsAt']),
};
},
});
module.exports = function exportSubscriptions(req, res, next) {
db.subscriptions.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportSubscriptions failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'plan', 'renewsAt']));
});
};
export const exportSubscriptions = handler({
method: 'GET',
path: '/subscriptions/export',
auth: 'admin',
query: ExportSubscriptionsQuery,
async run({ query, log }) {
const rows = await db.subscriptions.findMany({ limit: query.limit });
log.info('subscriptions exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'plan', 'renewsAt']),
};
},
});
src/handlers/subscriptions/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Subscriptions: read one record.// Subscriptions: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { SubscriptionParams } from '../../schemas/subscriptions';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { SubscriptionParams } from '../../schemas/subscriptions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
plan: row.plan, plan: row.plan,
renewsAt: row.renewsAt, renewsAt: row.renewsAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getSubscription(req, res, next) {export const getSubscription = handler({
db.subscriptions.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/subscriptions/:id',
log.error('getSubscription failed', err); auth: 'public',
return next(err); params: SubscriptionParams,
} async run({ params }) {
if (!row) { const row = await db.subscriptions.findById(params.id);
res.status(404).json({ error: 'Subscription not found' }); if (!row) throw new HttpError(404, 'not_found', 'Subscription not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getSubscription(req, res, next) {
db.subscriptions.findById(req.params.id, function (err, row) {
if (err) {
log.error('getSubscription failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Subscription not found' });
return;
}
res.json(toResponse(row));
});
};
export const getSubscription = handler({
method: 'GET',
path: '/subscriptions/:id',
auth: 'public',
params: SubscriptionParams,
async run({ params }) {
const row = await db.subscriptions.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Subscription not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/subscriptions/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Subscriptions: list one page.// Subscriptions: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListSubscriptionsQuery } from '../../schemas/subscriptions';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListSubscriptionsQuery } from '../../schemas/subscriptions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
plan: row.plan, plan: row.plan,
renewsAt: row.renewsAt, renewsAt: row.renewsAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listSubscriptions(req, res, next) {export const listSubscriptions = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.subscriptions.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/subscriptions',
if (err) { auth: 'public',
log.error('listSubscriptions failed', err); query: ListSubscriptionsQuery,
return next(err); async run({ query }) {
} const rows = await db.subscriptions.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listSubscriptions(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.subscriptions.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listSubscriptions failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listSubscriptions = handler({
method: 'GET',
path: '/subscriptions',
auth: 'public',
query: ListSubscriptionsQuery,
async run({ query }) {
const rows = await db.subscriptions.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/subscriptions/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Subscriptions: search by text.// Subscriptions: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchSubscriptionsQuery } from '../../schemas/subscriptions';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchSubscriptionsQuery } from '../../schemas/subscriptions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
plan: row.plan, plan: row.plan,
renewsAt: row.renewsAt, renewsAt: row.renewsAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchSubscriptions(req, res, next) {export const searchSubscriptions = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/subscriptions/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchSubscriptionsQuery,
} async run({ query }) {
db.subscriptions.search(q, { limit: 50 }, function (err, rows) { const rows = await db.subscriptions.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchSubscriptions failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchSubscriptions(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.subscriptions.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchSubscriptions failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchSubscriptions = handler({
method: 'GET',
path: '/subscriptions/search',
auth: 'public',
query: SearchSubscriptionsQuery,
async run({ query }) {
const rows = await db.subscriptions.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/subscriptions/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Subscriptions: change the fields of one record.// Subscriptions: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { SubscriptionParams, UpdateSubscriptionBody } from '../../schemas/subscriptions';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { SubscriptionParams, UpdateSubscriptionBody } from '../../schemas/subscriptions';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
plan: row.plan, plan: row.plan,
renewsAt: row.renewsAt, renewsAt: row.renewsAt,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateSubscription(req, res, next) {export const updateSubscription = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/subscriptions/:id',
db.subscriptions.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: SubscriptionParams,
if (!row) return res.status(404).json({ error: 'Subscription not found' }); body: UpdateSubscriptionBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; const updated = await db.subscriptions.update(params.id, { ...body, updated_by: user.id });
if (req.body.plan !== undefined) changes.plan = req.body.plan; if (!updated) throw new HttpError(404, 'not_found', 'Subscription not found');
if (req.body.renewsAt !== undefined) changes.renewsAt = req.body.renewsAt; log.info('Subscription updated', { id: updated.id, fields: Object.keys(body) });
db.subscriptions.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateSubscription failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateSubscription(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.subscriptions.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Subscription not found' });
const changes = {};
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.plan !== undefined) changes.plan = req.body.plan;
if (req.body.renewsAt !== undefined) changes.renewsAt = req.body.renewsAt;
db.subscriptions.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateSubscription failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateSubscription = handler({
method: 'PATCH',
path: '/subscriptions/:id',
auth: 'user',
params: SubscriptionParams,
body: UpdateSubscriptionBody,
async run({ params, body, user, log }) {
const updated = await db.subscriptions.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Subscription not found');
log.info('Subscription updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/teams/create.ts
+18 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Teams: create one record.// Teams: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateTeamBody } from '../../schemas/teams';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateTeamBody } from '../../schemas/teams';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
ownerId: row.ownerId, ownerId: row.ownerId,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createTeam(req, res, next) {export const createTeam = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/teams',
const body = req.body || {}; auth: 'user',
if (body.slug === undefined) { body: CreateTeamBody,
res.status(400).json({ error: 'slug is required' }); async run({ body, user, log }) {
return; const existing = await db.teams.findOne({ slug: body.slug });
} if (existing)
if (body.name === undefined) { throw new HttpError(409, 'conflict', `A Team with slug ${body.slug} exists`);
res.status(400).json({ error: 'name is required' }); const row = await db.teams.insert({ ...body, created_by: user.id });
return; log.info('Team created', { id: row.id });
} return { status: 201, body: toResponse(row) };
db.teams.insert( },
Object.assign({}, body, { created_by: user.id }),});
function (err, row) {
if (err) {
log.error('createTeam failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createTeam(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.slug === undefined) {
res.status(400).json({ error: 'slug is required' });
return;
}
if (body.name === undefined) {
res.status(400).json({ error: 'name is required' });
return;
}
db.teams.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createTeam failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createTeam = handler({
method: 'POST',
path: '/teams',
auth: 'user',
body: CreateTeamBody,
async run({ body, user, log }) {
const existing = await db.teams.findOne({ slug: body.slug });
if (existing)
throw new HttpError(409, 'conflict', `A Team with slug ${body.slug} exists`);
const row = await db.teams.insert({ ...body, created_by: user.id });
log.info('Team created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/teams/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Teams: delete one record.// Teams: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { TeamParams } from '../../schemas/teams';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { TeamParams } from '../../schemas/teams';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
ownerId: row.ownerId, ownerId: row.ownerId,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteTeam(req, res, next) {export const deleteTeam = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/teams/:id',
db.teams.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: TeamParams,
log.error('deleteTeam failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.teams.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Team not found');
if (!removed) return res.status(404).json({ error: 'Team not found' }); log.info('Team deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteTeam(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.teams.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteTeam failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Team not found' });
res.status(204).end();
});
});
};
export const deleteTeam = handler({
method: 'DELETE',
path: '/teams/:id',
auth: 'admin',
params: TeamParams,
async run({ params, user, log }) {
const removed = await db.teams.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Team not found');
log.info('Team deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/teams/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Teams: export every record as CSV or JSON.// Teams: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportTeamsQuery } from '../../schemas/teams';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportTeamsQuery } from '../../schemas/teams';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
ownerId: row.ownerId, ownerId: row.ownerId,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportTeams(req, res, next) {export const exportTeams = handler({
db.teams.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/teams/export',
log.error('exportTeams failed', err); auth: 'admin',
return next(err); query: ExportTeamsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.teams.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('teams exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'ownerId'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'ownerId']),
};
},
});
module.exports = function exportTeams(req, res, next) {
db.teams.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportTeams failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'ownerId']));
});
};
export const exportTeams = handler({
method: 'GET',
path: '/teams/export',
auth: 'admin',
query: ExportTeamsQuery,
async run({ query, log }) {
const rows = await db.teams.findMany({ limit: query.limit });
log.info('teams exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'slug', 'name', 'ownerId']),
};
},
});
src/handlers/teams/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Teams: read one record.// Teams: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { TeamParams } from '../../schemas/teams';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { TeamParams } from '../../schemas/teams';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
ownerId: row.ownerId, ownerId: row.ownerId,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getTeam(req, res, next) {export const getTeam = handler({
db.teams.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/teams/:id',
log.error('getTeam failed', err); auth: 'public',
return next(err); params: TeamParams,
} async run({ params }) {
if (!row) { const row = await db.teams.findById(params.id);
res.status(404).json({ error: 'Team not found' }); if (!row) throw new HttpError(404, 'not_found', 'Team not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getTeam(req, res, next) {
db.teams.findById(req.params.id, function (err, row) {
if (err) {
log.error('getTeam failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Team not found' });
return;
}
res.json(toResponse(row));
});
};
export const getTeam = handler({
method: 'GET',
path: '/teams/:id',
auth: 'public',
params: TeamParams,
async run({ params }) {
const row = await db.teams.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Team not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/teams/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Teams: list one page.// Teams: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListTeamsQuery } from '../../schemas/teams';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListTeamsQuery } from '../../schemas/teams';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
ownerId: row.ownerId, ownerId: row.ownerId,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listTeams(req, res, next) {export const listTeams = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.teams.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/teams',
if (err) { auth: 'public',
log.error('listTeams failed', err); query: ListTeamsQuery,
return next(err); async run({ query }) {
} const rows = await db.teams.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listTeams(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.teams.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listTeams failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listTeams = handler({
method: 'GET',
path: '/teams',
auth: 'public',
query: ListTeamsQuery,
async run({ query }) {
const rows = await db.teams.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/teams/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Teams: search by text.// Teams: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchTeamsQuery } from '../../schemas/teams';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchTeamsQuery } from '../../schemas/teams';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
ownerId: row.ownerId, ownerId: row.ownerId,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchTeams(req, res, next) {export const searchTeams = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/teams/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchTeamsQuery,
} async run({ query }) {
db.teams.search(q, { limit: 50 }, function (err, rows) { const rows = await db.teams.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchTeams failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchTeams(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.teams.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchTeams failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchTeams = handler({
method: 'GET',
path: '/teams/search',
auth: 'public',
query: SearchTeamsQuery,
async run({ query }) {
const rows = await db.teams.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/teams/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Teams: change the fields of one record.// Teams: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { TeamParams, UpdateTeamBody } from '../../schemas/teams';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { TeamParams, UpdateTeamBody } from '../../schemas/teams';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
slug: row.slug, slug: row.slug,
name: row.name, name: row.name,
ownerId: row.ownerId, ownerId: row.ownerId,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateTeam(req, res, next) {export const updateTeam = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/teams/:id',
db.teams.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: TeamParams,
if (!row) return res.status(404).json({ error: 'Team not found' }); body: UpdateTeamBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.slug !== undefined) changes.slug = req.body.slug; const updated = await db.teams.update(params.id, { ...body, updated_by: user.id });
if (req.body.name !== undefined) changes.name = req.body.name; if (!updated) throw new HttpError(404, 'not_found', 'Team not found');
if (req.body.ownerId !== undefined) changes.ownerId = req.body.ownerId; log.info('Team updated', { id: updated.id, fields: Object.keys(body) });
db.teams.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateTeam failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateTeam(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.teams.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Team not found' });
const changes = {};
if (req.body.slug !== undefined) changes.slug = req.body.slug;
if (req.body.name !== undefined) changes.name = req.body.name;
if (req.body.ownerId !== undefined) changes.ownerId = req.body.ownerId;
db.teams.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateTeam failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateTeam = handler({
method: 'PATCH',
path: '/teams/:id',
auth: 'user',
params: TeamParams,
body: UpdateTeamBody,
async run({ params, body, user, log }) {
const updated = await db.teams.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Team not found');
log.info('Team updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});
src/handlers/wishlists/create.ts
+15 -29
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Wishlists: create one record.// Wishlists: create one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { CreateWishlistBody } from '../../schemas/wishlists';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { CreateWishlistBody } from '../../schemas/wishlists';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
name: row.name, name: row.name,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function createWishlist(req, res, next) {export const createWishlist = handler({
requireUser(req, function (authErr, user) { method: 'POST',
if (authErr) return next(authErr); path: '/wishlists',
const body = req.body || {}; auth: 'user',
if (body.customerId === undefined) { body: CreateWishlistBody,
res.status(400).json({ error: 'customerId is required' }); async run({ body, user, log }) {
return; const row = await db.wishlists.insert({ ...body, created_by: user.id });
} log.info('Wishlist created', { id: row.id });
if (body.name === undefined) { return { status: 201, body: toResponse(row) };
res.status(400).json({ error: 'name is required' }); },
return;});
}
db.wishlists.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createWishlist failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
module.exports = function createWishlist(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
const body = req.body || {};
if (body.customerId === undefined) {
res.status(400).json({ error: 'customerId is required' });
return;
}
if (body.name === undefined) {
res.status(400).json({ error: 'name is required' });
return;
}
db.wishlists.insert(
Object.assign({}, body, { created_by: user.id }),
function (err, row) {
if (err) {
log.error('createWishlist failed', err);
return next(err);
}
res.status(201).json(toResponse(row));
}
);
});
};
export const createWishlist = handler({
method: 'POST',
path: '/wishlists',
auth: 'user',
body: CreateWishlistBody,
async run({ body, user, log }) {
const row = await db.wishlists.insert({ ...body, created_by: user.id });
log.info('Wishlist created', { id: row.id });
return { status: 201, body: toResponse(row) };
},
});
src/handlers/wishlists/delete.ts
+16 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Wishlists: delete one record.// Wishlists: delete one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { WishlistParams } from '../../schemas/wishlists';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { WishlistParams } from '../../schemas/wishlists';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
name: row.name, name: row.name,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function deleteWishlist(req, res, next) {export const deleteWishlist = handler({
requireUser(req, function (authErr) { method: 'DELETE',
if (authErr) return next(authErr); path: '/wishlists/:id',
db.wishlists.remove(req.params.id, function (err, removed) { auth: 'admin',
if (err) { params: WishlistParams,
log.error('deleteWishlist failed', err); async run({ params, user, log }) {
return next(err); const removed = await db.wishlists.remove(params.id);
} if (!removed) throw new HttpError(404, 'not_found', 'Wishlist not found');
if (!removed) return res.status(404).json({ error: 'Wishlist not found' }); log.info('Wishlist deleted', { id: params.id, by: user.id });
res.status(204).end(); return { status: 204, body: null };
}); },
});});
};
module.exports = function deleteWishlist(req, res, next) {
requireUser(req, function (authErr) {
if (authErr) return next(authErr);
db.wishlists.remove(req.params.id, function (err, removed) {
if (err) {
log.error('deleteWishlist failed', err);
return next(err);
}
if (!removed) return res.status(404).json({ error: 'Wishlist not found' });
res.status(204).end();
});
});
};
export const deleteWishlist = handler({
method: 'DELETE',
path: '/wishlists/:id',
auth: 'admin',
params: WishlistParams,
async run({ params, user, log }) {
const removed = await db.wishlists.remove(params.id);
if (!removed) throw new HttpError(404, 'not_found', 'Wishlist not found');
log.info('Wishlist deleted', { id: params.id, by: user.id });
return { status: 204, body: null };
},
});
src/handlers/wishlists/export.ts
+20 -16
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Wishlists: export every record as CSV or JSON.// Wishlists: export every record as CSV or JSON.
'use strict';import { db } from '../../db';
import { toCsv } from '../../csv';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { ExportWishlistsQuery } from '../../schemas/wishlists';
const { toCsv } = require('../../csv');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { toCsv } = require('../../csv');
import { db } from '../../db';
import { toCsv } from '../../csv';
import { handler } from '../../http/handler';
import { ExportWishlistsQuery } from '../../schemas/wishlists';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
name: row.name, name: row.name,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function exportWishlists(req, res, next) {export const exportWishlists = handler({
db.wishlists.findMany({ limit: 100000 }, function (err, rows) { method: 'GET',
if (err) { path: '/wishlists/export',
log.error('exportWishlists failed', err); auth: 'admin',
return next(err); query: ExportWishlistsQuery,
} async run({ query, log }) {
if (req.query.format === 'json') return res.json(rows.map(toResponse)); const rows = await db.wishlists.findMany({ limit: query.limit });
res.set('Content-Type', 'text/csv'); log.info('wishlists exported', { count: rows.length, format: query.format });
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'name', 'productIds'])); if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
}); return {
}; status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'name', 'productIds']),
};
},
});
module.exports = function exportWishlists(req, res, next) {
db.wishlists.findMany({ limit: 100000 }, function (err, rows) {
if (err) {
log.error('exportWishlists failed', err);
return next(err);
}
if (req.query.format === 'json') return res.json(rows.map(toResponse));
res.set('Content-Type', 'text/csv');
res.send(toCsv(rows.map(toResponse), ['id', 'customerId', 'name', 'productIds']));
});
};
export const exportWishlists = handler({
method: 'GET',
path: '/wishlists/export',
auth: 'admin',
query: ExportWishlistsQuery,
async run({ query, log }) {
const rows = await db.wishlists.findMany({ limit: query.limit });
log.info('wishlists exported', { count: rows.length, format: query.format });
if (query.format === 'json') return { status: 200, body: rows.map(toResponse) };
return {
status: 200,
headers: { 'Content-Type': 'text/csv' },
body: toCsv(rows.map(toResponse), ['id', 'customerId', 'name', 'productIds']),
};
},
});
src/handlers/wishlists/get.ts
+15 -17
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Wishlists: read one record.// Wishlists: read one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { WishlistParams } from '../../schemas/wishlists';
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { WishlistParams } from '../../schemas/wishlists';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
name: row.name, name: row.name,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function getWishlist(req, res, next) {export const getWishlist = handler({
db.wishlists.findById(req.params.id, function (err, row) { method: 'GET',
if (err) { path: '/wishlists/:id',
log.error('getWishlist failed', err); auth: 'public',
return next(err); params: WishlistParams,
} async run({ params }) {
if (!row) { const row = await db.wishlists.findById(params.id);
res.status(404).json({ error: 'Wishlist not found' }); if (!row) throw new HttpError(404, 'not_found', 'Wishlist not found');
return; return { status: 200, body: toResponse(row) };
} },
res.json(toResponse(row));});
});
};
module.exports = function getWishlist(req, res, next) {
db.wishlists.findById(req.params.id, function (err, row) {
if (err) {
log.error('getWishlist failed', err);
return next(err);
}
if (!row) {
res.status(404).json({ error: 'Wishlist not found' });
return;
}
res.json(toResponse(row));
});
};
export const getWishlist = handler({
method: 'GET',
path: '/wishlists/:id',
auth: 'public',
params: WishlistParams,
async run({ params }) {
const row = await db.wishlists.findById(params.id);
if (!row) throw new HttpError(404, 'not_found', 'Wishlist not found');
return { status: 200, body: toResponse(row) };
},
});
src/handlers/wishlists/list.ts
+16 -14
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Wishlists: list one page.// Wishlists: list one page.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { ListWishlistsQuery } from '../../schemas/wishlists';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { ListWishlistsQuery } from '../../schemas/wishlists';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
name: row.name, name: row.name,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function listWishlists(req, res, next) {export const listWishlists = handler({
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100); method: 'GET',
db.wishlists.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) { path: '/wishlists',
if (err) { auth: 'public',
log.error('listWishlists failed', err); query: ListWishlistsQuery,
return next(err); async run({ query }) {
} const rows = await db.wishlists.findMany({ limit: query.limit, after: query.cursor });
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null }); return {
}); status: 200,
}; body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
module.exports = function listWishlists(req, res, next) {
const limit = Math.min(parseInt(req.query.limit, 10) || 20, 100);
db.wishlists.findMany({ limit: limit, after: req.query.cursor }, function (err, rows) {
if (err) {
log.error('listWishlists failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse), next: rows.length ? rows[rows.length - 1].id : null });
});
};
export const listWishlists = handler({
method: 'GET',
path: '/wishlists',
auth: 'public',
query: ListWishlistsQuery,
async run({ query }) {
const rows = await db.wishlists.findMany({ limit: query.limit, after: query.cursor });
return {
status: 200,
body: { items: rows.map(toResponse), next: rows.at(-1)?.id ?? null },
};
},
});
src/handlers/wishlists/search.ts
+13 -18
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Wishlists: search by text.// Wishlists: search by text.
'use strict';import { db } from '../../db';
import { handler } from '../../http/handler';
const { db } = require('../../db');import { SearchWishlistsQuery } from '../../schemas/wishlists';
const { log } = require('../../log');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
import { db } from '../../db';
import { handler } from '../../http/handler';
import { SearchWishlistsQuery } from '../../schemas/wishlists';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
name: row.name, name: row.name,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function searchWishlists(req, res, next) {export const searchWishlists = handler({
const q = String(req.query.q || '').trim(); method: 'GET',
if (q.length < 2) { path: '/wishlists/search',
res.status(400).json({ error: 'q must have at least 2 characters' }); auth: 'public',
return; query: SearchWishlistsQuery,
} async run({ query }) {
db.wishlists.search(q, { limit: 50 }, function (err, rows) { const rows = await db.wishlists.search(query.q, { limit: query.limit });
if (err) { return { status: 200, body: { items: rows.map(toResponse) } };
log.error('searchWishlists failed', err); },
return next(err);});
}
res.json({ items: rows.map(toResponse) });
});
};
module.exports = function searchWishlists(req, res, next) {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
res.status(400).json({ error: 'q must have at least 2 characters' });
return;
}
db.wishlists.search(q, { limit: 50 }, function (err, rows) {
if (err) {
log.error('searchWishlists failed', err);
return next(err);
}
res.json({ items: rows.map(toResponse) });
});
};
export const searchWishlists = handler({
method: 'GET',
path: '/wishlists/search',
auth: 'public',
query: SearchWishlistsQuery,
async run({ query }) {
const rows = await db.wishlists.search(query.q, { limit: query.limit });
return { status: 200, body: { items: rows.map(toResponse) } };
},
});
src/handlers/wishlists/update.ts
+17 -25
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Wishlists: change the fields of one record.// Wishlists: change the fields of one record.
'use strict';import { db } from '../../db';
import { HttpError } from '../../http/errors';
const { db } = require('../../db');import { handler } from '../../http/handler';
const { log } = require('../../log');import { WishlistParams, UpdateWishlistBody } from '../../schemas/wishlists';
const { requireUser } = require('../../auth');
'use strict';
const { db } = require('../../db');
const { log } = require('../../log');
const { requireUser } = require('../../auth');
import { db } from '../../db';
import { HttpError } from '../../http/errors';
import { handler } from '../../http/handler';
import { WishlistParams, UpdateWishlistBody } from '../../schemas/wishlists';
function toResponse(row) {function toResponse(row) {
return { return {
id: row.id, id: row.id,
customerId: row.customerId, customerId: row.customerId,
name: row.name, name: row.name,
productIds: row.productIds, productIds: row.productIds,
createdAt: row.created_at.toISOString(), createdAt: row.created_at.toISOString(),
updatedAt: row.updated_at.toISOString(), updatedAt: row.updated_at.toISOString(),
}; };
}}
module.exports = function updateWishlist(req, res, next) {export const updateWishlist = handler({
requireUser(req, function (authErr, user) { method: 'PATCH',
if (authErr) return next(authErr); path: '/wishlists/:id',
db.wishlists.findById(req.params.id, function (findErr, row) { auth: 'user',
if (findErr) return next(findErr); params: WishlistParams,
if (!row) return res.status(404).json({ error: 'Wishlist not found' }); body: UpdateWishlistBody,
const changes = {}; async run({ params, body, user, log }) {
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId; const updated = await db.wishlists.update(params.id, { ...body, updated_by: user.id });
if (req.body.name !== undefined) changes.name = req.body.name; if (!updated) throw new HttpError(404, 'not_found', 'Wishlist not found');
if (req.body.productIds !== undefined) changes.productIds = req.body.productIds; log.info('Wishlist updated', { id: updated.id, fields: Object.keys(body) });
db.wishlists.update(row.id, changes, function (err, updated) { return { status: 200, body: toResponse(updated) };
if (err) { },
log.error('updateWishlist failed', err);});
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
module.exports = function updateWishlist(req, res, next) {
requireUser(req, function (authErr, user) {
if (authErr) return next(authErr);
db.wishlists.findById(req.params.id, function (findErr, row) {
if (findErr) return next(findErr);
if (!row) return res.status(404).json({ error: 'Wishlist not found' });
const changes = {};
if (req.body.customerId !== undefined) changes.customerId = req.body.customerId;
if (req.body.name !== undefined) changes.name = req.body.name;
if (req.body.productIds !== undefined) changes.productIds = req.body.productIds;
db.wishlists.update(row.id, changes, function (err, updated) {
if (err) {
log.error('updateWishlist failed', err);
return next(err);
}
res.json(toResponse(updated));
});
});
});
};
export const updateWishlist = handler({
method: 'PATCH',
path: '/wishlists/:id',
auth: 'user',
params: WishlistParams,
body: UpdateWishlistBody,
async run({ params, body, user, log }) {
const updated = await db.wishlists.update(params.id, { ...body, updated_by: user.id });
if (!updated) throw new HttpError(404, 'not_found', 'Wishlist not found');
log.info('Wishlist updated', { id: updated.id, fields: Object.keys(body) });
return { status: 200, body: toResponse(updated) };
},
});

Request schemas

One schema file for each resource. A create body is strict, so an unknown field is a 422; an update body needs at least one field.

src/schemas/addresses.ts
+35 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const AddressParams = z.object({ id: z.string().uuid() });
export const AddressFields = z.object({
customerId: z.string().uuid(),
line1: z.string().min(1).max(200),
city: z.string().min(1).max(120),
postcode: z.string().max(16),
country: z.string().length(2),
});
export const ListAddressesQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateAddressBody = AddressFields.strict();
export const UpdateAddressBody = AddressFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchAddressesQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportAddressesQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Address = z.infer<typeof AddressFields> & { id: string };
src/schemas/apiKeys.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const ApiKeyParams = z.object({ id: z.string().uuid() });
export const ApiKeyFields = z.object({
teamId: z.string().uuid(),
label: z.string().min(1).max(80),
scopes: z.array(z.enum(['read', 'write'])).min(1),
});
export const ListApiKeysQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateApiKeyBody = ApiKeyFields.strict();
export const UpdateApiKeyBody = ApiKeyFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchApiKeysQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportApiKeysQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type ApiKey = z.infer<typeof ApiKeyFields> & { id: string };
src/schemas/attributes.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const AttributeParams = z.object({ id: z.string().uuid() });
export const AttributeFields = z.object({
code: z.string().regex(/^[a-z_]+$/),
label: z.string().min(1).max(80),
kind: z.enum(['text', 'number', 'colour']),
});
export const ListAttributesQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateAttributeBody = AttributeFields.strict();
export const UpdateAttributeBody = AttributeFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchAttributesQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportAttributesQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Attribute = z.infer<typeof AttributeFields> & { id: string };
src/schemas/brands.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const BrandParams = z.object({ id: z.string().uuid() });
export const BrandFields = z.object({
slug: z.string().regex(/^[a-z0-9-]+$/),
name: z.string().min(1).max(120),
website: z.string().url().nullable(),
});
export const ListBrandsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateBrandBody = BrandFields.strict();
export const UpdateBrandBody = BrandFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchBrandsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportBrandsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Brand = z.infer<typeof BrandFields> & { id: string };
src/schemas/bundles.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const BundleParams = z.object({ id: z.string().uuid() });
export const BundleFields = z.object({
sku: z.string().min(3).max(32),
productIds: z.array(z.string().uuid()).min(2).max(20),
discountPercent: z.number().int().min(0).max(50),
});
export const ListBundlesQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateBundleBody = BundleFields.strict();
export const UpdateBundleBody = BundleFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchBundlesQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportBundlesQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Bundle = z.infer<typeof BundleFields> & { id: string };
src/schemas/carts.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
import { CartLine } from './cartLines';
export const CartParams = z.object({ id: z.string().uuid() });
export const CartFields = z.object({
customerId: z.string().uuid().nullable(),
currency: z.string().length(3),
lines: z.array(CartLine).max(100),
});
export const ListCartsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateCartBody = CartFields.strict();
export const UpdateCartBody = CartFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchCartsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportCartsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Cart = z.infer<typeof CartFields> & { id: string };
src/schemas/categories.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const CategoryParams = z.object({ id: z.string().uuid() });
export const CategoryFields = z.object({
slug: z.string().regex(/^[a-z0-9-]+$/),
name: z.string().min(1).max(120),
parentId: z.string().uuid().nullable(),
position: z.number().int().min(0),
});
export const ListCategoriesQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateCategoryBody = CategoryFields.strict();
export const UpdateCategoryBody = CategoryFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchCategoriesQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportCategoriesQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Category = z.infer<typeof CategoryFields> & { id: string };
src/schemas/collections.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const CollectionParams = z.object({ id: z.string().uuid() });
export const CollectionFields = z.object({
slug: z.string().regex(/^[a-z0-9-]+$/),
title: z.string().min(1).max(160),
productIds: z.array(z.string().uuid()).max(500),
});
export const ListCollectionsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateCollectionBody = CollectionFields.strict();
export const UpdateCollectionBody = CollectionFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchCollectionsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportCollectionsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Collection = z.infer<typeof CollectionFields> & { id: string };
src/schemas/consents.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const ConsentParams = z.object({ id: z.string().uuid() });
export const ConsentFields = z.object({
customerId: z.string().uuid(),
purpose: z.enum(['marketing', 'analytics', 'personalisation']),
granted: z.boolean(),
});
export const ListConsentsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateConsentBody = ConsentFields.strict();
export const UpdateConsentBody = ConsentFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchConsentsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportConsentsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Consent = z.infer<typeof ConsentFields> & { id: string };
src/schemas/coupons.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const CouponParams = z.object({ id: z.string().uuid() });
export const CouponFields = z.object({
code: z.string().regex(/^[A-Z0-9]{4,16}$/),
percentOff: z.number().int().min(1).max(90),
expiresAt: z.string().datetime().nullable(),
});
export const ListCouponsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateCouponBody = CouponFields.strict();
export const UpdateCouponBody = CouponFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchCouponsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportCouponsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Coupon = z.infer<typeof CouponFields> & { id: string };
src/schemas/customers.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const CustomerParams = z.object({ id: z.string().uuid() });
export const CustomerFields = z.object({
email: z.string().email(),
name: z.string().min(1).max(160),
marketingOptIn: z.boolean(),
});
export const ListCustomersQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateCustomerBody = CustomerFields.strict();
export const UpdateCustomerBody = CustomerFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchCustomersQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportCustomersQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Customer = z.infer<typeof CustomerFields> & { id: string };
src/schemas/giftCards.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const GiftCardParams = z.object({ id: z.string().uuid() });
export const GiftCardFields = z.object({
code: z.string().regex(/^[A-Z0-9]{16}$/),
balanceCents: z.number().int().nonnegative(),
currency: z.string().length(3),
});
export const ListGiftCardsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateGiftCardBody = GiftCardFields.strict();
export const UpdateGiftCardBody = GiftCardFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchGiftCardsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportGiftCardsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type GiftCard = z.infer<typeof GiftCardFields> & { id: string };
src/schemas/inventory.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const StockLevelParams = z.object({ id: z.string().uuid() });
export const StockLevelFields = z.object({
sku: z.string().min(3).max(32),
warehouseId: z.string().uuid(),
onHand: z.number().int(),
reserved: z.number().int().nonnegative(),
});
export const ListInventoryQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateStockLevelBody = StockLevelFields.strict();
export const UpdateStockLevelBody = StockLevelFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchInventoryQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportInventoryQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type StockLevel = z.infer<typeof StockLevelFields> & { id: string };
src/schemas/invoices.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const InvoiceParams = z.object({ id: z.string().uuid() });
export const InvoiceFields = z.object({
number: z.string().regex(/^INV-\d{8}$/),
orderId: z.string().uuid(),
dueAt: z.string().datetime(),
totalCents: z.number().int().nonnegative(),
});
export const ListInvoicesQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateInvoiceBody = InvoiceFields.strict();
export const UpdateInvoiceBody = InvoiceFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchInvoicesQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportInvoicesQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Invoice = z.infer<typeof InvoiceFields> & { id: string };
src/schemas/loyalty.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const LoyaltyAccountParams = z.object({ id: z.string().uuid() });
export const LoyaltyAccountFields = z.object({
customerId: z.string().uuid(),
points: z.number().int().nonnegative(),
tier: z.enum(['bronze', 'silver', 'gold']),
});
export const ListLoyaltyQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateLoyaltyAccountBody = LoyaltyAccountFields.strict();
export const UpdateLoyaltyAccountBody = LoyaltyAccountFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchLoyaltyQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportLoyaltyQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type LoyaltyAccount = z.infer<typeof LoyaltyAccountFields> & { id: string };
src/schemas/media.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const MediaAssetParams = z.object({ id: z.string().uuid() });
export const MediaAssetFields = z.object({
productId: z.string().uuid(),
url: z.string().url(),
altText: z.string().max(300),
position: z.number().int().min(0),
});
export const ListMediaQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateMediaAssetBody = MediaAssetFields.strict();
export const UpdateMediaAssetBody = MediaAssetFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchMediaQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportMediaQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type MediaAsset = z.infer<typeof MediaAssetFields> & { id: string };
src/schemas/notifications.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const NotificationParams = z.object({ id: z.string().uuid() });
export const NotificationFields = z.object({
customerId: z.string().uuid(),
channel: z.enum(['email', 'sms', 'push']),
template: z.string().max(80),
});
export const ListNotificationsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateNotificationBody = NotificationFields.strict();
export const UpdateNotificationBody = NotificationFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchNotificationsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportNotificationsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Notification = z.infer<typeof NotificationFields> & { id: string };
src/schemas/orders.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const OrderParams = z.object({ id: z.string().uuid() });
export const OrderFields = z.object({
number: z.string().regex(/^SO-\d{8}$/),
customerId: z.string().uuid(),
totalCents: z.number().int().nonnegative(),
status: z.enum(['pending', 'paid', 'shipped', 'cancelled']),
});
export const ListOrdersQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateOrderBody = OrderFields.strict();
export const UpdateOrderBody = OrderFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchOrdersQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportOrdersQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Order = z.infer<typeof OrderFields> & { id: string };
src/schemas/payments.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const PaymentParams = z.object({ id: z.string().uuid() });
export const PaymentFields = z.object({
orderId: z.string().uuid(),
provider: z.enum(['card', 'paypal', 'invoice']),
amountCents: z.number().int().positive(),
reference: z.string().max(64),
});
export const ListPaymentsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreatePaymentBody = PaymentFields.strict();
export const UpdatePaymentBody = PaymentFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchPaymentsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportPaymentsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Payment = z.infer<typeof PaymentFields> & { id: string };
src/schemas/preferences.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const PreferenceParams = z.object({ id: z.string().uuid() });
export const PreferenceFields = z.object({
customerId: z.string().uuid(),
locale: z.string().max(10),
currency: z.string().length(3),
});
export const ListPreferencesQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreatePreferenceBody = PreferenceFields.strict();
export const UpdatePreferenceBody = PreferenceFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchPreferencesQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportPreferencesQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Preference = z.infer<typeof PreferenceFields> & { id: string };
src/schemas/prices.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const PriceParams = z.object({ id: z.string().uuid() });
export const PriceFields = z.object({
productId: z.string().uuid(),
currency: z.string().length(3),
amountCents: z.number().int().nonnegative(),
validFrom: z.string().datetime(),
});
export const ListPricesQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreatePriceBody = PriceFields.strict();
export const UpdatePriceBody = PriceFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchPricesQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportPricesQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Price = z.infer<typeof PriceFields> & { id: string };
src/schemas/products.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const ProductParams = z.object({ id: z.string().uuid() });
export const ProductFields = z.object({
sku: z.string().min(3).max(32),
name: z.string().min(1).max(200),
priceCents: z.number().int().nonnegative(),
status: z.enum(['draft', 'active', 'archived']),
});
export const ListProductsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateProductBody = ProductFields.strict();
export const UpdateProductBody = ProductFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchProductsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportProductsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Product = z.infer<typeof ProductFields> & { id: string };
src/schemas/quotes.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const QuoteParams = z.object({ id: z.string().uuid() });
export const QuoteFields = z.object({
number: z.string().regex(/^QT-\d{8}$/),
customerId: z.string().uuid(),
validUntil: z.string().datetime(),
});
export const ListQuotesQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateQuoteBody = QuoteFields.strict();
export const UpdateQuoteBody = QuoteFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchQuotesQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportQuotesQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Quote = z.infer<typeof QuoteFields> & { id: string };
src/schemas/refunds.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const RefundParams = z.object({ id: z.string().uuid() });
export const RefundFields = z.object({
paymentId: z.string().uuid(),
amountCents: z.number().int().positive(),
reason: z.enum(['damaged', 'late', 'other']),
});
export const ListRefundsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateRefundBody = RefundFields.strict();
export const UpdateRefundBody = RefundFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchRefundsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportRefundsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Refund = z.infer<typeof RefundFields> & { id: string };
src/schemas/returns.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const ReturnRequestParams = z.object({ id: z.string().uuid() });
export const ReturnRequestFields = z.object({
orderId: z.string().uuid(),
lineIds: z.array(z.string().uuid()).min(1),
reason: z.string().max(500),
});
export const ListReturnsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateReturnRequestBody = ReturnRequestFields.strict();
export const UpdateReturnRequestBody = ReturnRequestFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchReturnsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportReturnsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type ReturnRequest = z.infer<typeof ReturnRequestFields> & { id: string };
src/schemas/reviews.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const ProductReviewParams = z.object({ id: z.string().uuid() });
export const ProductReviewFields = z.object({
productId: z.string().uuid(),
rating: z.number().int().min(1).max(5),
title: z.string().max(120),
body: z.string().max(5000),
});
export const ListReviewsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateProductReviewBody = ProductReviewFields.strict();
export const UpdateProductReviewBody = ProductReviewFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchReviewsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportReviewsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type ProductReview = z.infer<typeof ProductReviewFields> & { id: string };
src/schemas/sessions.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const SessionParams = z.object({ id: z.string().uuid() });
export const SessionFields = z.object({
customerId: z.string().uuid(),
userAgent: z.string().max(400),
expiresAt: z.string().datetime(),
});
export const ListSessionsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateSessionBody = SessionFields.strict();
export const UpdateSessionBody = SessionFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchSessionsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportSessionsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Session = z.infer<typeof SessionFields> & { id: string };
src/schemas/shipments.ts
+34 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const ShipmentParams = z.object({ id: z.string().uuid() });
export const ShipmentFields = z.object({
orderId: z.string().uuid(),
carrier: z.string().max(40),
trackingNumber: z.string().max(64),
shippedAt: z.string().datetime().nullable(),
});
export const ListShipmentsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateShipmentBody = ShipmentFields.strict();
export const UpdateShipmentBody = ShipmentFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchShipmentsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportShipmentsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Shipment = z.infer<typeof ShipmentFields> & { id: string };
src/schemas/subscriptions.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const SubscriptionParams = z.object({ id: z.string().uuid() });
export const SubscriptionFields = z.object({
customerId: z.string().uuid(),
plan: z.enum(['monthly', 'quarterly', 'yearly']),
renewsAt: z.string().datetime(),
});
export const ListSubscriptionsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateSubscriptionBody = SubscriptionFields.strict();
export const UpdateSubscriptionBody = SubscriptionFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchSubscriptionsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportSubscriptionsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Subscription = z.infer<typeof SubscriptionFields> & { id: string };
src/schemas/teams.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const TeamParams = z.object({ id: z.string().uuid() });
export const TeamFields = z.object({
slug: z.string().regex(/^[a-z0-9-]+$/),
name: z.string().min(1).max(120),
ownerId: z.string().uuid(),
});
export const ListTeamsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateTeamBody = TeamFields.strict();
export const UpdateTeamBody = TeamFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchTeamsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportTeamsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Team = z.infer<typeof TeamFields> & { id: string };
src/schemas/variants.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const VariantParams = z.object({ id: z.string().uuid() });
export const VariantFields = z.object({
productId: z.string().uuid(),
sku: z.string().min(3).max(32),
options: z.record(z.string(), z.string()),
});
export const ListVariantsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateVariantBody = VariantFields.strict();
export const UpdateVariantBody = VariantFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchVariantsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportVariantsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Variant = z.infer<typeof VariantFields> & { id: string };
src/schemas/wishlists.ts
+33 -0
Difftastic 0.69.0 · TypeScript: added file, no line evidence

Placing the discussions of this file for the layout of this page…

import { z } from 'zod';
export const WishlistParams = z.object({ id: z.string().uuid() });
export const WishlistFields = z.object({
customerId: z.string().uuid(),
name: z.string().min(1).max(80),
productIds: z.array(z.string().uuid()).max(200),
});
export const ListWishlistsQuery = z.object({
limit: z.coerce.number().int().min(1).max(100).default(20),
cursor: z.string().uuid().optional(),
});
export const CreateWishlistBody = WishlistFields.strict();
export const UpdateWishlistBody = WishlistFields.partial().strict().refine(
(body) => Object.keys(body).length > 0,
'Send at least one field to change'
);
export const SearchWishlistsQuery = z.object({
q: z.string().trim().min(2).max(100),
limit: z.coerce.number().int().min(1).max(50).default(20),
});
export const ExportWishlistsQuery = z.object({
format: z.enum(['csv', 'json']).default('csv'),
limit: z.coerce.number().int().min(1).max(100000).default(100000),
});
export type Wishlist = z.infer<typeof WishlistFields> & { id: string };

Handler tests

Each handler test calls the handler through invoke instead of starting the Express app, and adds a request without a session.

test/handlers/addresses/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createAddress } from '../../../src/handlers/addresses/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /addresses', function () {test('create addresses answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createAddress, {
resetDatabase(done); method: 'POST',
}); url: '/addresses',
user: await signedInUser(),
it('answers 201', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', line1: 'line1-1', city: 'city-1', postcode: 'postcode-1', country: 'AU' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/addresses')
.set('Authorization', 'Bearer ' + token)test('create addresses rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', line1: 'line1-1', city: 'city-1', postcode: 'postcode-1', country: 'AU' }) const response = await invoke(createAddress, {
.expect(201) method: 'POST',
.end(done); url: '/addresses',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /addresses', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/addresses')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', line1: 'line1-1', city: 'city-1', postcode: 'postcode-1', country: 'AU' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createAddress } from '../../../src/handlers/addresses/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create addresses answers 201 for a signed-in user', async () => {
const response = await invoke(createAddress, {
method: 'POST',
url: '/addresses',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', line1: 'line1-1', city: 'city-1', postcode: 'postcode-1', country: 'AU' },
});
assert.equal(response.status, 201);
});
test('create addresses rejects a request without a session', async () => {
const response = await invoke(createAddress, {
method: 'POST',
url: '/addresses',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/addresses/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteAddress } from '../../../src/handlers/addresses/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete addresses answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteAddress, {
resetDatabase(done); method: 'DELETE',
}); url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete addresses rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteAddress, {
.expect(204) method: 'DELETE',
.end(done); url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteAddress } from '../../../src/handlers/addresses/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete addresses answers 204 for a signed-in user', async () => {
const response = await invoke(deleteAddress, {
method: 'DELETE',
url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete addresses rejects a request without a session', async () => {
const response = await invoke(deleteAddress, {
method: 'DELETE',
url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/addresses/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportAddresses } from '../../../src/handlers/addresses/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /addresses/export', function () {test('export addresses answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportAddresses, {
resetDatabase(done); method: 'GET',
}); url: '/addresses/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/addresses/export?format=json')test('export addresses rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportAddresses, {
.expect(200) method: 'GET',
.end(done); url: '/addresses/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /addresses/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/addresses/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportAddresses } from '../../../src/handlers/addresses/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export addresses answers 200 for a signed-in user', async () => {
const response = await invoke(exportAddresses, {
method: 'GET',
url: '/addresses/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export addresses rejects a request without a session', async () => {
const response = await invoke(exportAddresses, {
method: 'GET',
url: '/addresses/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/addresses/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getAddress } from '../../../src/handlers/addresses/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get addresses answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getAddress, {
resetDatabase(done); method: 'GET',
}); url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get addresses rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getAddress, {
.expect(200) method: 'GET',
.end(done); url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getAddress } from '../../../src/handlers/addresses/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get addresses answers 200 for a signed-in user', async () => {
const response = await invoke(getAddress, {
method: 'GET',
url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get addresses rejects a request without a session', async () => {
const response = await invoke(getAddress, {
method: 'GET',
url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/addresses/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listAddresses } from '../../../src/handlers/addresses/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /addresses', function () {test('list addresses answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listAddresses, {
resetDatabase(done); method: 'GET',
}); url: '/addresses',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/addresses')test('list addresses rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listAddresses, {
.expect(200) method: 'GET',
.end(done); url: '/addresses',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /addresses', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/addresses')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listAddresses } from '../../../src/handlers/addresses/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list addresses answers 200 for a signed-in user', async () => {
const response = await invoke(listAddresses, {
method: 'GET',
url: '/addresses',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list addresses rejects a request without a session', async () => {
const response = await invoke(listAddresses, {
method: 'GET',
url: '/addresses',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/addresses/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchAddresses } from '../../../src/handlers/addresses/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /addresses/search', function () {test('search addresses answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchAddresses, {
resetDatabase(done); method: 'GET',
}); url: '/addresses/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/addresses/search?q=blue')test('search addresses rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchAddresses, {
.expect(200) method: 'GET',
.end(done); url: '/addresses/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /addresses/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/addresses/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchAddresses } from '../../../src/handlers/addresses/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search addresses answers 200 for a signed-in user', async () => {
const response = await invoke(searchAddresses, {
method: 'GET',
url: '/addresses/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search addresses rejects a request without a session', async () => {
const response = await invoke(searchAddresses, {
method: 'GET',
url: '/addresses/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/addresses/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateAddress } from '../../../src/handlers/addresses/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update addresses answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateAddress, {
resetDatabase(done); method: 'PATCH',
}); url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', line1: 'line1-1', city: 'city-1', postcode: 'postcode-1', country: 'AU' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update addresses rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', line1: 'line1-1', city: 'city-1', postcode: 'postcode-1', country: 'AU' }) const response = await invoke(updateAddress, {
.expect(200) method: 'PATCH',
.end(done); url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', line1: 'line1-1', city: 'city-1', postcode: 'postcode-1', country: 'AU' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateAddress } from '../../../src/handlers/addresses/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update addresses answers 200 for a signed-in user', async () => {
const response = await invoke(updateAddress, {
method: 'PATCH',
url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', line1: 'line1-1', city: 'city-1', postcode: 'postcode-1', country: 'AU' },
});
assert.equal(response.status, 200);
});
test('update addresses rejects a request without a session', async () => {
const response = await invoke(updateAddress, {
method: 'PATCH',
url: '/addresses/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/apiKeys/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createApiKey } from '../../../src/handlers/apiKeys/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /apiKeys', function () {test('create apiKeys answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createApiKey, {
resetDatabase(done); method: 'POST',
}); url: '/apiKeys',
user: await signedInUser(),
it('answers 201', function (done) { body: { teamId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', label: 'label-1', scopes: [] },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/apiKeys')
.set('Authorization', 'Bearer ' + token)test('create apiKeys rejects a request without a session', async () => {
.send({ teamId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', label: 'label-1', scopes: [] }) const response = await invoke(createApiKey, {
.expect(201) method: 'POST',
.end(done); url: '/apiKeys',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /apiKeys', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/apiKeys')
.set('Authorization', 'Bearer ' + token)
.send({ teamId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', label: 'label-1', scopes: [] })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createApiKey } from '../../../src/handlers/apiKeys/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create apiKeys answers 201 for a signed-in user', async () => {
const response = await invoke(createApiKey, {
method: 'POST',
url: '/apiKeys',
user: await signedInUser(),
body: { teamId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', label: 'label-1', scopes: [] },
});
assert.equal(response.status, 201);
});
test('create apiKeys rejects a request without a session', async () => {
const response = await invoke(createApiKey, {
method: 'POST',
url: '/apiKeys',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/apiKeys/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteApiKey } from '../../../src/handlers/apiKeys/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete apiKeys answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteApiKey, {
resetDatabase(done); method: 'DELETE',
}); url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete apiKeys rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteApiKey, {
.expect(204) method: 'DELETE',
.end(done); url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteApiKey } from '../../../src/handlers/apiKeys/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete apiKeys answers 204 for a signed-in user', async () => {
const response = await invoke(deleteApiKey, {
method: 'DELETE',
url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete apiKeys rejects a request without a session', async () => {
const response = await invoke(deleteApiKey, {
method: 'DELETE',
url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/apiKeys/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportApiKeys } from '../../../src/handlers/apiKeys/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /apiKeys/export', function () {test('export apiKeys answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportApiKeys, {
resetDatabase(done); method: 'GET',
}); url: '/apiKeys/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/apiKeys/export?format=json')test('export apiKeys rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportApiKeys, {
.expect(200) method: 'GET',
.end(done); url: '/apiKeys/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /apiKeys/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/apiKeys/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportApiKeys } from '../../../src/handlers/apiKeys/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export apiKeys answers 200 for a signed-in user', async () => {
const response = await invoke(exportApiKeys, {
method: 'GET',
url: '/apiKeys/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export apiKeys rejects a request without a session', async () => {
const response = await invoke(exportApiKeys, {
method: 'GET',
url: '/apiKeys/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/apiKeys/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getApiKey } from '../../../src/handlers/apiKeys/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get apiKeys answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getApiKey, {
resetDatabase(done); method: 'GET',
}); url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get apiKeys rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getApiKey, {
.expect(200) method: 'GET',
.end(done); url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getApiKey } from '../../../src/handlers/apiKeys/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get apiKeys answers 200 for a signed-in user', async () => {
const response = await invoke(getApiKey, {
method: 'GET',
url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get apiKeys rejects a request without a session', async () => {
const response = await invoke(getApiKey, {
method: 'GET',
url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/apiKeys/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listApiKeys } from '../../../src/handlers/apiKeys/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /apiKeys', function () {test('list apiKeys answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listApiKeys, {
resetDatabase(done); method: 'GET',
}); url: '/apiKeys',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/apiKeys')test('list apiKeys rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listApiKeys, {
.expect(200) method: 'GET',
.end(done); url: '/apiKeys',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /apiKeys', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/apiKeys')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listApiKeys } from '../../../src/handlers/apiKeys/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list apiKeys answers 200 for a signed-in user', async () => {
const response = await invoke(listApiKeys, {
method: 'GET',
url: '/apiKeys',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list apiKeys rejects a request without a session', async () => {
const response = await invoke(listApiKeys, {
method: 'GET',
url: '/apiKeys',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/apiKeys/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchApiKeys } from '../../../src/handlers/apiKeys/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /apiKeys/search', function () {test('search apiKeys answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchApiKeys, {
resetDatabase(done); method: 'GET',
}); url: '/apiKeys/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/apiKeys/search?q=blue')test('search apiKeys rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchApiKeys, {
.expect(200) method: 'GET',
.end(done); url: '/apiKeys/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /apiKeys/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/apiKeys/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchApiKeys } from '../../../src/handlers/apiKeys/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search apiKeys answers 200 for a signed-in user', async () => {
const response = await invoke(searchApiKeys, {
method: 'GET',
url: '/apiKeys/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search apiKeys rejects a request without a session', async () => {
const response = await invoke(searchApiKeys, {
method: 'GET',
url: '/apiKeys/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/apiKeys/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateApiKey } from '../../../src/handlers/apiKeys/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update apiKeys answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateApiKey, {
resetDatabase(done); method: 'PATCH',
}); url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { teamId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', label: 'label-1', scopes: [] },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update apiKeys rejects a request without a session', async () => {
.send({ teamId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', label: 'label-1', scopes: [] }) const response = await invoke(updateApiKey, {
.expect(200) method: 'PATCH',
.end(done); url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ teamId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', label: 'label-1', scopes: [] })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateApiKey } from '../../../src/handlers/apiKeys/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update apiKeys answers 200 for a signed-in user', async () => {
const response = await invoke(updateApiKey, {
method: 'PATCH',
url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { teamId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', label: 'label-1', scopes: [] },
});
assert.equal(response.status, 200);
});
test('update apiKeys rejects a request without a session', async () => {
const response = await invoke(updateApiKey, {
method: 'PATCH',
url: '/apiKeys/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/attributes/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createAttribute } from '../../../src/handlers/attributes/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /attributes', function () {test('create attributes answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createAttribute, {
resetDatabase(done); method: 'POST',
}); url: '/attributes',
user: await signedInUser(),
it('answers 201', function (done) { body: { code: 'code-1', label: 'label-1', kind: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/attributes')
.set('Authorization', 'Bearer ' + token)test('create attributes rejects a request without a session', async () => {
.send({ code: 'code-1', label: 'label-1', kind: 3 }) const response = await invoke(createAttribute, {
.expect(201) method: 'POST',
.end(done); url: '/attributes',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /attributes', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/attributes')
.set('Authorization', 'Bearer ' + token)
.send({ code: 'code-1', label: 'label-1', kind: 3 })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createAttribute } from '../../../src/handlers/attributes/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create attributes answers 201 for a signed-in user', async () => {
const response = await invoke(createAttribute, {
method: 'POST',
url: '/attributes',
user: await signedInUser(),
body: { code: 'code-1', label: 'label-1', kind: 3 },
});
assert.equal(response.status, 201);
});
test('create attributes rejects a request without a session', async () => {
const response = await invoke(createAttribute, {
method: 'POST',
url: '/attributes',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/attributes/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteAttribute } from '../../../src/handlers/attributes/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete attributes answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteAttribute, {
resetDatabase(done); method: 'DELETE',
}); url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete attributes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteAttribute, {
.expect(204) method: 'DELETE',
.end(done); url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteAttribute } from '../../../src/handlers/attributes/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete attributes answers 204 for a signed-in user', async () => {
const response = await invoke(deleteAttribute, {
method: 'DELETE',
url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete attributes rejects a request without a session', async () => {
const response = await invoke(deleteAttribute, {
method: 'DELETE',
url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/attributes/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportAttributes } from '../../../src/handlers/attributes/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /attributes/export', function () {test('export attributes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportAttributes, {
resetDatabase(done); method: 'GET',
}); url: '/attributes/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/attributes/export?format=json')test('export attributes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportAttributes, {
.expect(200) method: 'GET',
.end(done); url: '/attributes/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /attributes/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/attributes/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportAttributes } from '../../../src/handlers/attributes/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export attributes answers 200 for a signed-in user', async () => {
const response = await invoke(exportAttributes, {
method: 'GET',
url: '/attributes/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export attributes rejects a request without a session', async () => {
const response = await invoke(exportAttributes, {
method: 'GET',
url: '/attributes/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/attributes/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getAttribute } from '../../../src/handlers/attributes/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get attributes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getAttribute, {
resetDatabase(done); method: 'GET',
}); url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get attributes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getAttribute, {
.expect(200) method: 'GET',
.end(done); url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getAttribute } from '../../../src/handlers/attributes/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get attributes answers 200 for a signed-in user', async () => {
const response = await invoke(getAttribute, {
method: 'GET',
url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get attributes rejects a request without a session', async () => {
const response = await invoke(getAttribute, {
method: 'GET',
url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/attributes/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listAttributes } from '../../../src/handlers/attributes/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /attributes', function () {test('list attributes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listAttributes, {
resetDatabase(done); method: 'GET',
}); url: '/attributes',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/attributes')test('list attributes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listAttributes, {
.expect(200) method: 'GET',
.end(done); url: '/attributes',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /attributes', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/attributes')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listAttributes } from '../../../src/handlers/attributes/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list attributes answers 200 for a signed-in user', async () => {
const response = await invoke(listAttributes, {
method: 'GET',
url: '/attributes',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list attributes rejects a request without a session', async () => {
const response = await invoke(listAttributes, {
method: 'GET',
url: '/attributes',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/attributes/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchAttributes } from '../../../src/handlers/attributes/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /attributes/search', function () {test('search attributes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchAttributes, {
resetDatabase(done); method: 'GET',
}); url: '/attributes/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/attributes/search?q=blue')test('search attributes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchAttributes, {
.expect(200) method: 'GET',
.end(done); url: '/attributes/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /attributes/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/attributes/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchAttributes } from '../../../src/handlers/attributes/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search attributes answers 200 for a signed-in user', async () => {
const response = await invoke(searchAttributes, {
method: 'GET',
url: '/attributes/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search attributes rejects a request without a session', async () => {
const response = await invoke(searchAttributes, {
method: 'GET',
url: '/attributes/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/attributes/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateAttribute } from '../../../src/handlers/attributes/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update attributes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateAttribute, {
resetDatabase(done); method: 'PATCH',
}); url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { code: 'code-1', label: 'label-1', kind: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update attributes rejects a request without a session', async () => {
.send({ code: 'code-1', label: 'label-1', kind: 3 }) const response = await invoke(updateAttribute, {
.expect(200) method: 'PATCH',
.end(done); url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ code: 'code-1', label: 'label-1', kind: 3 })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateAttribute } from '../../../src/handlers/attributes/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update attributes answers 200 for a signed-in user', async () => {
const response = await invoke(updateAttribute, {
method: 'PATCH',
url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { code: 'code-1', label: 'label-1', kind: 3 },
});
assert.equal(response.status, 200);
});
test('update attributes rejects a request without a session', async () => {
const response = await invoke(updateAttribute, {
method: 'PATCH',
url: '/attributes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/brands/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createBrand } from '../../../src/handlers/brands/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /brands', function () {test('create brands answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createBrand, {
resetDatabase(done); method: 'POST',
}); url: '/brands',
user: await signedInUser(),
it('answers 201', function (done) { body: { slug: 'slug-1', name: 'name-1', website: 'https://cdn.example.com/a.jpg' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/brands')
.set('Authorization', 'Bearer ' + token)test('create brands rejects a request without a session', async () => {
.send({ slug: 'slug-1', name: 'name-1', website: 'https://cdn.example.com/a.jpg' }) const response = await invoke(createBrand, {
.expect(201) method: 'POST',
.end(done); url: '/brands',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /brands', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/brands')
.set('Authorization', 'Bearer ' + token)
.send({ slug: 'slug-1', name: 'name-1', website: 'https://cdn.example.com/a.jpg' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createBrand } from '../../../src/handlers/brands/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create brands answers 201 for a signed-in user', async () => {
const response = await invoke(createBrand, {
method: 'POST',
url: '/brands',
user: await signedInUser(),
body: { slug: 'slug-1', name: 'name-1', website: 'https://cdn.example.com/a.jpg' },
});
assert.equal(response.status, 201);
});
test('create brands rejects a request without a session', async () => {
const response = await invoke(createBrand, {
method: 'POST',
url: '/brands',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/brands/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteBrand } from '../../../src/handlers/brands/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete brands answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteBrand, {
resetDatabase(done); method: 'DELETE',
}); url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete brands rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteBrand, {
.expect(204) method: 'DELETE',
.end(done); url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteBrand } from '../../../src/handlers/brands/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete brands answers 204 for a signed-in user', async () => {
const response = await invoke(deleteBrand, {
method: 'DELETE',
url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete brands rejects a request without a session', async () => {
const response = await invoke(deleteBrand, {
method: 'DELETE',
url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/brands/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportBrands } from '../../../src/handlers/brands/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /brands/export', function () {test('export brands answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportBrands, {
resetDatabase(done); method: 'GET',
}); url: '/brands/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/brands/export?format=json')test('export brands rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportBrands, {
.expect(200) method: 'GET',
.end(done); url: '/brands/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /brands/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/brands/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportBrands } from '../../../src/handlers/brands/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export brands answers 200 for a signed-in user', async () => {
const response = await invoke(exportBrands, {
method: 'GET',
url: '/brands/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export brands rejects a request without a session', async () => {
const response = await invoke(exportBrands, {
method: 'GET',
url: '/brands/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/brands/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getBrand } from '../../../src/handlers/brands/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get brands answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getBrand, {
resetDatabase(done); method: 'GET',
}); url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get brands rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getBrand, {
.expect(200) method: 'GET',
.end(done); url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getBrand } from '../../../src/handlers/brands/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get brands answers 200 for a signed-in user', async () => {
const response = await invoke(getBrand, {
method: 'GET',
url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get brands rejects a request without a session', async () => {
const response = await invoke(getBrand, {
method: 'GET',
url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/brands/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listBrands } from '../../../src/handlers/brands/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /brands', function () {test('list brands answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listBrands, {
resetDatabase(done); method: 'GET',
}); url: '/brands',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/brands')test('list brands rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listBrands, {
.expect(200) method: 'GET',
.end(done); url: '/brands',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /brands', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/brands')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listBrands } from '../../../src/handlers/brands/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list brands answers 200 for a signed-in user', async () => {
const response = await invoke(listBrands, {
method: 'GET',
url: '/brands',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list brands rejects a request without a session', async () => {
const response = await invoke(listBrands, {
method: 'GET',
url: '/brands',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/brands/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchBrands } from '../../../src/handlers/brands/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /brands/search', function () {test('search brands answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchBrands, {
resetDatabase(done); method: 'GET',
}); url: '/brands/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/brands/search?q=blue')test('search brands rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchBrands, {
.expect(200) method: 'GET',
.end(done); url: '/brands/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /brands/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/brands/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchBrands } from '../../../src/handlers/brands/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search brands answers 200 for a signed-in user', async () => {
const response = await invoke(searchBrands, {
method: 'GET',
url: '/brands/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search brands rejects a request without a session', async () => {
const response = await invoke(searchBrands, {
method: 'GET',
url: '/brands/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/brands/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateBrand } from '../../../src/handlers/brands/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update brands answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateBrand, {
resetDatabase(done); method: 'PATCH',
}); url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { slug: 'slug-1', name: 'name-1', website: 'https://cdn.example.com/a.jpg' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update brands rejects a request without a session', async () => {
.send({ slug: 'slug-1', name: 'name-1', website: 'https://cdn.example.com/a.jpg' }) const response = await invoke(updateBrand, {
.expect(200) method: 'PATCH',
.end(done); url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ slug: 'slug-1', name: 'name-1', website: 'https://cdn.example.com/a.jpg' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateBrand } from '../../../src/handlers/brands/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update brands answers 200 for a signed-in user', async () => {
const response = await invoke(updateBrand, {
method: 'PATCH',
url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { slug: 'slug-1', name: 'name-1', website: 'https://cdn.example.com/a.jpg' },
});
assert.equal(response.status, 200);
});
test('update brands rejects a request without a session', async () => {
const response = await invoke(updateBrand, {
method: 'PATCH',
url: '/brands/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/bundles/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createBundle } from '../../../src/handlers/bundles/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /bundles', function () {test('create bundles answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createBundle, {
resetDatabase(done); method: 'POST',
}); url: '/bundles',
user: await signedInUser(),
it('answers 201', function (done) { body: { sku: 'sku-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', discountPercent: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/bundles')
.set('Authorization', 'Bearer ' + token)test('create bundles rejects a request without a session', async () => {
.send({ sku: 'sku-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', discountPercent: 3 }) const response = await invoke(createBundle, {
.expect(201) method: 'POST',
.end(done); url: '/bundles',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /bundles', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/bundles')
.set('Authorization', 'Bearer ' + token)
.send({ sku: 'sku-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', discountPercent: 3 })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createBundle } from '../../../src/handlers/bundles/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create bundles answers 201 for a signed-in user', async () => {
const response = await invoke(createBundle, {
method: 'POST',
url: '/bundles',
user: await signedInUser(),
body: { sku: 'sku-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', discountPercent: 3 },
});
assert.equal(response.status, 201);
});
test('create bundles rejects a request without a session', async () => {
const response = await invoke(createBundle, {
method: 'POST',
url: '/bundles',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/bundles/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteBundle } from '../../../src/handlers/bundles/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete bundles answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteBundle, {
resetDatabase(done); method: 'DELETE',
}); url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete bundles rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteBundle, {
.expect(204) method: 'DELETE',
.end(done); url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteBundle } from '../../../src/handlers/bundles/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete bundles answers 204 for a signed-in user', async () => {
const response = await invoke(deleteBundle, {
method: 'DELETE',
url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete bundles rejects a request without a session', async () => {
const response = await invoke(deleteBundle, {
method: 'DELETE',
url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/bundles/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportBundles } from '../../../src/handlers/bundles/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /bundles/export', function () {test('export bundles answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportBundles, {
resetDatabase(done); method: 'GET',
}); url: '/bundles/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/bundles/export?format=json')test('export bundles rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportBundles, {
.expect(200) method: 'GET',
.end(done); url: '/bundles/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /bundles/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/bundles/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportBundles } from '../../../src/handlers/bundles/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export bundles answers 200 for a signed-in user', async () => {
const response = await invoke(exportBundles, {
method: 'GET',
url: '/bundles/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export bundles rejects a request without a session', async () => {
const response = await invoke(exportBundles, {
method: 'GET',
url: '/bundles/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/bundles/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getBundle } from '../../../src/handlers/bundles/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get bundles answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getBundle, {
resetDatabase(done); method: 'GET',
}); url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get bundles rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getBundle, {
.expect(200) method: 'GET',
.end(done); url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getBundle } from '../../../src/handlers/bundles/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get bundles answers 200 for a signed-in user', async () => {
const response = await invoke(getBundle, {
method: 'GET',
url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get bundles rejects a request without a session', async () => {
const response = await invoke(getBundle, {
method: 'GET',
url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/bundles/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listBundles } from '../../../src/handlers/bundles/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /bundles', function () {test('list bundles answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listBundles, {
resetDatabase(done); method: 'GET',
}); url: '/bundles',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/bundles')test('list bundles rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listBundles, {
.expect(200) method: 'GET',
.end(done); url: '/bundles',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /bundles', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/bundles')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listBundles } from '../../../src/handlers/bundles/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list bundles answers 200 for a signed-in user', async () => {
const response = await invoke(listBundles, {
method: 'GET',
url: '/bundles',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list bundles rejects a request without a session', async () => {
const response = await invoke(listBundles, {
method: 'GET',
url: '/bundles',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/bundles/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchBundles } from '../../../src/handlers/bundles/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /bundles/search', function () {test('search bundles answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchBundles, {
resetDatabase(done); method: 'GET',
}); url: '/bundles/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/bundles/search?q=blue')test('search bundles rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchBundles, {
.expect(200) method: 'GET',
.end(done); url: '/bundles/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /bundles/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/bundles/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchBundles } from '../../../src/handlers/bundles/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search bundles answers 200 for a signed-in user', async () => {
const response = await invoke(searchBundles, {
method: 'GET',
url: '/bundles/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search bundles rejects a request without a session', async () => {
const response = await invoke(searchBundles, {
method: 'GET',
url: '/bundles/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/bundles/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateBundle } from '../../../src/handlers/bundles/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update bundles answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateBundle, {
resetDatabase(done); method: 'PATCH',
}); url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { sku: 'sku-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', discountPercent: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update bundles rejects a request without a session', async () => {
.send({ sku: 'sku-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', discountPercent: 3 }) const response = await invoke(updateBundle, {
.expect(200) method: 'PATCH',
.end(done); url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ sku: 'sku-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', discountPercent: 3 })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateBundle } from '../../../src/handlers/bundles/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update bundles answers 200 for a signed-in user', async () => {
const response = await invoke(updateBundle, {
method: 'PATCH',
url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { sku: 'sku-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', discountPercent: 3 },
});
assert.equal(response.status, 200);
});
test('update bundles rejects a request without a session', async () => {
const response = await invoke(updateBundle, {
method: 'PATCH',
url: '/bundles/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/carts/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createCart } from '../../../src/handlers/carts/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /carts', function () {test('create carts answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createCart, {
resetDatabase(done); method: 'POST',
}); url: '/carts',
user: await signedInUser(),
it('answers 201', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', lines: [] },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/carts')
.set('Authorization', 'Bearer ' + token)test('create carts rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', lines: [] }) const response = await invoke(createCart, {
.expect(201) method: 'POST',
.end(done); url: '/carts',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /carts', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/carts')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', lines: [] })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createCart } from '../../../src/handlers/carts/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create carts answers 201 for a signed-in user', async () => {
const response = await invoke(createCart, {
method: 'POST',
url: '/carts',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', lines: [] },
});
assert.equal(response.status, 201);
});
test('create carts rejects a request without a session', async () => {
const response = await invoke(createCart, {
method: 'POST',
url: '/carts',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/carts/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteCart } from '../../../src/handlers/carts/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete carts answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteCart, {
resetDatabase(done); method: 'DELETE',
}); url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete carts rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteCart, {
.expect(204) method: 'DELETE',
.end(done); url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteCart } from '../../../src/handlers/carts/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete carts answers 204 for a signed-in user', async () => {
const response = await invoke(deleteCart, {
method: 'DELETE',
url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete carts rejects a request without a session', async () => {
const response = await invoke(deleteCart, {
method: 'DELETE',
url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/carts/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportCarts } from '../../../src/handlers/carts/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /carts/export', function () {test('export carts answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportCarts, {
resetDatabase(done); method: 'GET',
}); url: '/carts/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/carts/export?format=json')test('export carts rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportCarts, {
.expect(200) method: 'GET',
.end(done); url: '/carts/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /carts/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/carts/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportCarts } from '../../../src/handlers/carts/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export carts answers 200 for a signed-in user', async () => {
const response = await invoke(exportCarts, {
method: 'GET',
url: '/carts/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export carts rejects a request without a session', async () => {
const response = await invoke(exportCarts, {
method: 'GET',
url: '/carts/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/carts/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getCart } from '../../../src/handlers/carts/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get carts answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getCart, {
resetDatabase(done); method: 'GET',
}); url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get carts rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getCart, {
.expect(200) method: 'GET',
.end(done); url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getCart } from '../../../src/handlers/carts/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get carts answers 200 for a signed-in user', async () => {
const response = await invoke(getCart, {
method: 'GET',
url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get carts rejects a request without a session', async () => {
const response = await invoke(getCart, {
method: 'GET',
url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/carts/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listCarts } from '../../../src/handlers/carts/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /carts', function () {test('list carts answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listCarts, {
resetDatabase(done); method: 'GET',
}); url: '/carts',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/carts')test('list carts rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listCarts, {
.expect(200) method: 'GET',
.end(done); url: '/carts',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /carts', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/carts')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listCarts } from '../../../src/handlers/carts/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list carts answers 200 for a signed-in user', async () => {
const response = await invoke(listCarts, {
method: 'GET',
url: '/carts',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list carts rejects a request without a session', async () => {
const response = await invoke(listCarts, {
method: 'GET',
url: '/carts',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/carts/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchCarts } from '../../../src/handlers/carts/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /carts/search', function () {test('search carts answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchCarts, {
resetDatabase(done); method: 'GET',
}); url: '/carts/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/carts/search?q=blue')test('search carts rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchCarts, {
.expect(200) method: 'GET',
.end(done); url: '/carts/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /carts/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/carts/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchCarts } from '../../../src/handlers/carts/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search carts answers 200 for a signed-in user', async () => {
const response = await invoke(searchCarts, {
method: 'GET',
url: '/carts/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search carts rejects a request without a session', async () => {
const response = await invoke(searchCarts, {
method: 'GET',
url: '/carts/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/carts/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateCart } from '../../../src/handlers/carts/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update carts answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateCart, {
resetDatabase(done); method: 'PATCH',
}); url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', lines: [] },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update carts rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', lines: [] }) const response = await invoke(updateCart, {
.expect(200) method: 'PATCH',
.end(done); url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', lines: [] })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateCart } from '../../../src/handlers/carts/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update carts answers 200 for a signed-in user', async () => {
const response = await invoke(updateCart, {
method: 'PATCH',
url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', lines: [] },
});
assert.equal(response.status, 200);
});
test('update carts rejects a request without a session', async () => {
const response = await invoke(updateCart, {
method: 'PATCH',
url: '/carts/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/categories/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createCategory } from '../../../src/handlers/categories/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /categories', function () {test('create categories answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createCategory, {
resetDatabase(done); method: 'POST',
}); url: '/categories',
user: await signedInUser(),
it('answers 201', function (done) { body: { slug: 'slug-1', name: 'name-1', parentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', position: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/categories')
.set('Authorization', 'Bearer ' + token)test('create categories rejects a request without a session', async () => {
.send({ slug: 'slug-1', name: 'name-1', parentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', position: 3 }) const response = await invoke(createCategory, {
.expect(201) method: 'POST',
.end(done); url: '/categories',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /categories', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/categories')
.set('Authorization', 'Bearer ' + token)
.send({ slug: 'slug-1', name: 'name-1', parentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', position: 3 })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createCategory } from '../../../src/handlers/categories/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create categories answers 201 for a signed-in user', async () => {
const response = await invoke(createCategory, {
method: 'POST',
url: '/categories',
user: await signedInUser(),
body: { slug: 'slug-1', name: 'name-1', parentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', position: 3 },
});
assert.equal(response.status, 201);
});
test('create categories rejects a request without a session', async () => {
const response = await invoke(createCategory, {
method: 'POST',
url: '/categories',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/categories/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteCategory } from '../../../src/handlers/categories/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete categories answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteCategory, {
resetDatabase(done); method: 'DELETE',
}); url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete categories rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteCategory, {
.expect(204) method: 'DELETE',
.end(done); url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteCategory } from '../../../src/handlers/categories/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete categories answers 204 for a signed-in user', async () => {
const response = await invoke(deleteCategory, {
method: 'DELETE',
url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete categories rejects a request without a session', async () => {
const response = await invoke(deleteCategory, {
method: 'DELETE',
url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/categories/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportCategories } from '../../../src/handlers/categories/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /categories/export', function () {test('export categories answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportCategories, {
resetDatabase(done); method: 'GET',
}); url: '/categories/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/categories/export?format=json')test('export categories rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportCategories, {
.expect(200) method: 'GET',
.end(done); url: '/categories/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /categories/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/categories/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportCategories } from '../../../src/handlers/categories/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export categories answers 200 for a signed-in user', async () => {
const response = await invoke(exportCategories, {
method: 'GET',
url: '/categories/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export categories rejects a request without a session', async () => {
const response = await invoke(exportCategories, {
method: 'GET',
url: '/categories/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/categories/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getCategory } from '../../../src/handlers/categories/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get categories answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getCategory, {
resetDatabase(done); method: 'GET',
}); url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get categories rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getCategory, {
.expect(200) method: 'GET',
.end(done); url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getCategory } from '../../../src/handlers/categories/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get categories answers 200 for a signed-in user', async () => {
const response = await invoke(getCategory, {
method: 'GET',
url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get categories rejects a request without a session', async () => {
const response = await invoke(getCategory, {
method: 'GET',
url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/categories/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listCategories } from '../../../src/handlers/categories/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /categories', function () {test('list categories answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listCategories, {
resetDatabase(done); method: 'GET',
}); url: '/categories',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/categories')test('list categories rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listCategories, {
.expect(200) method: 'GET',
.end(done); url: '/categories',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /categories', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/categories')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listCategories } from '../../../src/handlers/categories/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list categories answers 200 for a signed-in user', async () => {
const response = await invoke(listCategories, {
method: 'GET',
url: '/categories',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list categories rejects a request without a session', async () => {
const response = await invoke(listCategories, {
method: 'GET',
url: '/categories',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/categories/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchCategories } from '../../../src/handlers/categories/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /categories/search', function () {test('search categories answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchCategories, {
resetDatabase(done); method: 'GET',
}); url: '/categories/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/categories/search?q=blue')test('search categories rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchCategories, {
.expect(200) method: 'GET',
.end(done); url: '/categories/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /categories/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/categories/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchCategories } from '../../../src/handlers/categories/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search categories answers 200 for a signed-in user', async () => {
const response = await invoke(searchCategories, {
method: 'GET',
url: '/categories/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search categories rejects a request without a session', async () => {
const response = await invoke(searchCategories, {
method: 'GET',
url: '/categories/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/categories/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateCategory } from '../../../src/handlers/categories/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update categories answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateCategory, {
resetDatabase(done); method: 'PATCH',
}); url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { slug: 'slug-1', name: 'name-1', parentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', position: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update categories rejects a request without a session', async () => {
.send({ slug: 'slug-1', name: 'name-1', parentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', position: 3 }) const response = await invoke(updateCategory, {
.expect(200) method: 'PATCH',
.end(done); url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ slug: 'slug-1', name: 'name-1', parentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', position: 3 })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateCategory } from '../../../src/handlers/categories/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update categories answers 200 for a signed-in user', async () => {
const response = await invoke(updateCategory, {
method: 'PATCH',
url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { slug: 'slug-1', name: 'name-1', parentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', position: 3 },
});
assert.equal(response.status, 200);
});
test('update categories rejects a request without a session', async () => {
const response = await invoke(updateCategory, {
method: 'PATCH',
url: '/categories/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/collections/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createCollection } from '../../../src/handlers/collections/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /collections', function () {test('create collections answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createCollection, {
resetDatabase(done); method: 'POST',
}); url: '/collections',
user: await signedInUser(),
it('answers 201', function (done) { body: { slug: 'slug-1', title: 'title-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/collections')
.set('Authorization', 'Bearer ' + token)test('create collections rejects a request without a session', async () => {
.send({ slug: 'slug-1', title: 'title-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' }) const response = await invoke(createCollection, {
.expect(201) method: 'POST',
.end(done); url: '/collections',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /collections', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/collections')
.set('Authorization', 'Bearer ' + token)
.send({ slug: 'slug-1', title: 'title-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createCollection } from '../../../src/handlers/collections/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create collections answers 201 for a signed-in user', async () => {
const response = await invoke(createCollection, {
method: 'POST',
url: '/collections',
user: await signedInUser(),
body: { slug: 'slug-1', title: 'title-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
});
assert.equal(response.status, 201);
});
test('create collections rejects a request without a session', async () => {
const response = await invoke(createCollection, {
method: 'POST',
url: '/collections',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/collections/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteCollection } from '../../../src/handlers/collections/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete collections answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteCollection, {
resetDatabase(done); method: 'DELETE',
}); url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete collections rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteCollection, {
.expect(204) method: 'DELETE',
.end(done); url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteCollection } from '../../../src/handlers/collections/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete collections answers 204 for a signed-in user', async () => {
const response = await invoke(deleteCollection, {
method: 'DELETE',
url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete collections rejects a request without a session', async () => {
const response = await invoke(deleteCollection, {
method: 'DELETE',
url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/collections/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportCollections } from '../../../src/handlers/collections/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /collections/export', function () {test('export collections answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportCollections, {
resetDatabase(done); method: 'GET',
}); url: '/collections/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/collections/export?format=json')test('export collections rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportCollections, {
.expect(200) method: 'GET',
.end(done); url: '/collections/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /collections/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/collections/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportCollections } from '../../../src/handlers/collections/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export collections answers 200 for a signed-in user', async () => {
const response = await invoke(exportCollections, {
method: 'GET',
url: '/collections/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export collections rejects a request without a session', async () => {
const response = await invoke(exportCollections, {
method: 'GET',
url: '/collections/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/collections/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getCollection } from '../../../src/handlers/collections/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get collections answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getCollection, {
resetDatabase(done); method: 'GET',
}); url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get collections rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getCollection, {
.expect(200) method: 'GET',
.end(done); url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getCollection } from '../../../src/handlers/collections/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get collections answers 200 for a signed-in user', async () => {
const response = await invoke(getCollection, {
method: 'GET',
url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get collections rejects a request without a session', async () => {
const response = await invoke(getCollection, {
method: 'GET',
url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/collections/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listCollections } from '../../../src/handlers/collections/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /collections', function () {test('list collections answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listCollections, {
resetDatabase(done); method: 'GET',
}); url: '/collections',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/collections')test('list collections rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listCollections, {
.expect(200) method: 'GET',
.end(done); url: '/collections',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /collections', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/collections')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listCollections } from '../../../src/handlers/collections/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list collections answers 200 for a signed-in user', async () => {
const response = await invoke(listCollections, {
method: 'GET',
url: '/collections',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list collections rejects a request without a session', async () => {
const response = await invoke(listCollections, {
method: 'GET',
url: '/collections',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/collections/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchCollections } from '../../../src/handlers/collections/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /collections/search', function () {test('search collections answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchCollections, {
resetDatabase(done); method: 'GET',
}); url: '/collections/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/collections/search?q=blue')test('search collections rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchCollections, {
.expect(200) method: 'GET',
.end(done); url: '/collections/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /collections/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/collections/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchCollections } from '../../../src/handlers/collections/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search collections answers 200 for a signed-in user', async () => {
const response = await invoke(searchCollections, {
method: 'GET',
url: '/collections/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search collections rejects a request without a session', async () => {
const response = await invoke(searchCollections, {
method: 'GET',
url: '/collections/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/collections/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateCollection } from '../../../src/handlers/collections/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update collections answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateCollection, {
resetDatabase(done); method: 'PATCH',
}); url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { slug: 'slug-1', title: 'title-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update collections rejects a request without a session', async () => {
.send({ slug: 'slug-1', title: 'title-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' }) const response = await invoke(updateCollection, {
.expect(200) method: 'PATCH',
.end(done); url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ slug: 'slug-1', title: 'title-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateCollection } from '../../../src/handlers/collections/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update collections answers 200 for a signed-in user', async () => {
const response = await invoke(updateCollection, {
method: 'PATCH',
url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { slug: 'slug-1', title: 'title-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
});
assert.equal(response.status, 200);
});
test('update collections rejects a request without a session', async () => {
const response = await invoke(updateCollection, {
method: 'PATCH',
url: '/collections/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/consents/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createConsent } from '../../../src/handlers/consents/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /consents', function () {test('create consents answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createConsent, {
resetDatabase(done); method: 'POST',
}); url: '/consents',
user: await signedInUser(),
it('answers 201', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', purpose: 'marketing', granted: true },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/consents')
.set('Authorization', 'Bearer ' + token)test('create consents rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', purpose: 'marketing', granted: true }) const response = await invoke(createConsent, {
.expect(201) method: 'POST',
.end(done); url: '/consents',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /consents', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/consents')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', purpose: 'marketing', granted: true })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createConsent } from '../../../src/handlers/consents/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create consents answers 201 for a signed-in user', async () => {
const response = await invoke(createConsent, {
method: 'POST',
url: '/consents',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', purpose: 'marketing', granted: true },
});
assert.equal(response.status, 201);
});
test('create consents rejects a request without a session', async () => {
const response = await invoke(createConsent, {
method: 'POST',
url: '/consents',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/consents/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteConsent } from '../../../src/handlers/consents/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete consents answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteConsent, {
resetDatabase(done); method: 'DELETE',
}); url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete consents rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteConsent, {
.expect(204) method: 'DELETE',
.end(done); url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteConsent } from '../../../src/handlers/consents/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete consents answers 204 for a signed-in user', async () => {
const response = await invoke(deleteConsent, {
method: 'DELETE',
url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete consents rejects a request without a session', async () => {
const response = await invoke(deleteConsent, {
method: 'DELETE',
url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/consents/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportConsents } from '../../../src/handlers/consents/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /consents/export', function () {test('export consents answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportConsents, {
resetDatabase(done); method: 'GET',
}); url: '/consents/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/consents/export?format=json')test('export consents rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportConsents, {
.expect(200) method: 'GET',
.end(done); url: '/consents/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /consents/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/consents/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportConsents } from '../../../src/handlers/consents/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export consents answers 200 for a signed-in user', async () => {
const response = await invoke(exportConsents, {
method: 'GET',
url: '/consents/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export consents rejects a request without a session', async () => {
const response = await invoke(exportConsents, {
method: 'GET',
url: '/consents/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/consents/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getConsent } from '../../../src/handlers/consents/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get consents answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getConsent, {
resetDatabase(done); method: 'GET',
}); url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get consents rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getConsent, {
.expect(200) method: 'GET',
.end(done); url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getConsent } from '../../../src/handlers/consents/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get consents answers 200 for a signed-in user', async () => {
const response = await invoke(getConsent, {
method: 'GET',
url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get consents rejects a request without a session', async () => {
const response = await invoke(getConsent, {
method: 'GET',
url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/consents/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listConsents } from '../../../src/handlers/consents/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /consents', function () {test('list consents answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listConsents, {
resetDatabase(done); method: 'GET',
}); url: '/consents',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/consents')test('list consents rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listConsents, {
.expect(200) method: 'GET',
.end(done); url: '/consents',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /consents', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/consents')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listConsents } from '../../../src/handlers/consents/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list consents answers 200 for a signed-in user', async () => {
const response = await invoke(listConsents, {
method: 'GET',
url: '/consents',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list consents rejects a request without a session', async () => {
const response = await invoke(listConsents, {
method: 'GET',
url: '/consents',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/consents/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchConsents } from '../../../src/handlers/consents/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /consents/search', function () {test('search consents answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchConsents, {
resetDatabase(done); method: 'GET',
}); url: '/consents/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/consents/search?q=blue')test('search consents rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchConsents, {
.expect(200) method: 'GET',
.end(done); url: '/consents/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /consents/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/consents/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchConsents } from '../../../src/handlers/consents/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search consents answers 200 for a signed-in user', async () => {
const response = await invoke(searchConsents, {
method: 'GET',
url: '/consents/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search consents rejects a request without a session', async () => {
const response = await invoke(searchConsents, {
method: 'GET',
url: '/consents/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/consents/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateConsent } from '../../../src/handlers/consents/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update consents answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateConsent, {
resetDatabase(done); method: 'PATCH',
}); url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', purpose: 'marketing', granted: true },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update consents rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', purpose: 'marketing', granted: true }) const response = await invoke(updateConsent, {
.expect(200) method: 'PATCH',
.end(done); url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', purpose: 'marketing', granted: true })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateConsent } from '../../../src/handlers/consents/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update consents answers 200 for a signed-in user', async () => {
const response = await invoke(updateConsent, {
method: 'PATCH',
url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', purpose: 'marketing', granted: true },
});
assert.equal(response.status, 200);
});
test('update consents rejects a request without a session', async () => {
const response = await invoke(updateConsent, {
method: 'PATCH',
url: '/consents/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/coupons/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createCoupon } from '../../../src/handlers/coupons/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /coupons', function () {test('create coupons answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createCoupon, {
resetDatabase(done); method: 'POST',
}); url: '/coupons',
user: await signedInUser(),
it('answers 201', function (done) { body: { code: 'code-1', percentOff: 3, expiresAt: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/coupons')
.set('Authorization', 'Bearer ' + token)test('create coupons rejects a request without a session', async () => {
.send({ code: 'code-1', percentOff: 3, expiresAt: '2026-10-01T09:00:00.000Z' }) const response = await invoke(createCoupon, {
.expect(201) method: 'POST',
.end(done); url: '/coupons',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /coupons', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/coupons')
.set('Authorization', 'Bearer ' + token)
.send({ code: 'code-1', percentOff: 3, expiresAt: '2026-10-01T09:00:00.000Z' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createCoupon } from '../../../src/handlers/coupons/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create coupons answers 201 for a signed-in user', async () => {
const response = await invoke(createCoupon, {
method: 'POST',
url: '/coupons',
user: await signedInUser(),
body: { code: 'code-1', percentOff: 3, expiresAt: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 201);
});
test('create coupons rejects a request without a session', async () => {
const response = await invoke(createCoupon, {
method: 'POST',
url: '/coupons',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/coupons/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteCoupon } from '../../../src/handlers/coupons/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete coupons answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteCoupon, {
resetDatabase(done); method: 'DELETE',
}); url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete coupons rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteCoupon, {
.expect(204) method: 'DELETE',
.end(done); url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteCoupon } from '../../../src/handlers/coupons/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete coupons answers 204 for a signed-in user', async () => {
const response = await invoke(deleteCoupon, {
method: 'DELETE',
url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete coupons rejects a request without a session', async () => {
const response = await invoke(deleteCoupon, {
method: 'DELETE',
url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/coupons/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportCoupons } from '../../../src/handlers/coupons/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /coupons/export', function () {test('export coupons answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportCoupons, {
resetDatabase(done); method: 'GET',
}); url: '/coupons/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/coupons/export?format=json')test('export coupons rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportCoupons, {
.expect(200) method: 'GET',
.end(done); url: '/coupons/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /coupons/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/coupons/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportCoupons } from '../../../src/handlers/coupons/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export coupons answers 200 for a signed-in user', async () => {
const response = await invoke(exportCoupons, {
method: 'GET',
url: '/coupons/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export coupons rejects a request without a session', async () => {
const response = await invoke(exportCoupons, {
method: 'GET',
url: '/coupons/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/coupons/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getCoupon } from '../../../src/handlers/coupons/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get coupons answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getCoupon, {
resetDatabase(done); method: 'GET',
}); url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get coupons rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getCoupon, {
.expect(200) method: 'GET',
.end(done); url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getCoupon } from '../../../src/handlers/coupons/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get coupons answers 200 for a signed-in user', async () => {
const response = await invoke(getCoupon, {
method: 'GET',
url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get coupons rejects a request without a session', async () => {
const response = await invoke(getCoupon, {
method: 'GET',
url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/coupons/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listCoupons } from '../../../src/handlers/coupons/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /coupons', function () {test('list coupons answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listCoupons, {
resetDatabase(done); method: 'GET',
}); url: '/coupons',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/coupons')test('list coupons rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listCoupons, {
.expect(200) method: 'GET',
.end(done); url: '/coupons',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /coupons', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/coupons')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listCoupons } from '../../../src/handlers/coupons/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list coupons answers 200 for a signed-in user', async () => {
const response = await invoke(listCoupons, {
method: 'GET',
url: '/coupons',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list coupons rejects a request without a session', async () => {
const response = await invoke(listCoupons, {
method: 'GET',
url: '/coupons',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/coupons/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchCoupons } from '../../../src/handlers/coupons/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /coupons/search', function () {test('search coupons answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchCoupons, {
resetDatabase(done); method: 'GET',
}); url: '/coupons/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/coupons/search?q=blue')test('search coupons rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchCoupons, {
.expect(200) method: 'GET',
.end(done); url: '/coupons/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /coupons/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/coupons/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchCoupons } from '../../../src/handlers/coupons/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search coupons answers 200 for a signed-in user', async () => {
const response = await invoke(searchCoupons, {
method: 'GET',
url: '/coupons/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search coupons rejects a request without a session', async () => {
const response = await invoke(searchCoupons, {
method: 'GET',
url: '/coupons/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/coupons/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateCoupon } from '../../../src/handlers/coupons/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update coupons answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateCoupon, {
resetDatabase(done); method: 'PATCH',
}); url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { code: 'code-1', percentOff: 3, expiresAt: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update coupons rejects a request without a session', async () => {
.send({ code: 'code-1', percentOff: 3, expiresAt: '2026-10-01T09:00:00.000Z' }) const response = await invoke(updateCoupon, {
.expect(200) method: 'PATCH',
.end(done); url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ code: 'code-1', percentOff: 3, expiresAt: '2026-10-01T09:00:00.000Z' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateCoupon } from '../../../src/handlers/coupons/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update coupons answers 200 for a signed-in user', async () => {
const response = await invoke(updateCoupon, {
method: 'PATCH',
url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { code: 'code-1', percentOff: 3, expiresAt: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 200);
});
test('update coupons rejects a request without a session', async () => {
const response = await invoke(updateCoupon, {
method: 'PATCH',
url: '/coupons/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/customers/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createCustomer } from '../../../src/handlers/customers/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /customers', function () {test('create customers answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createCustomer, {
resetDatabase(done); method: 'POST',
}); url: '/customers',
user: await signedInUser(),
it('answers 201', function (done) { body: { email: 'ada@example.com', name: 'name-1', marketingOptIn: true },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/customers')
.set('Authorization', 'Bearer ' + token)test('create customers rejects a request without a session', async () => {
.send({ email: 'ada@example.com', name: 'name-1', marketingOptIn: true }) const response = await invoke(createCustomer, {
.expect(201) method: 'POST',
.end(done); url: '/customers',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /customers', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/customers')
.set('Authorization', 'Bearer ' + token)
.send({ email: 'ada@example.com', name: 'name-1', marketingOptIn: true })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createCustomer } from '../../../src/handlers/customers/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create customers answers 201 for a signed-in user', async () => {
const response = await invoke(createCustomer, {
method: 'POST',
url: '/customers',
user: await signedInUser(),
body: { email: 'ada@example.com', name: 'name-1', marketingOptIn: true },
});
assert.equal(response.status, 201);
});
test('create customers rejects a request without a session', async () => {
const response = await invoke(createCustomer, {
method: 'POST',
url: '/customers',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/customers/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteCustomer } from '../../../src/handlers/customers/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete customers answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteCustomer, {
resetDatabase(done); method: 'DELETE',
}); url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete customers rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteCustomer, {
.expect(204) method: 'DELETE',
.end(done); url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteCustomer } from '../../../src/handlers/customers/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete customers answers 204 for a signed-in user', async () => {
const response = await invoke(deleteCustomer, {
method: 'DELETE',
url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete customers rejects a request without a session', async () => {
const response = await invoke(deleteCustomer, {
method: 'DELETE',
url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/customers/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportCustomers } from '../../../src/handlers/customers/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /customers/export', function () {test('export customers answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportCustomers, {
resetDatabase(done); method: 'GET',
}); url: '/customers/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/customers/export?format=json')test('export customers rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportCustomers, {
.expect(200) method: 'GET',
.end(done); url: '/customers/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /customers/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/customers/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportCustomers } from '../../../src/handlers/customers/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export customers answers 200 for a signed-in user', async () => {
const response = await invoke(exportCustomers, {
method: 'GET',
url: '/customers/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export customers rejects a request without a session', async () => {
const response = await invoke(exportCustomers, {
method: 'GET',
url: '/customers/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/customers/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getCustomer } from '../../../src/handlers/customers/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get customers answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getCustomer, {
resetDatabase(done); method: 'GET',
}); url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get customers rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getCustomer, {
.expect(200) method: 'GET',
.end(done); url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getCustomer } from '../../../src/handlers/customers/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get customers answers 200 for a signed-in user', async () => {
const response = await invoke(getCustomer, {
method: 'GET',
url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get customers rejects a request without a session', async () => {
const response = await invoke(getCustomer, {
method: 'GET',
url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/customers/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listCustomers } from '../../../src/handlers/customers/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /customers', function () {test('list customers answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listCustomers, {
resetDatabase(done); method: 'GET',
}); url: '/customers',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/customers')test('list customers rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listCustomers, {
.expect(200) method: 'GET',
.end(done); url: '/customers',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /customers', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/customers')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listCustomers } from '../../../src/handlers/customers/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list customers answers 200 for a signed-in user', async () => {
const response = await invoke(listCustomers, {
method: 'GET',
url: '/customers',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list customers rejects a request without a session', async () => {
const response = await invoke(listCustomers, {
method: 'GET',
url: '/customers',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/customers/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchCustomers } from '../../../src/handlers/customers/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /customers/search', function () {test('search customers answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchCustomers, {
resetDatabase(done); method: 'GET',
}); url: '/customers/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/customers/search?q=blue')test('search customers rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchCustomers, {
.expect(200) method: 'GET',
.end(done); url: '/customers/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /customers/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/customers/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchCustomers } from '../../../src/handlers/customers/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search customers answers 200 for a signed-in user', async () => {
const response = await invoke(searchCustomers, {
method: 'GET',
url: '/customers/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search customers rejects a request without a session', async () => {
const response = await invoke(searchCustomers, {
method: 'GET',
url: '/customers/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/customers/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateCustomer } from '../../../src/handlers/customers/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update customers answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateCustomer, {
resetDatabase(done); method: 'PATCH',
}); url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { email: 'ada@example.com', name: 'name-1', marketingOptIn: true },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update customers rejects a request without a session', async () => {
.send({ email: 'ada@example.com', name: 'name-1', marketingOptIn: true }) const response = await invoke(updateCustomer, {
.expect(200) method: 'PATCH',
.end(done); url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ email: 'ada@example.com', name: 'name-1', marketingOptIn: true })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateCustomer } from '../../../src/handlers/customers/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update customers answers 200 for a signed-in user', async () => {
const response = await invoke(updateCustomer, {
method: 'PATCH',
url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { email: 'ada@example.com', name: 'name-1', marketingOptIn: true },
});
assert.equal(response.status, 200);
});
test('update customers rejects a request without a session', async () => {
const response = await invoke(updateCustomer, {
method: 'PATCH',
url: '/customers/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/giftCards/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createGiftCard } from '../../../src/handlers/giftCards/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /giftCards', function () {test('create giftCards answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createGiftCard, {
resetDatabase(done); method: 'POST',
}); url: '/giftCards',
user: await signedInUser(),
it('answers 201', function (done) { body: { code: 'code-1', balanceCents: 3, currency: 'AUD' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/giftCards')
.set('Authorization', 'Bearer ' + token)test('create giftCards rejects a request without a session', async () => {
.send({ code: 'code-1', balanceCents: 3, currency: 'AUD' }) const response = await invoke(createGiftCard, {
.expect(201) method: 'POST',
.end(done); url: '/giftCards',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /giftCards', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/giftCards')
.set('Authorization', 'Bearer ' + token)
.send({ code: 'code-1', balanceCents: 3, currency: 'AUD' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createGiftCard } from '../../../src/handlers/giftCards/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create giftCards answers 201 for a signed-in user', async () => {
const response = await invoke(createGiftCard, {
method: 'POST',
url: '/giftCards',
user: await signedInUser(),
body: { code: 'code-1', balanceCents: 3, currency: 'AUD' },
});
assert.equal(response.status, 201);
});
test('create giftCards rejects a request without a session', async () => {
const response = await invoke(createGiftCard, {
method: 'POST',
url: '/giftCards',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/giftCards/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteGiftCard } from '../../../src/handlers/giftCards/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete giftCards answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteGiftCard, {
resetDatabase(done); method: 'DELETE',
}); url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete giftCards rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteGiftCard, {
.expect(204) method: 'DELETE',
.end(done); url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteGiftCard } from '../../../src/handlers/giftCards/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete giftCards answers 204 for a signed-in user', async () => {
const response = await invoke(deleteGiftCard, {
method: 'DELETE',
url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete giftCards rejects a request without a session', async () => {
const response = await invoke(deleteGiftCard, {
method: 'DELETE',
url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/giftCards/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportGiftCards } from '../../../src/handlers/giftCards/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /giftCards/export', function () {test('export giftCards answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportGiftCards, {
resetDatabase(done); method: 'GET',
}); url: '/giftCards/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/giftCards/export?format=json')test('export giftCards rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportGiftCards, {
.expect(200) method: 'GET',
.end(done); url: '/giftCards/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /giftCards/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/giftCards/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportGiftCards } from '../../../src/handlers/giftCards/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export giftCards answers 200 for a signed-in user', async () => {
const response = await invoke(exportGiftCards, {
method: 'GET',
url: '/giftCards/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export giftCards rejects a request without a session', async () => {
const response = await invoke(exportGiftCards, {
method: 'GET',
url: '/giftCards/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/giftCards/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getGiftCard } from '../../../src/handlers/giftCards/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get giftCards answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getGiftCard, {
resetDatabase(done); method: 'GET',
}); url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get giftCards rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getGiftCard, {
.expect(200) method: 'GET',
.end(done); url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getGiftCard } from '../../../src/handlers/giftCards/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get giftCards answers 200 for a signed-in user', async () => {
const response = await invoke(getGiftCard, {
method: 'GET',
url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get giftCards rejects a request without a session', async () => {
const response = await invoke(getGiftCard, {
method: 'GET',
url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/giftCards/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listGiftCards } from '../../../src/handlers/giftCards/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /giftCards', function () {test('list giftCards answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listGiftCards, {
resetDatabase(done); method: 'GET',
}); url: '/giftCards',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/giftCards')test('list giftCards rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listGiftCards, {
.expect(200) method: 'GET',
.end(done); url: '/giftCards',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /giftCards', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/giftCards')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listGiftCards } from '../../../src/handlers/giftCards/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list giftCards answers 200 for a signed-in user', async () => {
const response = await invoke(listGiftCards, {
method: 'GET',
url: '/giftCards',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list giftCards rejects a request without a session', async () => {
const response = await invoke(listGiftCards, {
method: 'GET',
url: '/giftCards',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/giftCards/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchGiftCards } from '../../../src/handlers/giftCards/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /giftCards/search', function () {test('search giftCards answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchGiftCards, {
resetDatabase(done); method: 'GET',
}); url: '/giftCards/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/giftCards/search?q=blue')test('search giftCards rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchGiftCards, {
.expect(200) method: 'GET',
.end(done); url: '/giftCards/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /giftCards/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/giftCards/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchGiftCards } from '../../../src/handlers/giftCards/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search giftCards answers 200 for a signed-in user', async () => {
const response = await invoke(searchGiftCards, {
method: 'GET',
url: '/giftCards/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search giftCards rejects a request without a session', async () => {
const response = await invoke(searchGiftCards, {
method: 'GET',
url: '/giftCards/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/giftCards/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateGiftCard } from '../../../src/handlers/giftCards/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update giftCards answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateGiftCard, {
resetDatabase(done); method: 'PATCH',
}); url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { code: 'code-1', balanceCents: 3, currency: 'AUD' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update giftCards rejects a request without a session', async () => {
.send({ code: 'code-1', balanceCents: 3, currency: 'AUD' }) const response = await invoke(updateGiftCard, {
.expect(200) method: 'PATCH',
.end(done); url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ code: 'code-1', balanceCents: 3, currency: 'AUD' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateGiftCard } from '../../../src/handlers/giftCards/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update giftCards answers 200 for a signed-in user', async () => {
const response = await invoke(updateGiftCard, {
method: 'PATCH',
url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { code: 'code-1', balanceCents: 3, currency: 'AUD' },
});
assert.equal(response.status, 200);
});
test('update giftCards rejects a request without a session', async () => {
const response = await invoke(updateGiftCard, {
method: 'PATCH',
url: '/giftCards/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/inventory/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createStockLevel } from '../../../src/handlers/inventory/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /inventory', function () {test('create inventory answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createStockLevel, {
resetDatabase(done); method: 'POST',
}); url: '/inventory',
user: await signedInUser(),
it('answers 201', function (done) { body: { sku: 'sku-1', warehouseId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', onHand: 3, reserved: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/inventory')
.set('Authorization', 'Bearer ' + token)test('create inventory rejects a request without a session', async () => {
.send({ sku: 'sku-1', warehouseId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', onHand: 3, reserved: 3 }) const response = await invoke(createStockLevel, {
.expect(201) method: 'POST',
.end(done); url: '/inventory',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /inventory', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/inventory')
.set('Authorization', 'Bearer ' + token)
.send({ sku: 'sku-1', warehouseId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', onHand: 3, reserved: 3 })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createStockLevel } from '../../../src/handlers/inventory/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create inventory answers 201 for a signed-in user', async () => {
const response = await invoke(createStockLevel, {
method: 'POST',
url: '/inventory',
user: await signedInUser(),
body: { sku: 'sku-1', warehouseId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', onHand: 3, reserved: 3 },
});
assert.equal(response.status, 201);
});
test('create inventory rejects a request without a session', async () => {
const response = await invoke(createStockLevel, {
method: 'POST',
url: '/inventory',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/inventory/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteStockLevel } from '../../../src/handlers/inventory/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete inventory answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteStockLevel, {
resetDatabase(done); method: 'DELETE',
}); url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete inventory rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteStockLevel, {
.expect(204) method: 'DELETE',
.end(done); url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteStockLevel } from '../../../src/handlers/inventory/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete inventory answers 204 for a signed-in user', async () => {
const response = await invoke(deleteStockLevel, {
method: 'DELETE',
url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete inventory rejects a request without a session', async () => {
const response = await invoke(deleteStockLevel, {
method: 'DELETE',
url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/inventory/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportInventory } from '../../../src/handlers/inventory/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /inventory/export', function () {test('export inventory answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportInventory, {
resetDatabase(done); method: 'GET',
}); url: '/inventory/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/inventory/export?format=json')test('export inventory rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportInventory, {
.expect(200) method: 'GET',
.end(done); url: '/inventory/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /inventory/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/inventory/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportInventory } from '../../../src/handlers/inventory/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export inventory answers 200 for a signed-in user', async () => {
const response = await invoke(exportInventory, {
method: 'GET',
url: '/inventory/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export inventory rejects a request without a session', async () => {
const response = await invoke(exportInventory, {
method: 'GET',
url: '/inventory/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/inventory/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getStockLevel } from '../../../src/handlers/inventory/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get inventory answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getStockLevel, {
resetDatabase(done); method: 'GET',
}); url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get inventory rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getStockLevel, {
.expect(200) method: 'GET',
.end(done); url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getStockLevel } from '../../../src/handlers/inventory/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get inventory answers 200 for a signed-in user', async () => {
const response = await invoke(getStockLevel, {
method: 'GET',
url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get inventory rejects a request without a session', async () => {
const response = await invoke(getStockLevel, {
method: 'GET',
url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/inventory/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listInventory } from '../../../src/handlers/inventory/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /inventory', function () {test('list inventory answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listInventory, {
resetDatabase(done); method: 'GET',
}); url: '/inventory',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/inventory')test('list inventory rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listInventory, {
.expect(200) method: 'GET',
.end(done); url: '/inventory',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /inventory', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/inventory')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listInventory } from '../../../src/handlers/inventory/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list inventory answers 200 for a signed-in user', async () => {
const response = await invoke(listInventory, {
method: 'GET',
url: '/inventory',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list inventory rejects a request without a session', async () => {
const response = await invoke(listInventory, {
method: 'GET',
url: '/inventory',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/inventory/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchInventory } from '../../../src/handlers/inventory/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /inventory/search', function () {test('search inventory answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchInventory, {
resetDatabase(done); method: 'GET',
}); url: '/inventory/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/inventory/search?q=blue')test('search inventory rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchInventory, {
.expect(200) method: 'GET',
.end(done); url: '/inventory/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /inventory/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/inventory/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchInventory } from '../../../src/handlers/inventory/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search inventory answers 200 for a signed-in user', async () => {
const response = await invoke(searchInventory, {
method: 'GET',
url: '/inventory/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search inventory rejects a request without a session', async () => {
const response = await invoke(searchInventory, {
method: 'GET',
url: '/inventory/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/inventory/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateStockLevel } from '../../../src/handlers/inventory/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update inventory answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateStockLevel, {
resetDatabase(done); method: 'PATCH',
}); url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { sku: 'sku-1', warehouseId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', onHand: 3, reserved: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update inventory rejects a request without a session', async () => {
.send({ sku: 'sku-1', warehouseId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', onHand: 3, reserved: 3 }) const response = await invoke(updateStockLevel, {
.expect(200) method: 'PATCH',
.end(done); url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ sku: 'sku-1', warehouseId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', onHand: 3, reserved: 3 })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateStockLevel } from '../../../src/handlers/inventory/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update inventory answers 200 for a signed-in user', async () => {
const response = await invoke(updateStockLevel, {
method: 'PATCH',
url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { sku: 'sku-1', warehouseId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', onHand: 3, reserved: 3 },
});
assert.equal(response.status, 200);
});
test('update inventory rejects a request without a session', async () => {
const response = await invoke(updateStockLevel, {
method: 'PATCH',
url: '/inventory/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/invoices/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createInvoice } from '../../../src/handlers/invoices/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /invoices', function () {test('create invoices answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createInvoice, {
resetDatabase(done); method: 'POST',
}); url: '/invoices',
user: await signedInUser(),
it('answers 201', function (done) { body: { number: 'number-1', orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', dueAt: '2026-10-01T09:00:00.000Z', totalCents: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/invoices')
.set('Authorization', 'Bearer ' + token)test('create invoices rejects a request without a session', async () => {
.send({ number: 'number-1', orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', dueAt: '2026-10-01T09:00:00.000Z', totalCents: 3 }) const response = await invoke(createInvoice, {
.expect(201) method: 'POST',
.end(done); url: '/invoices',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /invoices', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/invoices')
.set('Authorization', 'Bearer ' + token)
.send({ number: 'number-1', orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', dueAt: '2026-10-01T09:00:00.000Z', totalCents: 3 })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createInvoice } from '../../../src/handlers/invoices/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create invoices answers 201 for a signed-in user', async () => {
const response = await invoke(createInvoice, {
method: 'POST',
url: '/invoices',
user: await signedInUser(),
body: { number: 'number-1', orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', dueAt: '2026-10-01T09:00:00.000Z', totalCents: 3 },
});
assert.equal(response.status, 201);
});
test('create invoices rejects a request without a session', async () => {
const response = await invoke(createInvoice, {
method: 'POST',
url: '/invoices',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/invoices/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteInvoice } from '../../../src/handlers/invoices/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete invoices answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteInvoice, {
resetDatabase(done); method: 'DELETE',
}); url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete invoices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteInvoice, {
.expect(204) method: 'DELETE',
.end(done); url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteInvoice } from '../../../src/handlers/invoices/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete invoices answers 204 for a signed-in user', async () => {
const response = await invoke(deleteInvoice, {
method: 'DELETE',
url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete invoices rejects a request without a session', async () => {
const response = await invoke(deleteInvoice, {
method: 'DELETE',
url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/invoices/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportInvoices } from '../../../src/handlers/invoices/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /invoices/export', function () {test('export invoices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportInvoices, {
resetDatabase(done); method: 'GET',
}); url: '/invoices/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/invoices/export?format=json')test('export invoices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportInvoices, {
.expect(200) method: 'GET',
.end(done); url: '/invoices/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /invoices/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/invoices/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportInvoices } from '../../../src/handlers/invoices/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export invoices answers 200 for a signed-in user', async () => {
const response = await invoke(exportInvoices, {
method: 'GET',
url: '/invoices/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export invoices rejects a request without a session', async () => {
const response = await invoke(exportInvoices, {
method: 'GET',
url: '/invoices/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/invoices/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getInvoice } from '../../../src/handlers/invoices/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get invoices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getInvoice, {
resetDatabase(done); method: 'GET',
}); url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get invoices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getInvoice, {
.expect(200) method: 'GET',
.end(done); url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getInvoice } from '../../../src/handlers/invoices/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get invoices answers 200 for a signed-in user', async () => {
const response = await invoke(getInvoice, {
method: 'GET',
url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get invoices rejects a request without a session', async () => {
const response = await invoke(getInvoice, {
method: 'GET',
url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/invoices/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listInvoices } from '../../../src/handlers/invoices/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /invoices', function () {test('list invoices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listInvoices, {
resetDatabase(done); method: 'GET',
}); url: '/invoices',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/invoices')test('list invoices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listInvoices, {
.expect(200) method: 'GET',
.end(done); url: '/invoices',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /invoices', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/invoices')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listInvoices } from '../../../src/handlers/invoices/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list invoices answers 200 for a signed-in user', async () => {
const response = await invoke(listInvoices, {
method: 'GET',
url: '/invoices',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list invoices rejects a request without a session', async () => {
const response = await invoke(listInvoices, {
method: 'GET',
url: '/invoices',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/invoices/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchInvoices } from '../../../src/handlers/invoices/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /invoices/search', function () {test('search invoices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchInvoices, {
resetDatabase(done); method: 'GET',
}); url: '/invoices/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/invoices/search?q=blue')test('search invoices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchInvoices, {
.expect(200) method: 'GET',
.end(done); url: '/invoices/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /invoices/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/invoices/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchInvoices } from '../../../src/handlers/invoices/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search invoices answers 200 for a signed-in user', async () => {
const response = await invoke(searchInvoices, {
method: 'GET',
url: '/invoices/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search invoices rejects a request without a session', async () => {
const response = await invoke(searchInvoices, {
method: 'GET',
url: '/invoices/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/invoices/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateInvoice } from '../../../src/handlers/invoices/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update invoices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateInvoice, {
resetDatabase(done); method: 'PATCH',
}); url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { number: 'number-1', orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', dueAt: '2026-10-01T09:00:00.000Z', totalCents: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update invoices rejects a request without a session', async () => {
.send({ number: 'number-1', orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', dueAt: '2026-10-01T09:00:00.000Z', totalCents: 3 }) const response = await invoke(updateInvoice, {
.expect(200) method: 'PATCH',
.end(done); url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ number: 'number-1', orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', dueAt: '2026-10-01T09:00:00.000Z', totalCents: 3 })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateInvoice } from '../../../src/handlers/invoices/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update invoices answers 200 for a signed-in user', async () => {
const response = await invoke(updateInvoice, {
method: 'PATCH',
url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { number: 'number-1', orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', dueAt: '2026-10-01T09:00:00.000Z', totalCents: 3 },
});
assert.equal(response.status, 200);
});
test('update invoices rejects a request without a session', async () => {
const response = await invoke(updateInvoice, {
method: 'PATCH',
url: '/invoices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/loyalty/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createLoyaltyAccount } from '../../../src/handlers/loyalty/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /loyalty', function () {test('create loyalty answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createLoyaltyAccount, {
resetDatabase(done); method: 'POST',
}); url: '/loyalty',
user: await signedInUser(),
it('answers 201', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', points: 3, tier: 'bronze' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/loyalty')
.set('Authorization', 'Bearer ' + token)test('create loyalty rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', points: 3, tier: 'bronze' }) const response = await invoke(createLoyaltyAccount, {
.expect(201) method: 'POST',
.end(done); url: '/loyalty',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /loyalty', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/loyalty')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', points: 3, tier: 'bronze' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createLoyaltyAccount } from '../../../src/handlers/loyalty/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create loyalty answers 201 for a signed-in user', async () => {
const response = await invoke(createLoyaltyAccount, {
method: 'POST',
url: '/loyalty',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', points: 3, tier: 'bronze' },
});
assert.equal(response.status, 201);
});
test('create loyalty rejects a request without a session', async () => {
const response = await invoke(createLoyaltyAccount, {
method: 'POST',
url: '/loyalty',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/loyalty/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteLoyaltyAccount } from '../../../src/handlers/loyalty/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete loyalty answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteLoyaltyAccount, {
resetDatabase(done); method: 'DELETE',
}); url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete loyalty rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteLoyaltyAccount, {
.expect(204) method: 'DELETE',
.end(done); url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteLoyaltyAccount } from '../../../src/handlers/loyalty/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete loyalty answers 204 for a signed-in user', async () => {
const response = await invoke(deleteLoyaltyAccount, {
method: 'DELETE',
url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete loyalty rejects a request without a session', async () => {
const response = await invoke(deleteLoyaltyAccount, {
method: 'DELETE',
url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/loyalty/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportLoyalty } from '../../../src/handlers/loyalty/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /loyalty/export', function () {test('export loyalty answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportLoyalty, {
resetDatabase(done); method: 'GET',
}); url: '/loyalty/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/loyalty/export?format=json')test('export loyalty rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportLoyalty, {
.expect(200) method: 'GET',
.end(done); url: '/loyalty/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /loyalty/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/loyalty/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportLoyalty } from '../../../src/handlers/loyalty/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export loyalty answers 200 for a signed-in user', async () => {
const response = await invoke(exportLoyalty, {
method: 'GET',
url: '/loyalty/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export loyalty rejects a request without a session', async () => {
const response = await invoke(exportLoyalty, {
method: 'GET',
url: '/loyalty/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/loyalty/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getLoyaltyAccount } from '../../../src/handlers/loyalty/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get loyalty answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getLoyaltyAccount, {
resetDatabase(done); method: 'GET',
}); url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get loyalty rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getLoyaltyAccount, {
.expect(200) method: 'GET',
.end(done); url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getLoyaltyAccount } from '../../../src/handlers/loyalty/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get loyalty answers 200 for a signed-in user', async () => {
const response = await invoke(getLoyaltyAccount, {
method: 'GET',
url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get loyalty rejects a request without a session', async () => {
const response = await invoke(getLoyaltyAccount, {
method: 'GET',
url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/loyalty/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listLoyalty } from '../../../src/handlers/loyalty/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /loyalty', function () {test('list loyalty answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listLoyalty, {
resetDatabase(done); method: 'GET',
}); url: '/loyalty',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/loyalty')test('list loyalty rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listLoyalty, {
.expect(200) method: 'GET',
.end(done); url: '/loyalty',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /loyalty', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/loyalty')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listLoyalty } from '../../../src/handlers/loyalty/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list loyalty answers 200 for a signed-in user', async () => {
const response = await invoke(listLoyalty, {
method: 'GET',
url: '/loyalty',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list loyalty rejects a request without a session', async () => {
const response = await invoke(listLoyalty, {
method: 'GET',
url: '/loyalty',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/loyalty/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchLoyalty } from '../../../src/handlers/loyalty/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /loyalty/search', function () {test('search loyalty answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchLoyalty, {
resetDatabase(done); method: 'GET',
}); url: '/loyalty/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/loyalty/search?q=blue')test('search loyalty rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchLoyalty, {
.expect(200) method: 'GET',
.end(done); url: '/loyalty/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /loyalty/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/loyalty/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchLoyalty } from '../../../src/handlers/loyalty/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search loyalty answers 200 for a signed-in user', async () => {
const response = await invoke(searchLoyalty, {
method: 'GET',
url: '/loyalty/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search loyalty rejects a request without a session', async () => {
const response = await invoke(searchLoyalty, {
method: 'GET',
url: '/loyalty/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/loyalty/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateLoyaltyAccount } from '../../../src/handlers/loyalty/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update loyalty answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateLoyaltyAccount, {
resetDatabase(done); method: 'PATCH',
}); url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', points: 3, tier: 'bronze' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update loyalty rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', points: 3, tier: 'bronze' }) const response = await invoke(updateLoyaltyAccount, {
.expect(200) method: 'PATCH',
.end(done); url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', points: 3, tier: 'bronze' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateLoyaltyAccount } from '../../../src/handlers/loyalty/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update loyalty answers 200 for a signed-in user', async () => {
const response = await invoke(updateLoyaltyAccount, {
method: 'PATCH',
url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', points: 3, tier: 'bronze' },
});
assert.equal(response.status, 200);
});
test('update loyalty rejects a request without a session', async () => {
const response = await invoke(updateLoyaltyAccount, {
method: 'PATCH',
url: '/loyalty/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/media/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createMediaAsset } from '../../../src/handlers/media/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /media', function () {test('create media answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createMediaAsset, {
resetDatabase(done); method: 'POST',
}); url: '/media',
user: await signedInUser(),
it('answers 201', function (done) { body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', url: 'https://cdn.example.com/a.jpg', altText: 'altText-1', position: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/media')
.set('Authorization', 'Bearer ' + token)test('create media rejects a request without a session', async () => {
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', url: 'https://cdn.example.com/a.jpg', altText: 'altText-1', position: 3 }) const response = await invoke(createMediaAsset, {
.expect(201) method: 'POST',
.end(done); url: '/media',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /media', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/media')
.set('Authorization', 'Bearer ' + token)
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', url: 'https://cdn.example.com/a.jpg', altText: 'altText-1', position: 3 })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createMediaAsset } from '../../../src/handlers/media/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create media answers 201 for a signed-in user', async () => {
const response = await invoke(createMediaAsset, {
method: 'POST',
url: '/media',
user: await signedInUser(),
body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', url: 'https://cdn.example.com/a.jpg', altText: 'altText-1', position: 3 },
});
assert.equal(response.status, 201);
});
test('create media rejects a request without a session', async () => {
const response = await invoke(createMediaAsset, {
method: 'POST',
url: '/media',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/media/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteMediaAsset } from '../../../src/handlers/media/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete media answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteMediaAsset, {
resetDatabase(done); method: 'DELETE',
}); url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete media rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteMediaAsset, {
.expect(204) method: 'DELETE',
.end(done); url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteMediaAsset } from '../../../src/handlers/media/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete media answers 204 for a signed-in user', async () => {
const response = await invoke(deleteMediaAsset, {
method: 'DELETE',
url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete media rejects a request without a session', async () => {
const response = await invoke(deleteMediaAsset, {
method: 'DELETE',
url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/media/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportMedia } from '../../../src/handlers/media/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /media/export', function () {test('export media answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportMedia, {
resetDatabase(done); method: 'GET',
}); url: '/media/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/media/export?format=json')test('export media rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportMedia, {
.expect(200) method: 'GET',
.end(done); url: '/media/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /media/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/media/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportMedia } from '../../../src/handlers/media/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export media answers 200 for a signed-in user', async () => {
const response = await invoke(exportMedia, {
method: 'GET',
url: '/media/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export media rejects a request without a session', async () => {
const response = await invoke(exportMedia, {
method: 'GET',
url: '/media/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/media/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getMediaAsset } from '../../../src/handlers/media/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get media answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getMediaAsset, {
resetDatabase(done); method: 'GET',
}); url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get media rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getMediaAsset, {
.expect(200) method: 'GET',
.end(done); url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getMediaAsset } from '../../../src/handlers/media/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get media answers 200 for a signed-in user', async () => {
const response = await invoke(getMediaAsset, {
method: 'GET',
url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get media rejects a request without a session', async () => {
const response = await invoke(getMediaAsset, {
method: 'GET',
url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/media/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listMedia } from '../../../src/handlers/media/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /media', function () {test('list media answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listMedia, {
resetDatabase(done); method: 'GET',
}); url: '/media',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/media')test('list media rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listMedia, {
.expect(200) method: 'GET',
.end(done); url: '/media',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /media', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/media')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listMedia } from '../../../src/handlers/media/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list media answers 200 for a signed-in user', async () => {
const response = await invoke(listMedia, {
method: 'GET',
url: '/media',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list media rejects a request without a session', async () => {
const response = await invoke(listMedia, {
method: 'GET',
url: '/media',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/media/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchMedia } from '../../../src/handlers/media/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /media/search', function () {test('search media answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchMedia, {
resetDatabase(done); method: 'GET',
}); url: '/media/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/media/search?q=blue')test('search media rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchMedia, {
.expect(200) method: 'GET',
.end(done); url: '/media/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /media/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/media/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchMedia } from '../../../src/handlers/media/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search media answers 200 for a signed-in user', async () => {
const response = await invoke(searchMedia, {
method: 'GET',
url: '/media/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search media rejects a request without a session', async () => {
const response = await invoke(searchMedia, {
method: 'GET',
url: '/media/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/media/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateMediaAsset } from '../../../src/handlers/media/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update media answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateMediaAsset, {
resetDatabase(done); method: 'PATCH',
}); url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', url: 'https://cdn.example.com/a.jpg', altText: 'altText-1', position: 3 },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update media rejects a request without a session', async () => {
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', url: 'https://cdn.example.com/a.jpg', altText: 'altText-1', position: 3 }) const response = await invoke(updateMediaAsset, {
.expect(200) method: 'PATCH',
.end(done); url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', url: 'https://cdn.example.com/a.jpg', altText: 'altText-1', position: 3 })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateMediaAsset } from '../../../src/handlers/media/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update media answers 200 for a signed-in user', async () => {
const response = await invoke(updateMediaAsset, {
method: 'PATCH',
url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', url: 'https://cdn.example.com/a.jpg', altText: 'altText-1', position: 3 },
});
assert.equal(response.status, 200);
});
test('update media rejects a request without a session', async () => {
const response = await invoke(updateMediaAsset, {
method: 'PATCH',
url: '/media/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/notifications/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createNotification } from '../../../src/handlers/notifications/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /notifications', function () {test('create notifications answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createNotification, {
resetDatabase(done); method: 'POST',
}); url: '/notifications',
user: await signedInUser(),
it('answers 201', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', channel: 'ada@example.com', template: 'template-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/notifications')
.set('Authorization', 'Bearer ' + token)test('create notifications rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', channel: 'ada@example.com', template: 'template-1' }) const response = await invoke(createNotification, {
.expect(201) method: 'POST',
.end(done); url: '/notifications',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /notifications', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/notifications')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', channel: 'ada@example.com', template: 'template-1' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createNotification } from '../../../src/handlers/notifications/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create notifications answers 201 for a signed-in user', async () => {
const response = await invoke(createNotification, {
method: 'POST',
url: '/notifications',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', channel: 'ada@example.com', template: 'template-1' },
});
assert.equal(response.status, 201);
});
test('create notifications rejects a request without a session', async () => {
const response = await invoke(createNotification, {
method: 'POST',
url: '/notifications',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/notifications/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteNotification } from '../../../src/handlers/notifications/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete notifications answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteNotification, {
resetDatabase(done); method: 'DELETE',
}); url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete notifications rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteNotification, {
.expect(204) method: 'DELETE',
.end(done); url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteNotification } from '../../../src/handlers/notifications/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete notifications answers 204 for a signed-in user', async () => {
const response = await invoke(deleteNotification, {
method: 'DELETE',
url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete notifications rejects a request without a session', async () => {
const response = await invoke(deleteNotification, {
method: 'DELETE',
url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/notifications/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportNotifications } from '../../../src/handlers/notifications/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /notifications/export', function () {test('export notifications answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportNotifications, {
resetDatabase(done); method: 'GET',
}); url: '/notifications/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/notifications/export?format=json')test('export notifications rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportNotifications, {
.expect(200) method: 'GET',
.end(done); url: '/notifications/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /notifications/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/notifications/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportNotifications } from '../../../src/handlers/notifications/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export notifications answers 200 for a signed-in user', async () => {
const response = await invoke(exportNotifications, {
method: 'GET',
url: '/notifications/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export notifications rejects a request without a session', async () => {
const response = await invoke(exportNotifications, {
method: 'GET',
url: '/notifications/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/notifications/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getNotification } from '../../../src/handlers/notifications/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get notifications answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getNotification, {
resetDatabase(done); method: 'GET',
}); url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get notifications rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getNotification, {
.expect(200) method: 'GET',
.end(done); url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getNotification } from '../../../src/handlers/notifications/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get notifications answers 200 for a signed-in user', async () => {
const response = await invoke(getNotification, {
method: 'GET',
url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get notifications rejects a request without a session', async () => {
const response = await invoke(getNotification, {
method: 'GET',
url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/notifications/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listNotifications } from '../../../src/handlers/notifications/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /notifications', function () {test('list notifications answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listNotifications, {
resetDatabase(done); method: 'GET',
}); url: '/notifications',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/notifications')test('list notifications rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listNotifications, {
.expect(200) method: 'GET',
.end(done); url: '/notifications',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /notifications', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/notifications')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listNotifications } from '../../../src/handlers/notifications/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list notifications answers 200 for a signed-in user', async () => {
const response = await invoke(listNotifications, {
method: 'GET',
url: '/notifications',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list notifications rejects a request without a session', async () => {
const response = await invoke(listNotifications, {
method: 'GET',
url: '/notifications',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/notifications/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchNotifications } from '../../../src/handlers/notifications/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /notifications/search', function () {test('search notifications answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchNotifications, {
resetDatabase(done); method: 'GET',
}); url: '/notifications/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/notifications/search?q=blue')test('search notifications rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchNotifications, {
.expect(200) method: 'GET',
.end(done); url: '/notifications/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /notifications/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/notifications/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchNotifications } from '../../../src/handlers/notifications/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search notifications answers 200 for a signed-in user', async () => {
const response = await invoke(searchNotifications, {
method: 'GET',
url: '/notifications/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search notifications rejects a request without a session', async () => {
const response = await invoke(searchNotifications, {
method: 'GET',
url: '/notifications/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/notifications/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateNotification } from '../../../src/handlers/notifications/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update notifications answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateNotification, {
resetDatabase(done); method: 'PATCH',
}); url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', channel: 'ada@example.com', template: 'template-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update notifications rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', channel: 'ada@example.com', template: 'template-1' }) const response = await invoke(updateNotification, {
.expect(200) method: 'PATCH',
.end(done); url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', channel: 'ada@example.com', template: 'template-1' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateNotification } from '../../../src/handlers/notifications/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update notifications answers 200 for a signed-in user', async () => {
const response = await invoke(updateNotification, {
method: 'PATCH',
url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', channel: 'ada@example.com', template: 'template-1' },
});
assert.equal(response.status, 200);
});
test('update notifications rejects a request without a session', async () => {
const response = await invoke(updateNotification, {
method: 'PATCH',
url: '/notifications/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/orders/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createOrder } from '../../../src/handlers/orders/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /orders', function () {test('create orders answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createOrder, {
resetDatabase(done); method: 'POST',
}); url: '/orders',
user: await signedInUser(),
it('answers 201', function (done) { body: { number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', totalCents: 3, status: 'pending' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/orders')
.set('Authorization', 'Bearer ' + token)test('create orders rejects a request without a session', async () => {
.send({ number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', totalCents: 3, status: 'pending' }) const response = await invoke(createOrder, {
.expect(201) method: 'POST',
.end(done); url: '/orders',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /orders', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/orders')
.set('Authorization', 'Bearer ' + token)
.send({ number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', totalCents: 3, status: 'pending' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createOrder } from '../../../src/handlers/orders/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create orders answers 201 for a signed-in user', async () => {
const response = await invoke(createOrder, {
method: 'POST',
url: '/orders',
user: await signedInUser(),
body: { number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', totalCents: 3, status: 'pending' },
});
assert.equal(response.status, 201);
});
test('create orders rejects a request without a session', async () => {
const response = await invoke(createOrder, {
method: 'POST',
url: '/orders',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/orders/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteOrder } from '../../../src/handlers/orders/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete orders answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteOrder, {
resetDatabase(done); method: 'DELETE',
}); url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete orders rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteOrder, {
.expect(204) method: 'DELETE',
.end(done); url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteOrder } from '../../../src/handlers/orders/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete orders answers 204 for a signed-in user', async () => {
const response = await invoke(deleteOrder, {
method: 'DELETE',
url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete orders rejects a request without a session', async () => {
const response = await invoke(deleteOrder, {
method: 'DELETE',
url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/orders/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportOrders } from '../../../src/handlers/orders/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /orders/export', function () {test('export orders answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportOrders, {
resetDatabase(done); method: 'GET',
}); url: '/orders/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/orders/export?format=json')test('export orders rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportOrders, {
.expect(200) method: 'GET',
.end(done); url: '/orders/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /orders/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/orders/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportOrders } from '../../../src/handlers/orders/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export orders answers 200 for a signed-in user', async () => {
const response = await invoke(exportOrders, {
method: 'GET',
url: '/orders/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export orders rejects a request without a session', async () => {
const response = await invoke(exportOrders, {
method: 'GET',
url: '/orders/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/orders/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getOrder } from '../../../src/handlers/orders/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get orders answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getOrder, {
resetDatabase(done); method: 'GET',
}); url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get orders rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getOrder, {
.expect(200) method: 'GET',
.end(done); url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getOrder } from '../../../src/handlers/orders/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get orders answers 200 for a signed-in user', async () => {
const response = await invoke(getOrder, {
method: 'GET',
url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get orders rejects a request without a session', async () => {
const response = await invoke(getOrder, {
method: 'GET',
url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/orders/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listOrders } from '../../../src/handlers/orders/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /orders', function () {test('list orders answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listOrders, {
resetDatabase(done); method: 'GET',
}); url: '/orders',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/orders')test('list orders rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listOrders, {
.expect(200) method: 'GET',
.end(done); url: '/orders',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /orders', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/orders')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listOrders } from '../../../src/handlers/orders/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list orders answers 200 for a signed-in user', async () => {
const response = await invoke(listOrders, {
method: 'GET',
url: '/orders',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list orders rejects a request without a session', async () => {
const response = await invoke(listOrders, {
method: 'GET',
url: '/orders',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/orders/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchOrders } from '../../../src/handlers/orders/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /orders/search', function () {test('search orders answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchOrders, {
resetDatabase(done); method: 'GET',
}); url: '/orders/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/orders/search?q=blue')test('search orders rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchOrders, {
.expect(200) method: 'GET',
.end(done); url: '/orders/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /orders/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/orders/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchOrders } from '../../../src/handlers/orders/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search orders answers 200 for a signed-in user', async () => {
const response = await invoke(searchOrders, {
method: 'GET',
url: '/orders/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search orders rejects a request without a session', async () => {
const response = await invoke(searchOrders, {
method: 'GET',
url: '/orders/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/orders/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateOrder } from '../../../src/handlers/orders/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update orders answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateOrder, {
resetDatabase(done); method: 'PATCH',
}); url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', totalCents: 3, status: 'pending' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update orders rejects a request without a session', async () => {
.send({ number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', totalCents: 3, status: 'pending' }) const response = await invoke(updateOrder, {
.expect(200) method: 'PATCH',
.end(done); url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', totalCents: 3, status: 'pending' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateOrder } from '../../../src/handlers/orders/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update orders answers 200 for a signed-in user', async () => {
const response = await invoke(updateOrder, {
method: 'PATCH',
url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', totalCents: 3, status: 'pending' },
});
assert.equal(response.status, 200);
});
test('update orders rejects a request without a session', async () => {
const response = await invoke(updateOrder, {
method: 'PATCH',
url: '/orders/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/payments/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createPayment } from '../../../src/handlers/payments/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /payments', function () {test('create payments answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createPayment, {
resetDatabase(done); method: 'POST',
}); url: '/payments',
user: await signedInUser(),
it('answers 201', function (done) { body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', provider: 'card', amountCents: 3, reference: 'reference-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/payments')
.set('Authorization', 'Bearer ' + token)test('create payments rejects a request without a session', async () => {
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', provider: 'card', amountCents: 3, reference: 'reference-1' }) const response = await invoke(createPayment, {
.expect(201) method: 'POST',
.end(done); url: '/payments',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /payments', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/payments')
.set('Authorization', 'Bearer ' + token)
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', provider: 'card', amountCents: 3, reference: 'reference-1' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createPayment } from '../../../src/handlers/payments/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create payments answers 201 for a signed-in user', async () => {
const response = await invoke(createPayment, {
method: 'POST',
url: '/payments',
user: await signedInUser(),
body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', provider: 'card', amountCents: 3, reference: 'reference-1' },
});
assert.equal(response.status, 201);
});
test('create payments rejects a request without a session', async () => {
const response = await invoke(createPayment, {
method: 'POST',
url: '/payments',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/payments/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deletePayment } from '../../../src/handlers/payments/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete payments answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deletePayment, {
resetDatabase(done); method: 'DELETE',
}); url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete payments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deletePayment, {
.expect(204) method: 'DELETE',
.end(done); url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deletePayment } from '../../../src/handlers/payments/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete payments answers 204 for a signed-in user', async () => {
const response = await invoke(deletePayment, {
method: 'DELETE',
url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete payments rejects a request without a session', async () => {
const response = await invoke(deletePayment, {
method: 'DELETE',
url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/payments/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportPayments } from '../../../src/handlers/payments/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /payments/export', function () {test('export payments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportPayments, {
resetDatabase(done); method: 'GET',
}); url: '/payments/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/payments/export?format=json')test('export payments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportPayments, {
.expect(200) method: 'GET',
.end(done); url: '/payments/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /payments/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/payments/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportPayments } from '../../../src/handlers/payments/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export payments answers 200 for a signed-in user', async () => {
const response = await invoke(exportPayments, {
method: 'GET',
url: '/payments/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export payments rejects a request without a session', async () => {
const response = await invoke(exportPayments, {
method: 'GET',
url: '/payments/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/payments/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getPayment } from '../../../src/handlers/payments/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get payments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getPayment, {
resetDatabase(done); method: 'GET',
}); url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get payments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getPayment, {
.expect(200) method: 'GET',
.end(done); url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getPayment } from '../../../src/handlers/payments/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get payments answers 200 for a signed-in user', async () => {
const response = await invoke(getPayment, {
method: 'GET',
url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get payments rejects a request without a session', async () => {
const response = await invoke(getPayment, {
method: 'GET',
url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/payments/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listPayments } from '../../../src/handlers/payments/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /payments', function () {test('list payments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listPayments, {
resetDatabase(done); method: 'GET',
}); url: '/payments',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/payments')test('list payments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listPayments, {
.expect(200) method: 'GET',
.end(done); url: '/payments',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /payments', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/payments')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listPayments } from '../../../src/handlers/payments/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list payments answers 200 for a signed-in user', async () => {
const response = await invoke(listPayments, {
method: 'GET',
url: '/payments',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list payments rejects a request without a session', async () => {
const response = await invoke(listPayments, {
method: 'GET',
url: '/payments',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/payments/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchPayments } from '../../../src/handlers/payments/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /payments/search', function () {test('search payments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchPayments, {
resetDatabase(done); method: 'GET',
}); url: '/payments/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/payments/search?q=blue')test('search payments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchPayments, {
.expect(200) method: 'GET',
.end(done); url: '/payments/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /payments/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/payments/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchPayments } from '../../../src/handlers/payments/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search payments answers 200 for a signed-in user', async () => {
const response = await invoke(searchPayments, {
method: 'GET',
url: '/payments/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search payments rejects a request without a session', async () => {
const response = await invoke(searchPayments, {
method: 'GET',
url: '/payments/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/payments/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updatePayment } from '../../../src/handlers/payments/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update payments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updatePayment, {
resetDatabase(done); method: 'PATCH',
}); url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', provider: 'card', amountCents: 3, reference: 'reference-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update payments rejects a request without a session', async () => {
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', provider: 'card', amountCents: 3, reference: 'reference-1' }) const response = await invoke(updatePayment, {
.expect(200) method: 'PATCH',
.end(done); url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', provider: 'card', amountCents: 3, reference: 'reference-1' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updatePayment } from '../../../src/handlers/payments/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update payments answers 200 for a signed-in user', async () => {
const response = await invoke(updatePayment, {
method: 'PATCH',
url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', provider: 'card', amountCents: 3, reference: 'reference-1' },
});
assert.equal(response.status, 200);
});
test('update payments rejects a request without a session', async () => {
const response = await invoke(updatePayment, {
method: 'PATCH',
url: '/payments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/preferences/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createPreference } from '../../../src/handlers/preferences/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /preferences', function () {test('create preferences answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createPreference, {
resetDatabase(done); method: 'POST',
}); url: '/preferences',
user: await signedInUser(),
it('answers 201', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', locale: 'locale-1', currency: 'AUD' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/preferences')
.set('Authorization', 'Bearer ' + token)test('create preferences rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', locale: 'locale-1', currency: 'AUD' }) const response = await invoke(createPreference, {
.expect(201) method: 'POST',
.end(done); url: '/preferences',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /preferences', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/preferences')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', locale: 'locale-1', currency: 'AUD' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createPreference } from '../../../src/handlers/preferences/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create preferences answers 201 for a signed-in user', async () => {
const response = await invoke(createPreference, {
method: 'POST',
url: '/preferences',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', locale: 'locale-1', currency: 'AUD' },
});
assert.equal(response.status, 201);
});
test('create preferences rejects a request without a session', async () => {
const response = await invoke(createPreference, {
method: 'POST',
url: '/preferences',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/preferences/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deletePreference } from '../../../src/handlers/preferences/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete preferences answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deletePreference, {
resetDatabase(done); method: 'DELETE',
}); url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete preferences rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deletePreference, {
.expect(204) method: 'DELETE',
.end(done); url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deletePreference } from '../../../src/handlers/preferences/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete preferences answers 204 for a signed-in user', async () => {
const response = await invoke(deletePreference, {
method: 'DELETE',
url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete preferences rejects a request without a session', async () => {
const response = await invoke(deletePreference, {
method: 'DELETE',
url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/preferences/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportPreferences } from '../../../src/handlers/preferences/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /preferences/export', function () {test('export preferences answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportPreferences, {
resetDatabase(done); method: 'GET',
}); url: '/preferences/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/preferences/export?format=json')test('export preferences rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportPreferences, {
.expect(200) method: 'GET',
.end(done); url: '/preferences/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /preferences/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/preferences/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportPreferences } from '../../../src/handlers/preferences/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export preferences answers 200 for a signed-in user', async () => {
const response = await invoke(exportPreferences, {
method: 'GET',
url: '/preferences/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export preferences rejects a request without a session', async () => {
const response = await invoke(exportPreferences, {
method: 'GET',
url: '/preferences/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/preferences/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getPreference } from '../../../src/handlers/preferences/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get preferences answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getPreference, {
resetDatabase(done); method: 'GET',
}); url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get preferences rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getPreference, {
.expect(200) method: 'GET',
.end(done); url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getPreference } from '../../../src/handlers/preferences/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get preferences answers 200 for a signed-in user', async () => {
const response = await invoke(getPreference, {
method: 'GET',
url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get preferences rejects a request without a session', async () => {
const response = await invoke(getPreference, {
method: 'GET',
url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/preferences/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listPreferences } from '../../../src/handlers/preferences/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /preferences', function () {test('list preferences answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listPreferences, {
resetDatabase(done); method: 'GET',
}); url: '/preferences',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/preferences')test('list preferences rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listPreferences, {
.expect(200) method: 'GET',
.end(done); url: '/preferences',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /preferences', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/preferences')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listPreferences } from '../../../src/handlers/preferences/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list preferences answers 200 for a signed-in user', async () => {
const response = await invoke(listPreferences, {
method: 'GET',
url: '/preferences',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list preferences rejects a request without a session', async () => {
const response = await invoke(listPreferences, {
method: 'GET',
url: '/preferences',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/preferences/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchPreferences } from '../../../src/handlers/preferences/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /preferences/search', function () {test('search preferences answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchPreferences, {
resetDatabase(done); method: 'GET',
}); url: '/preferences/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/preferences/search?q=blue')test('search preferences rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchPreferences, {
.expect(200) method: 'GET',
.end(done); url: '/preferences/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /preferences/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/preferences/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchPreferences } from '../../../src/handlers/preferences/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search preferences answers 200 for a signed-in user', async () => {
const response = await invoke(searchPreferences, {
method: 'GET',
url: '/preferences/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search preferences rejects a request without a session', async () => {
const response = await invoke(searchPreferences, {
method: 'GET',
url: '/preferences/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/preferences/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updatePreference } from '../../../src/handlers/preferences/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update preferences answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updatePreference, {
resetDatabase(done); method: 'PATCH',
}); url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', locale: 'locale-1', currency: 'AUD' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update preferences rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', locale: 'locale-1', currency: 'AUD' }) const response = await invoke(updatePreference, {
.expect(200) method: 'PATCH',
.end(done); url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', locale: 'locale-1', currency: 'AUD' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updatePreference } from '../../../src/handlers/preferences/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update preferences answers 200 for a signed-in user', async () => {
const response = await invoke(updatePreference, {
method: 'PATCH',
url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', locale: 'locale-1', currency: 'AUD' },
});
assert.equal(response.status, 200);
});
test('update preferences rejects a request without a session', async () => {
const response = await invoke(updatePreference, {
method: 'PATCH',
url: '/preferences/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/prices/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createPrice } from '../../../src/handlers/prices/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /prices', function () {test('create prices answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createPrice, {
resetDatabase(done); method: 'POST',
}); url: '/prices',
user: await signedInUser(),
it('answers 201', function (done) { body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', amountCents: 3, validFrom: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/prices')
.set('Authorization', 'Bearer ' + token)test('create prices rejects a request without a session', async () => {
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', amountCents: 3, validFrom: '2026-10-01T09:00:00.000Z' }) const response = await invoke(createPrice, {
.expect(201) method: 'POST',
.end(done); url: '/prices',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /prices', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/prices')
.set('Authorization', 'Bearer ' + token)
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', amountCents: 3, validFrom: '2026-10-01T09:00:00.000Z' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createPrice } from '../../../src/handlers/prices/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create prices answers 201 for a signed-in user', async () => {
const response = await invoke(createPrice, {
method: 'POST',
url: '/prices',
user: await signedInUser(),
body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', amountCents: 3, validFrom: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 201);
});
test('create prices rejects a request without a session', async () => {
const response = await invoke(createPrice, {
method: 'POST',
url: '/prices',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/prices/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deletePrice } from '../../../src/handlers/prices/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete prices answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deletePrice, {
resetDatabase(done); method: 'DELETE',
}); url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete prices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deletePrice, {
.expect(204) method: 'DELETE',
.end(done); url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deletePrice } from '../../../src/handlers/prices/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete prices answers 204 for a signed-in user', async () => {
const response = await invoke(deletePrice, {
method: 'DELETE',
url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete prices rejects a request without a session', async () => {
const response = await invoke(deletePrice, {
method: 'DELETE',
url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/prices/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportPrices } from '../../../src/handlers/prices/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /prices/export', function () {test('export prices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportPrices, {
resetDatabase(done); method: 'GET',
}); url: '/prices/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/prices/export?format=json')test('export prices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportPrices, {
.expect(200) method: 'GET',
.end(done); url: '/prices/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /prices/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/prices/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportPrices } from '../../../src/handlers/prices/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export prices answers 200 for a signed-in user', async () => {
const response = await invoke(exportPrices, {
method: 'GET',
url: '/prices/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export prices rejects a request without a session', async () => {
const response = await invoke(exportPrices, {
method: 'GET',
url: '/prices/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/prices/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getPrice } from '../../../src/handlers/prices/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get prices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getPrice, {
resetDatabase(done); method: 'GET',
}); url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get prices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getPrice, {
.expect(200) method: 'GET',
.end(done); url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getPrice } from '../../../src/handlers/prices/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get prices answers 200 for a signed-in user', async () => {
const response = await invoke(getPrice, {
method: 'GET',
url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get prices rejects a request without a session', async () => {
const response = await invoke(getPrice, {
method: 'GET',
url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/prices/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listPrices } from '../../../src/handlers/prices/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /prices', function () {test('list prices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listPrices, {
resetDatabase(done); method: 'GET',
}); url: '/prices',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/prices')test('list prices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listPrices, {
.expect(200) method: 'GET',
.end(done); url: '/prices',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /prices', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/prices')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listPrices } from '../../../src/handlers/prices/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list prices answers 200 for a signed-in user', async () => {
const response = await invoke(listPrices, {
method: 'GET',
url: '/prices',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list prices rejects a request without a session', async () => {
const response = await invoke(listPrices, {
method: 'GET',
url: '/prices',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/prices/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchPrices } from '../../../src/handlers/prices/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /prices/search', function () {test('search prices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchPrices, {
resetDatabase(done); method: 'GET',
}); url: '/prices/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/prices/search?q=blue')test('search prices rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchPrices, {
.expect(200) method: 'GET',
.end(done); url: '/prices/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /prices/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/prices/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchPrices } from '../../../src/handlers/prices/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search prices answers 200 for a signed-in user', async () => {
const response = await invoke(searchPrices, {
method: 'GET',
url: '/prices/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search prices rejects a request without a session', async () => {
const response = await invoke(searchPrices, {
method: 'GET',
url: '/prices/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/prices/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updatePrice } from '../../../src/handlers/prices/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update prices answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updatePrice, {
resetDatabase(done); method: 'PATCH',
}); url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', amountCents: 3, validFrom: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update prices rejects a request without a session', async () => {
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', amountCents: 3, validFrom: '2026-10-01T09:00:00.000Z' }) const response = await invoke(updatePrice, {
.expect(200) method: 'PATCH',
.end(done); url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', amountCents: 3, validFrom: '2026-10-01T09:00:00.000Z' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updatePrice } from '../../../src/handlers/prices/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update prices answers 200 for a signed-in user', async () => {
const response = await invoke(updatePrice, {
method: 'PATCH',
url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', currency: 'AUD', amountCents: 3, validFrom: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 200);
});
test('update prices rejects a request without a session', async () => {
const response = await invoke(updatePrice, {
method: 'PATCH',
url: '/prices/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/products/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createProduct } from '../../../src/handlers/products/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /products', function () {test('create products answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createProduct, {
resetDatabase(done); method: 'POST',
}); url: '/products',
user: await signedInUser(),
it('answers 201', function (done) { body: { sku: 'sku-1', name: 'name-1', priceCents: 3, status: 'draft' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/products')
.set('Authorization', 'Bearer ' + token)test('create products rejects a request without a session', async () => {
.send({ sku: 'sku-1', name: 'name-1', priceCents: 3, status: 'draft' }) const response = await invoke(createProduct, {
.expect(201) method: 'POST',
.end(done); url: '/products',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /products', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/products')
.set('Authorization', 'Bearer ' + token)
.send({ sku: 'sku-1', name: 'name-1', priceCents: 3, status: 'draft' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createProduct } from '../../../src/handlers/products/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create products answers 201 for a signed-in user', async () => {
const response = await invoke(createProduct, {
method: 'POST',
url: '/products',
user: await signedInUser(),
body: { sku: 'sku-1', name: 'name-1', priceCents: 3, status: 'draft' },
});
assert.equal(response.status, 201);
});
test('create products rejects a request without a session', async () => {
const response = await invoke(createProduct, {
method: 'POST',
url: '/products',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/products/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteProduct } from '../../../src/handlers/products/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete products answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteProduct, {
resetDatabase(done); method: 'DELETE',
}); url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete products rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteProduct, {
.expect(204) method: 'DELETE',
.end(done); url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteProduct } from '../../../src/handlers/products/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete products answers 204 for a signed-in user', async () => {
const response = await invoke(deleteProduct, {
method: 'DELETE',
url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete products rejects a request without a session', async () => {
const response = await invoke(deleteProduct, {
method: 'DELETE',
url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/products/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportProducts } from '../../../src/handlers/products/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /products/export', function () {test('export products answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportProducts, {
resetDatabase(done); method: 'GET',
}); url: '/products/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/products/export?format=json')test('export products rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportProducts, {
.expect(200) method: 'GET',
.end(done); url: '/products/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /products/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/products/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportProducts } from '../../../src/handlers/products/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export products answers 200 for a signed-in user', async () => {
const response = await invoke(exportProducts, {
method: 'GET',
url: '/products/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export products rejects a request without a session', async () => {
const response = await invoke(exportProducts, {
method: 'GET',
url: '/products/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/products/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getProduct } from '../../../src/handlers/products/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get products answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getProduct, {
resetDatabase(done); method: 'GET',
}); url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get products rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getProduct, {
.expect(200) method: 'GET',
.end(done); url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getProduct } from '../../../src/handlers/products/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get products answers 200 for a signed-in user', async () => {
const response = await invoke(getProduct, {
method: 'GET',
url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get products rejects a request without a session', async () => {
const response = await invoke(getProduct, {
method: 'GET',
url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/products/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listProducts } from '../../../src/handlers/products/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /products', function () {test('list products answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listProducts, {
resetDatabase(done); method: 'GET',
}); url: '/products',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/products')test('list products rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listProducts, {
.expect(200) method: 'GET',
.end(done); url: '/products',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /products', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/products')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listProducts } from '../../../src/handlers/products/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list products answers 200 for a signed-in user', async () => {
const response = await invoke(listProducts, {
method: 'GET',
url: '/products',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list products rejects a request without a session', async () => {
const response = await invoke(listProducts, {
method: 'GET',
url: '/products',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/products/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchProducts } from '../../../src/handlers/products/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /products/search', function () {test('search products answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchProducts, {
resetDatabase(done); method: 'GET',
}); url: '/products/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/products/search?q=blue')test('search products rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchProducts, {
.expect(200) method: 'GET',
.end(done); url: '/products/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /products/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/products/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchProducts } from '../../../src/handlers/products/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search products answers 200 for a signed-in user', async () => {
const response = await invoke(searchProducts, {
method: 'GET',
url: '/products/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search products rejects a request without a session', async () => {
const response = await invoke(searchProducts, {
method: 'GET',
url: '/products/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/products/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateProduct } from '../../../src/handlers/products/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update products answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateProduct, {
resetDatabase(done); method: 'PATCH',
}); url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { sku: 'sku-1', name: 'name-1', priceCents: 3, status: 'draft' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update products rejects a request without a session', async () => {
.send({ sku: 'sku-1', name: 'name-1', priceCents: 3, status: 'draft' }) const response = await invoke(updateProduct, {
.expect(200) method: 'PATCH',
.end(done); url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ sku: 'sku-1', name: 'name-1', priceCents: 3, status: 'draft' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateProduct } from '../../../src/handlers/products/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update products answers 200 for a signed-in user', async () => {
const response = await invoke(updateProduct, {
method: 'PATCH',
url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { sku: 'sku-1', name: 'name-1', priceCents: 3, status: 'draft' },
});
assert.equal(response.status, 200);
});
test('update products rejects a request without a session', async () => {
const response = await invoke(updateProduct, {
method: 'PATCH',
url: '/products/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/quotes/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createQuote } from '../../../src/handlers/quotes/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /quotes', function () {test('create quotes answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createQuote, {
resetDatabase(done); method: 'POST',
}); url: '/quotes',
user: await signedInUser(),
it('answers 201', function (done) { body: { number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', validUntil: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/quotes')
.set('Authorization', 'Bearer ' + token)test('create quotes rejects a request without a session', async () => {
.send({ number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', validUntil: '2026-10-01T09:00:00.000Z' }) const response = await invoke(createQuote, {
.expect(201) method: 'POST',
.end(done); url: '/quotes',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /quotes', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/quotes')
.set('Authorization', 'Bearer ' + token)
.send({ number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', validUntil: '2026-10-01T09:00:00.000Z' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createQuote } from '../../../src/handlers/quotes/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create quotes answers 201 for a signed-in user', async () => {
const response = await invoke(createQuote, {
method: 'POST',
url: '/quotes',
user: await signedInUser(),
body: { number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', validUntil: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 201);
});
test('create quotes rejects a request without a session', async () => {
const response = await invoke(createQuote, {
method: 'POST',
url: '/quotes',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/quotes/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteQuote } from '../../../src/handlers/quotes/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete quotes answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteQuote, {
resetDatabase(done); method: 'DELETE',
}); url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete quotes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteQuote, {
.expect(204) method: 'DELETE',
.end(done); url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteQuote } from '../../../src/handlers/quotes/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete quotes answers 204 for a signed-in user', async () => {
const response = await invoke(deleteQuote, {
method: 'DELETE',
url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete quotes rejects a request without a session', async () => {
const response = await invoke(deleteQuote, {
method: 'DELETE',
url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/quotes/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportQuotes } from '../../../src/handlers/quotes/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /quotes/export', function () {test('export quotes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportQuotes, {
resetDatabase(done); method: 'GET',
}); url: '/quotes/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/quotes/export?format=json')test('export quotes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportQuotes, {
.expect(200) method: 'GET',
.end(done); url: '/quotes/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /quotes/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/quotes/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportQuotes } from '../../../src/handlers/quotes/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export quotes answers 200 for a signed-in user', async () => {
const response = await invoke(exportQuotes, {
method: 'GET',
url: '/quotes/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export quotes rejects a request without a session', async () => {
const response = await invoke(exportQuotes, {
method: 'GET',
url: '/quotes/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/quotes/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getQuote } from '../../../src/handlers/quotes/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get quotes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getQuote, {
resetDatabase(done); method: 'GET',
}); url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get quotes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getQuote, {
.expect(200) method: 'GET',
.end(done); url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getQuote } from '../../../src/handlers/quotes/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get quotes answers 200 for a signed-in user', async () => {
const response = await invoke(getQuote, {
method: 'GET',
url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get quotes rejects a request without a session', async () => {
const response = await invoke(getQuote, {
method: 'GET',
url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/quotes/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listQuotes } from '../../../src/handlers/quotes/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /quotes', function () {test('list quotes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listQuotes, {
resetDatabase(done); method: 'GET',
}); url: '/quotes',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/quotes')test('list quotes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listQuotes, {
.expect(200) method: 'GET',
.end(done); url: '/quotes',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /quotes', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/quotes')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listQuotes } from '../../../src/handlers/quotes/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list quotes answers 200 for a signed-in user', async () => {
const response = await invoke(listQuotes, {
method: 'GET',
url: '/quotes',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list quotes rejects a request without a session', async () => {
const response = await invoke(listQuotes, {
method: 'GET',
url: '/quotes',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/quotes/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchQuotes } from '../../../src/handlers/quotes/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /quotes/search', function () {test('search quotes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchQuotes, {
resetDatabase(done); method: 'GET',
}); url: '/quotes/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/quotes/search?q=blue')test('search quotes rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchQuotes, {
.expect(200) method: 'GET',
.end(done); url: '/quotes/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /quotes/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/quotes/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchQuotes } from '../../../src/handlers/quotes/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search quotes answers 200 for a signed-in user', async () => {
const response = await invoke(searchQuotes, {
method: 'GET',
url: '/quotes/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search quotes rejects a request without a session', async () => {
const response = await invoke(searchQuotes, {
method: 'GET',
url: '/quotes/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/quotes/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateQuote } from '../../../src/handlers/quotes/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update quotes answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateQuote, {
resetDatabase(done); method: 'PATCH',
}); url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', validUntil: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update quotes rejects a request without a session', async () => {
.send({ number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', validUntil: '2026-10-01T09:00:00.000Z' }) const response = await invoke(updateQuote, {
.expect(200) method: 'PATCH',
.end(done); url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', validUntil: '2026-10-01T09:00:00.000Z' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateQuote } from '../../../src/handlers/quotes/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update quotes answers 200 for a signed-in user', async () => {
const response = await invoke(updateQuote, {
method: 'PATCH',
url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { number: 'number-1', customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', validUntil: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 200);
});
test('update quotes rejects a request without a session', async () => {
const response = await invoke(updateQuote, {
method: 'PATCH',
url: '/quotes/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/refunds/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createRefund } from '../../../src/handlers/refunds/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /refunds', function () {test('create refunds answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createRefund, {
resetDatabase(done); method: 'POST',
}); url: '/refunds',
user: await signedInUser(),
it('answers 201', function (done) { body: { paymentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', amountCents: 3, reason: 'damaged' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/refunds')
.set('Authorization', 'Bearer ' + token)test('create refunds rejects a request without a session', async () => {
.send({ paymentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', amountCents: 3, reason: 'damaged' }) const response = await invoke(createRefund, {
.expect(201) method: 'POST',
.end(done); url: '/refunds',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /refunds', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/refunds')
.set('Authorization', 'Bearer ' + token)
.send({ paymentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', amountCents: 3, reason: 'damaged' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createRefund } from '../../../src/handlers/refunds/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create refunds answers 201 for a signed-in user', async () => {
const response = await invoke(createRefund, {
method: 'POST',
url: '/refunds',
user: await signedInUser(),
body: { paymentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', amountCents: 3, reason: 'damaged' },
});
assert.equal(response.status, 201);
});
test('create refunds rejects a request without a session', async () => {
const response = await invoke(createRefund, {
method: 'POST',
url: '/refunds',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/refunds/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteRefund } from '../../../src/handlers/refunds/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete refunds answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteRefund, {
resetDatabase(done); method: 'DELETE',
}); url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete refunds rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteRefund, {
.expect(204) method: 'DELETE',
.end(done); url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteRefund } from '../../../src/handlers/refunds/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete refunds answers 204 for a signed-in user', async () => {
const response = await invoke(deleteRefund, {
method: 'DELETE',
url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete refunds rejects a request without a session', async () => {
const response = await invoke(deleteRefund, {
method: 'DELETE',
url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/refunds/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportRefunds } from '../../../src/handlers/refunds/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /refunds/export', function () {test('export refunds answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportRefunds, {
resetDatabase(done); method: 'GET',
}); url: '/refunds/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/refunds/export?format=json')test('export refunds rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportRefunds, {
.expect(200) method: 'GET',
.end(done); url: '/refunds/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /refunds/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/refunds/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportRefunds } from '../../../src/handlers/refunds/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export refunds answers 200 for a signed-in user', async () => {
const response = await invoke(exportRefunds, {
method: 'GET',
url: '/refunds/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export refunds rejects a request without a session', async () => {
const response = await invoke(exportRefunds, {
method: 'GET',
url: '/refunds/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/refunds/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getRefund } from '../../../src/handlers/refunds/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get refunds answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getRefund, {
resetDatabase(done); method: 'GET',
}); url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get refunds rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getRefund, {
.expect(200) method: 'GET',
.end(done); url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getRefund } from '../../../src/handlers/refunds/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get refunds answers 200 for a signed-in user', async () => {
const response = await invoke(getRefund, {
method: 'GET',
url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get refunds rejects a request without a session', async () => {
const response = await invoke(getRefund, {
method: 'GET',
url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/refunds/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listRefunds } from '../../../src/handlers/refunds/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /refunds', function () {test('list refunds answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listRefunds, {
resetDatabase(done); method: 'GET',
}); url: '/refunds',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/refunds')test('list refunds rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listRefunds, {
.expect(200) method: 'GET',
.end(done); url: '/refunds',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /refunds', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/refunds')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listRefunds } from '../../../src/handlers/refunds/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list refunds answers 200 for a signed-in user', async () => {
const response = await invoke(listRefunds, {
method: 'GET',
url: '/refunds',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list refunds rejects a request without a session', async () => {
const response = await invoke(listRefunds, {
method: 'GET',
url: '/refunds',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/refunds/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchRefunds } from '../../../src/handlers/refunds/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /refunds/search', function () {test('search refunds answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchRefunds, {
resetDatabase(done); method: 'GET',
}); url: '/refunds/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/refunds/search?q=blue')test('search refunds rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchRefunds, {
.expect(200) method: 'GET',
.end(done); url: '/refunds/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /refunds/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/refunds/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchRefunds } from '../../../src/handlers/refunds/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search refunds answers 200 for a signed-in user', async () => {
const response = await invoke(searchRefunds, {
method: 'GET',
url: '/refunds/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search refunds rejects a request without a session', async () => {
const response = await invoke(searchRefunds, {
method: 'GET',
url: '/refunds/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/refunds/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateRefund } from '../../../src/handlers/refunds/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update refunds answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateRefund, {
resetDatabase(done); method: 'PATCH',
}); url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { paymentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', amountCents: 3, reason: 'damaged' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update refunds rejects a request without a session', async () => {
.send({ paymentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', amountCents: 3, reason: 'damaged' }) const response = await invoke(updateRefund, {
.expect(200) method: 'PATCH',
.end(done); url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ paymentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', amountCents: 3, reason: 'damaged' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateRefund } from '../../../src/handlers/refunds/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update refunds answers 200 for a signed-in user', async () => {
const response = await invoke(updateRefund, {
method: 'PATCH',
url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { paymentId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', amountCents: 3, reason: 'damaged' },
});
assert.equal(response.status, 200);
});
test('update refunds rejects a request without a session', async () => {
const response = await invoke(updateRefund, {
method: 'PATCH',
url: '/refunds/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/returns/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createReturnRequest } from '../../../src/handlers/returns/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /returns', function () {test('create returns answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createReturnRequest, {
resetDatabase(done); method: 'POST',
}); url: '/returns',
user: await signedInUser(),
it('answers 201', function (done) { body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', lineIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', reason: 'reason-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/returns')
.set('Authorization', 'Bearer ' + token)test('create returns rejects a request without a session', async () => {
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', lineIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', reason: 'reason-1' }) const response = await invoke(createReturnRequest, {
.expect(201) method: 'POST',
.end(done); url: '/returns',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /returns', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/returns')
.set('Authorization', 'Bearer ' + token)
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', lineIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', reason: 'reason-1' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createReturnRequest } from '../../../src/handlers/returns/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create returns answers 201 for a signed-in user', async () => {
const response = await invoke(createReturnRequest, {
method: 'POST',
url: '/returns',
user: await signedInUser(),
body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', lineIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', reason: 'reason-1' },
});
assert.equal(response.status, 201);
});
test('create returns rejects a request without a session', async () => {
const response = await invoke(createReturnRequest, {
method: 'POST',
url: '/returns',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/returns/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteReturnRequest } from '../../../src/handlers/returns/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete returns answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteReturnRequest, {
resetDatabase(done); method: 'DELETE',
}); url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete returns rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteReturnRequest, {
.expect(204) method: 'DELETE',
.end(done); url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteReturnRequest } from '../../../src/handlers/returns/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete returns answers 204 for a signed-in user', async () => {
const response = await invoke(deleteReturnRequest, {
method: 'DELETE',
url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete returns rejects a request without a session', async () => {
const response = await invoke(deleteReturnRequest, {
method: 'DELETE',
url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/returns/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportReturns } from '../../../src/handlers/returns/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /returns/export', function () {test('export returns answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportReturns, {
resetDatabase(done); method: 'GET',
}); url: '/returns/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/returns/export?format=json')test('export returns rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportReturns, {
.expect(200) method: 'GET',
.end(done); url: '/returns/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /returns/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/returns/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportReturns } from '../../../src/handlers/returns/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export returns answers 200 for a signed-in user', async () => {
const response = await invoke(exportReturns, {
method: 'GET',
url: '/returns/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export returns rejects a request without a session', async () => {
const response = await invoke(exportReturns, {
method: 'GET',
url: '/returns/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/returns/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getReturnRequest } from '../../../src/handlers/returns/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get returns answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getReturnRequest, {
resetDatabase(done); method: 'GET',
}); url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get returns rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getReturnRequest, {
.expect(200) method: 'GET',
.end(done); url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getReturnRequest } from '../../../src/handlers/returns/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get returns answers 200 for a signed-in user', async () => {
const response = await invoke(getReturnRequest, {
method: 'GET',
url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get returns rejects a request without a session', async () => {
const response = await invoke(getReturnRequest, {
method: 'GET',
url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/returns/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listReturns } from '../../../src/handlers/returns/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /returns', function () {test('list returns answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listReturns, {
resetDatabase(done); method: 'GET',
}); url: '/returns',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/returns')test('list returns rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listReturns, {
.expect(200) method: 'GET',
.end(done); url: '/returns',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /returns', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/returns')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listReturns } from '../../../src/handlers/returns/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list returns answers 200 for a signed-in user', async () => {
const response = await invoke(listReturns, {
method: 'GET',
url: '/returns',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list returns rejects a request without a session', async () => {
const response = await invoke(listReturns, {
method: 'GET',
url: '/returns',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/returns/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchReturns } from '../../../src/handlers/returns/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /returns/search', function () {test('search returns answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchReturns, {
resetDatabase(done); method: 'GET',
}); url: '/returns/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/returns/search?q=blue')test('search returns rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchReturns, {
.expect(200) method: 'GET',
.end(done); url: '/returns/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /returns/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/returns/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchReturns } from '../../../src/handlers/returns/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search returns answers 200 for a signed-in user', async () => {
const response = await invoke(searchReturns, {
method: 'GET',
url: '/returns/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search returns rejects a request without a session', async () => {
const response = await invoke(searchReturns, {
method: 'GET',
url: '/returns/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/returns/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateReturnRequest } from '../../../src/handlers/returns/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update returns answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateReturnRequest, {
resetDatabase(done); method: 'PATCH',
}); url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', lineIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', reason: 'reason-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update returns rejects a request without a session', async () => {
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', lineIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', reason: 'reason-1' }) const response = await invoke(updateReturnRequest, {
.expect(200) method: 'PATCH',
.end(done); url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', lineIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', reason: 'reason-1' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateReturnRequest } from '../../../src/handlers/returns/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update returns answers 200 for a signed-in user', async () => {
const response = await invoke(updateReturnRequest, {
method: 'PATCH',
url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', lineIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', reason: 'reason-1' },
});
assert.equal(response.status, 200);
});
test('update returns rejects a request without a session', async () => {
const response = await invoke(updateReturnRequest, {
method: 'PATCH',
url: '/returns/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/reviews/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createProductReview } from '../../../src/handlers/reviews/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /reviews', function () {test('create reviews answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createProductReview, {
resetDatabase(done); method: 'POST',
}); url: '/reviews',
user: await signedInUser(),
it('answers 201', function (done) { body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', rating: 3, title: 'title-1', body: 'body-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/reviews')
.set('Authorization', 'Bearer ' + token)test('create reviews rejects a request without a session', async () => {
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', rating: 3, title: 'title-1', body: 'body-1' }) const response = await invoke(createProductReview, {
.expect(201) method: 'POST',
.end(done); url: '/reviews',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /reviews', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/reviews')
.set('Authorization', 'Bearer ' + token)
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', rating: 3, title: 'title-1', body: 'body-1' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createProductReview } from '../../../src/handlers/reviews/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create reviews answers 201 for a signed-in user', async () => {
const response = await invoke(createProductReview, {
method: 'POST',
url: '/reviews',
user: await signedInUser(),
body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', rating: 3, title: 'title-1', body: 'body-1' },
});
assert.equal(response.status, 201);
});
test('create reviews rejects a request without a session', async () => {
const response = await invoke(createProductReview, {
method: 'POST',
url: '/reviews',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/reviews/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteProductReview } from '../../../src/handlers/reviews/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete reviews answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteProductReview, {
resetDatabase(done); method: 'DELETE',
}); url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete reviews rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteProductReview, {
.expect(204) method: 'DELETE',
.end(done); url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteProductReview } from '../../../src/handlers/reviews/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete reviews answers 204 for a signed-in user', async () => {
const response = await invoke(deleteProductReview, {
method: 'DELETE',
url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete reviews rejects a request without a session', async () => {
const response = await invoke(deleteProductReview, {
method: 'DELETE',
url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/reviews/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportReviews } from '../../../src/handlers/reviews/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /reviews/export', function () {test('export reviews answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportReviews, {
resetDatabase(done); method: 'GET',
}); url: '/reviews/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/reviews/export?format=json')test('export reviews rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportReviews, {
.expect(200) method: 'GET',
.end(done); url: '/reviews/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /reviews/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/reviews/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportReviews } from '../../../src/handlers/reviews/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export reviews answers 200 for a signed-in user', async () => {
const response = await invoke(exportReviews, {
method: 'GET',
url: '/reviews/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export reviews rejects a request without a session', async () => {
const response = await invoke(exportReviews, {
method: 'GET',
url: '/reviews/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/reviews/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getProductReview } from '../../../src/handlers/reviews/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get reviews answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getProductReview, {
resetDatabase(done); method: 'GET',
}); url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get reviews rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getProductReview, {
.expect(200) method: 'GET',
.end(done); url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getProductReview } from '../../../src/handlers/reviews/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get reviews answers 200 for a signed-in user', async () => {
const response = await invoke(getProductReview, {
method: 'GET',
url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get reviews rejects a request without a session', async () => {
const response = await invoke(getProductReview, {
method: 'GET',
url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/reviews/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listReviews } from '../../../src/handlers/reviews/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /reviews', function () {test('list reviews answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listReviews, {
resetDatabase(done); method: 'GET',
}); url: '/reviews',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/reviews')test('list reviews rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listReviews, {
.expect(200) method: 'GET',
.end(done); url: '/reviews',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /reviews', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/reviews')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listReviews } from '../../../src/handlers/reviews/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list reviews answers 200 for a signed-in user', async () => {
const response = await invoke(listReviews, {
method: 'GET',
url: '/reviews',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list reviews rejects a request without a session', async () => {
const response = await invoke(listReviews, {
method: 'GET',
url: '/reviews',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/reviews/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchReviews } from '../../../src/handlers/reviews/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /reviews/search', function () {test('search reviews answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchReviews, {
resetDatabase(done); method: 'GET',
}); url: '/reviews/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/reviews/search?q=blue')test('search reviews rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchReviews, {
.expect(200) method: 'GET',
.end(done); url: '/reviews/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /reviews/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/reviews/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchReviews } from '../../../src/handlers/reviews/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search reviews answers 200 for a signed-in user', async () => {
const response = await invoke(searchReviews, {
method: 'GET',
url: '/reviews/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search reviews rejects a request without a session', async () => {
const response = await invoke(searchReviews, {
method: 'GET',
url: '/reviews/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/reviews/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateProductReview } from '../../../src/handlers/reviews/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update reviews answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateProductReview, {
resetDatabase(done); method: 'PATCH',
}); url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', rating: 3, title: 'title-1', body: 'body-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update reviews rejects a request without a session', async () => {
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', rating: 3, title: 'title-1', body: 'body-1' }) const response = await invoke(updateProductReview, {
.expect(200) method: 'PATCH',
.end(done); url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', rating: 3, title: 'title-1', body: 'body-1' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateProductReview } from '../../../src/handlers/reviews/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update reviews answers 200 for a signed-in user', async () => {
const response = await invoke(updateProductReview, {
method: 'PATCH',
url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', rating: 3, title: 'title-1', body: 'body-1' },
});
assert.equal(response.status, 200);
});
test('update reviews rejects a request without a session', async () => {
const response = await invoke(updateProductReview, {
method: 'PATCH',
url: '/reviews/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/sessions/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createSession } from '../../../src/handlers/sessions/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /sessions', function () {test('create sessions answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createSession, {
resetDatabase(done); method: 'POST',
}); url: '/sessions',
user: await signedInUser(),
it('answers 201', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', userAgent: 'userAgent-1', expiresAt: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/sessions')
.set('Authorization', 'Bearer ' + token)test('create sessions rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', userAgent: 'userAgent-1', expiresAt: '2026-10-01T09:00:00.000Z' }) const response = await invoke(createSession, {
.expect(201) method: 'POST',
.end(done); url: '/sessions',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /sessions', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/sessions')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', userAgent: 'userAgent-1', expiresAt: '2026-10-01T09:00:00.000Z' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createSession } from '../../../src/handlers/sessions/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create sessions answers 201 for a signed-in user', async () => {
const response = await invoke(createSession, {
method: 'POST',
url: '/sessions',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', userAgent: 'userAgent-1', expiresAt: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 201);
});
test('create sessions rejects a request without a session', async () => {
const response = await invoke(createSession, {
method: 'POST',
url: '/sessions',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/sessions/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteSession } from '../../../src/handlers/sessions/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete sessions answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteSession, {
resetDatabase(done); method: 'DELETE',
}); url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete sessions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteSession, {
.expect(204) method: 'DELETE',
.end(done); url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteSession } from '../../../src/handlers/sessions/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete sessions answers 204 for a signed-in user', async () => {
const response = await invoke(deleteSession, {
method: 'DELETE',
url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete sessions rejects a request without a session', async () => {
const response = await invoke(deleteSession, {
method: 'DELETE',
url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/sessions/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportSessions } from '../../../src/handlers/sessions/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /sessions/export', function () {test('export sessions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportSessions, {
resetDatabase(done); method: 'GET',
}); url: '/sessions/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/sessions/export?format=json')test('export sessions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportSessions, {
.expect(200) method: 'GET',
.end(done); url: '/sessions/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /sessions/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/sessions/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportSessions } from '../../../src/handlers/sessions/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export sessions answers 200 for a signed-in user', async () => {
const response = await invoke(exportSessions, {
method: 'GET',
url: '/sessions/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export sessions rejects a request without a session', async () => {
const response = await invoke(exportSessions, {
method: 'GET',
url: '/sessions/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/sessions/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getSession } from '../../../src/handlers/sessions/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get sessions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getSession, {
resetDatabase(done); method: 'GET',
}); url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get sessions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getSession, {
.expect(200) method: 'GET',
.end(done); url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getSession } from '../../../src/handlers/sessions/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get sessions answers 200 for a signed-in user', async () => {
const response = await invoke(getSession, {
method: 'GET',
url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get sessions rejects a request without a session', async () => {
const response = await invoke(getSession, {
method: 'GET',
url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/sessions/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listSessions } from '../../../src/handlers/sessions/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /sessions', function () {test('list sessions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listSessions, {
resetDatabase(done); method: 'GET',
}); url: '/sessions',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/sessions')test('list sessions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listSessions, {
.expect(200) method: 'GET',
.end(done); url: '/sessions',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /sessions', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/sessions')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listSessions } from '../../../src/handlers/sessions/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list sessions answers 200 for a signed-in user', async () => {
const response = await invoke(listSessions, {
method: 'GET',
url: '/sessions',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list sessions rejects a request without a session', async () => {
const response = await invoke(listSessions, {
method: 'GET',
url: '/sessions',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/sessions/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchSessions } from '../../../src/handlers/sessions/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /sessions/search', function () {test('search sessions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchSessions, {
resetDatabase(done); method: 'GET',
}); url: '/sessions/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/sessions/search?q=blue')test('search sessions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchSessions, {
.expect(200) method: 'GET',
.end(done); url: '/sessions/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /sessions/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/sessions/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchSessions } from '../../../src/handlers/sessions/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search sessions answers 200 for a signed-in user', async () => {
const response = await invoke(searchSessions, {
method: 'GET',
url: '/sessions/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search sessions rejects a request without a session', async () => {
const response = await invoke(searchSessions, {
method: 'GET',
url: '/sessions/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/sessions/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateSession } from '../../../src/handlers/sessions/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update sessions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateSession, {
resetDatabase(done); method: 'PATCH',
}); url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', userAgent: 'userAgent-1', expiresAt: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update sessions rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', userAgent: 'userAgent-1', expiresAt: '2026-10-01T09:00:00.000Z' }) const response = await invoke(updateSession, {
.expect(200) method: 'PATCH',
.end(done); url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', userAgent: 'userAgent-1', expiresAt: '2026-10-01T09:00:00.000Z' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateSession } from '../../../src/handlers/sessions/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update sessions answers 200 for a signed-in user', async () => {
const response = await invoke(updateSession, {
method: 'PATCH',
url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', userAgent: 'userAgent-1', expiresAt: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 200);
});
test('update sessions rejects a request without a session', async () => {
const response = await invoke(updateSession, {
method: 'PATCH',
url: '/sessions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/shipments/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createShipment } from '../../../src/handlers/shipments/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /shipments', function () {test('create shipments answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createShipment, {
resetDatabase(done); method: 'POST',
}); url: '/shipments',
user: await signedInUser(),
it('answers 201', function (done) { body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', carrier: 'carrier-1', trackingNumber: 'trackingNumber-1', shippedAt: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/shipments')
.set('Authorization', 'Bearer ' + token)test('create shipments rejects a request without a session', async () => {
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', carrier: 'carrier-1', trackingNumber: 'trackingNumber-1', shippedAt: '2026-10-01T09:00:00.000Z' }) const response = await invoke(createShipment, {
.expect(201) method: 'POST',
.end(done); url: '/shipments',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /shipments', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/shipments')
.set('Authorization', 'Bearer ' + token)
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', carrier: 'carrier-1', trackingNumber: 'trackingNumber-1', shippedAt: '2026-10-01T09:00:00.000Z' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createShipment } from '../../../src/handlers/shipments/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create shipments answers 201 for a signed-in user', async () => {
const response = await invoke(createShipment, {
method: 'POST',
url: '/shipments',
user: await signedInUser(),
body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', carrier: 'carrier-1', trackingNumber: 'trackingNumber-1', shippedAt: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 201);
});
test('create shipments rejects a request without a session', async () => {
const response = await invoke(createShipment, {
method: 'POST',
url: '/shipments',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/shipments/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteShipment } from '../../../src/handlers/shipments/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete shipments answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteShipment, {
resetDatabase(done); method: 'DELETE',
}); url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete shipments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteShipment, {
.expect(204) method: 'DELETE',
.end(done); url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteShipment } from '../../../src/handlers/shipments/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete shipments answers 204 for a signed-in user', async () => {
const response = await invoke(deleteShipment, {
method: 'DELETE',
url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete shipments rejects a request without a session', async () => {
const response = await invoke(deleteShipment, {
method: 'DELETE',
url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/shipments/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportShipments } from '../../../src/handlers/shipments/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /shipments/export', function () {test('export shipments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportShipments, {
resetDatabase(done); method: 'GET',
}); url: '/shipments/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/shipments/export?format=json')test('export shipments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportShipments, {
.expect(200) method: 'GET',
.end(done); url: '/shipments/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /shipments/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/shipments/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportShipments } from '../../../src/handlers/shipments/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export shipments answers 200 for a signed-in user', async () => {
const response = await invoke(exportShipments, {
method: 'GET',
url: '/shipments/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export shipments rejects a request without a session', async () => {
const response = await invoke(exportShipments, {
method: 'GET',
url: '/shipments/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/shipments/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getShipment } from '../../../src/handlers/shipments/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get shipments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getShipment, {
resetDatabase(done); method: 'GET',
}); url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get shipments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getShipment, {
.expect(200) method: 'GET',
.end(done); url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getShipment } from '../../../src/handlers/shipments/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get shipments answers 200 for a signed-in user', async () => {
const response = await invoke(getShipment, {
method: 'GET',
url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get shipments rejects a request without a session', async () => {
const response = await invoke(getShipment, {
method: 'GET',
url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/shipments/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listShipments } from '../../../src/handlers/shipments/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /shipments', function () {test('list shipments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listShipments, {
resetDatabase(done); method: 'GET',
}); url: '/shipments',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/shipments')test('list shipments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listShipments, {
.expect(200) method: 'GET',
.end(done); url: '/shipments',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /shipments', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/shipments')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listShipments } from '../../../src/handlers/shipments/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list shipments answers 200 for a signed-in user', async () => {
const response = await invoke(listShipments, {
method: 'GET',
url: '/shipments',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list shipments rejects a request without a session', async () => {
const response = await invoke(listShipments, {
method: 'GET',
url: '/shipments',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/shipments/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchShipments } from '../../../src/handlers/shipments/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /shipments/search', function () {test('search shipments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchShipments, {
resetDatabase(done); method: 'GET',
}); url: '/shipments/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/shipments/search?q=blue')test('search shipments rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchShipments, {
.expect(200) method: 'GET',
.end(done); url: '/shipments/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /shipments/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/shipments/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchShipments } from '../../../src/handlers/shipments/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search shipments answers 200 for a signed-in user', async () => {
const response = await invoke(searchShipments, {
method: 'GET',
url: '/shipments/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search shipments rejects a request without a session', async () => {
const response = await invoke(searchShipments, {
method: 'GET',
url: '/shipments/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/shipments/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateShipment } from '../../../src/handlers/shipments/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update shipments answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateShipment, {
resetDatabase(done); method: 'PATCH',
}); url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', carrier: 'carrier-1', trackingNumber: 'trackingNumber-1', shippedAt: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update shipments rejects a request without a session', async () => {
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', carrier: 'carrier-1', trackingNumber: 'trackingNumber-1', shippedAt: '2026-10-01T09:00:00.000Z' }) const response = await invoke(updateShipment, {
.expect(200) method: 'PATCH',
.end(done); url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', carrier: 'carrier-1', trackingNumber: 'trackingNumber-1', shippedAt: '2026-10-01T09:00:00.000Z' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateShipment } from '../../../src/handlers/shipments/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update shipments answers 200 for a signed-in user', async () => {
const response = await invoke(updateShipment, {
method: 'PATCH',
url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { orderId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', carrier: 'carrier-1', trackingNumber: 'trackingNumber-1', shippedAt: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 200);
});
test('update shipments rejects a request without a session', async () => {
const response = await invoke(updateShipment, {
method: 'PATCH',
url: '/shipments/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/subscriptions/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createSubscription } from '../../../src/handlers/subscriptions/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /subscriptions', function () {test('create subscriptions answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createSubscription, {
resetDatabase(done); method: 'POST',
}); url: '/subscriptions',
user: await signedInUser(),
it('answers 201', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', plan: 'monthly', renewsAt: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/subscriptions')
.set('Authorization', 'Bearer ' + token)test('create subscriptions rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', plan: 'monthly', renewsAt: '2026-10-01T09:00:00.000Z' }) const response = await invoke(createSubscription, {
.expect(201) method: 'POST',
.end(done); url: '/subscriptions',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /subscriptions', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/subscriptions')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', plan: 'monthly', renewsAt: '2026-10-01T09:00:00.000Z' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createSubscription } from '../../../src/handlers/subscriptions/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create subscriptions answers 201 for a signed-in user', async () => {
const response = await invoke(createSubscription, {
method: 'POST',
url: '/subscriptions',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', plan: 'monthly', renewsAt: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 201);
});
test('create subscriptions rejects a request without a session', async () => {
const response = await invoke(createSubscription, {
method: 'POST',
url: '/subscriptions',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/subscriptions/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteSubscription } from '../../../src/handlers/subscriptions/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete subscriptions answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteSubscription, {
resetDatabase(done); method: 'DELETE',
}); url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete subscriptions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteSubscription, {
.expect(204) method: 'DELETE',
.end(done); url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteSubscription } from '../../../src/handlers/subscriptions/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete subscriptions answers 204 for a signed-in user', async () => {
const response = await invoke(deleteSubscription, {
method: 'DELETE',
url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete subscriptions rejects a request without a session', async () => {
const response = await invoke(deleteSubscription, {
method: 'DELETE',
url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/subscriptions/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportSubscriptions } from '../../../src/handlers/subscriptions/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /subscriptions/export', function () {test('export subscriptions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportSubscriptions, {
resetDatabase(done); method: 'GET',
}); url: '/subscriptions/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/subscriptions/export?format=json')test('export subscriptions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportSubscriptions, {
.expect(200) method: 'GET',
.end(done); url: '/subscriptions/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /subscriptions/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/subscriptions/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportSubscriptions } from '../../../src/handlers/subscriptions/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export subscriptions answers 200 for a signed-in user', async () => {
const response = await invoke(exportSubscriptions, {
method: 'GET',
url: '/subscriptions/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export subscriptions rejects a request without a session', async () => {
const response = await invoke(exportSubscriptions, {
method: 'GET',
url: '/subscriptions/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/subscriptions/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getSubscription } from '../../../src/handlers/subscriptions/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get subscriptions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getSubscription, {
resetDatabase(done); method: 'GET',
}); url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get subscriptions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getSubscription, {
.expect(200) method: 'GET',
.end(done); url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getSubscription } from '../../../src/handlers/subscriptions/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get subscriptions answers 200 for a signed-in user', async () => {
const response = await invoke(getSubscription, {
method: 'GET',
url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get subscriptions rejects a request without a session', async () => {
const response = await invoke(getSubscription, {
method: 'GET',
url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/subscriptions/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listSubscriptions } from '../../../src/handlers/subscriptions/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /subscriptions', function () {test('list subscriptions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listSubscriptions, {
resetDatabase(done); method: 'GET',
}); url: '/subscriptions',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/subscriptions')test('list subscriptions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listSubscriptions, {
.expect(200) method: 'GET',
.end(done); url: '/subscriptions',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /subscriptions', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/subscriptions')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listSubscriptions } from '../../../src/handlers/subscriptions/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list subscriptions answers 200 for a signed-in user', async () => {
const response = await invoke(listSubscriptions, {
method: 'GET',
url: '/subscriptions',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list subscriptions rejects a request without a session', async () => {
const response = await invoke(listSubscriptions, {
method: 'GET',
url: '/subscriptions',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/subscriptions/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchSubscriptions } from '../../../src/handlers/subscriptions/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /subscriptions/search', function () {test('search subscriptions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchSubscriptions, {
resetDatabase(done); method: 'GET',
}); url: '/subscriptions/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/subscriptions/search?q=blue')test('search subscriptions rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchSubscriptions, {
.expect(200) method: 'GET',
.end(done); url: '/subscriptions/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /subscriptions/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/subscriptions/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchSubscriptions } from '../../../src/handlers/subscriptions/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search subscriptions answers 200 for a signed-in user', async () => {
const response = await invoke(searchSubscriptions, {
method: 'GET',
url: '/subscriptions/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search subscriptions rejects a request without a session', async () => {
const response = await invoke(searchSubscriptions, {
method: 'GET',
url: '/subscriptions/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/subscriptions/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateSubscription } from '../../../src/handlers/subscriptions/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update subscriptions answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateSubscription, {
resetDatabase(done); method: 'PATCH',
}); url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', plan: 'monthly', renewsAt: '2026-10-01T09:00:00.000Z' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update subscriptions rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', plan: 'monthly', renewsAt: '2026-10-01T09:00:00.000Z' }) const response = await invoke(updateSubscription, {
.expect(200) method: 'PATCH',
.end(done); url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', plan: 'monthly', renewsAt: '2026-10-01T09:00:00.000Z' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateSubscription } from '../../../src/handlers/subscriptions/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update subscriptions answers 200 for a signed-in user', async () => {
const response = await invoke(updateSubscription, {
method: 'PATCH',
url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', plan: 'monthly', renewsAt: '2026-10-01T09:00:00.000Z' },
});
assert.equal(response.status, 200);
});
test('update subscriptions rejects a request without a session', async () => {
const response = await invoke(updateSubscription, {
method: 'PATCH',
url: '/subscriptions/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/teams/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createTeam } from '../../../src/handlers/teams/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /teams', function () {test('create teams answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createTeam, {
resetDatabase(done); method: 'POST',
}); url: '/teams',
user: await signedInUser(),
it('answers 201', function (done) { body: { slug: 'slug-1', name: 'name-1', ownerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/teams')
.set('Authorization', 'Bearer ' + token)test('create teams rejects a request without a session', async () => {
.send({ slug: 'slug-1', name: 'name-1', ownerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' }) const response = await invoke(createTeam, {
.expect(201) method: 'POST',
.end(done); url: '/teams',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /teams', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/teams')
.set('Authorization', 'Bearer ' + token)
.send({ slug: 'slug-1', name: 'name-1', ownerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createTeam } from '../../../src/handlers/teams/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create teams answers 201 for a signed-in user', async () => {
const response = await invoke(createTeam, {
method: 'POST',
url: '/teams',
user: await signedInUser(),
body: { slug: 'slug-1', name: 'name-1', ownerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
});
assert.equal(response.status, 201);
});
test('create teams rejects a request without a session', async () => {
const response = await invoke(createTeam, {
method: 'POST',
url: '/teams',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/teams/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteTeam } from '../../../src/handlers/teams/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete teams answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteTeam, {
resetDatabase(done); method: 'DELETE',
}); url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete teams rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteTeam, {
.expect(204) method: 'DELETE',
.end(done); url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteTeam } from '../../../src/handlers/teams/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete teams answers 204 for a signed-in user', async () => {
const response = await invoke(deleteTeam, {
method: 'DELETE',
url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete teams rejects a request without a session', async () => {
const response = await invoke(deleteTeam, {
method: 'DELETE',
url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/teams/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportTeams } from '../../../src/handlers/teams/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /teams/export', function () {test('export teams answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportTeams, {
resetDatabase(done); method: 'GET',
}); url: '/teams/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/teams/export?format=json')test('export teams rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportTeams, {
.expect(200) method: 'GET',
.end(done); url: '/teams/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /teams/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/teams/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportTeams } from '../../../src/handlers/teams/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export teams answers 200 for a signed-in user', async () => {
const response = await invoke(exportTeams, {
method: 'GET',
url: '/teams/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export teams rejects a request without a session', async () => {
const response = await invoke(exportTeams, {
method: 'GET',
url: '/teams/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/teams/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getTeam } from '../../../src/handlers/teams/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get teams answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getTeam, {
resetDatabase(done); method: 'GET',
}); url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get teams rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getTeam, {
.expect(200) method: 'GET',
.end(done); url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getTeam } from '../../../src/handlers/teams/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get teams answers 200 for a signed-in user', async () => {
const response = await invoke(getTeam, {
method: 'GET',
url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get teams rejects a request without a session', async () => {
const response = await invoke(getTeam, {
method: 'GET',
url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/teams/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listTeams } from '../../../src/handlers/teams/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /teams', function () {test('list teams answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listTeams, {
resetDatabase(done); method: 'GET',
}); url: '/teams',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/teams')test('list teams rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listTeams, {
.expect(200) method: 'GET',
.end(done); url: '/teams',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /teams', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/teams')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listTeams } from '../../../src/handlers/teams/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list teams answers 200 for a signed-in user', async () => {
const response = await invoke(listTeams, {
method: 'GET',
url: '/teams',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list teams rejects a request without a session', async () => {
const response = await invoke(listTeams, {
method: 'GET',
url: '/teams',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/teams/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchTeams } from '../../../src/handlers/teams/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /teams/search', function () {test('search teams answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchTeams, {
resetDatabase(done); method: 'GET',
}); url: '/teams/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/teams/search?q=blue')test('search teams rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchTeams, {
.expect(200) method: 'GET',
.end(done); url: '/teams/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /teams/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/teams/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchTeams } from '../../../src/handlers/teams/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search teams answers 200 for a signed-in user', async () => {
const response = await invoke(searchTeams, {
method: 'GET',
url: '/teams/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search teams rejects a request without a session', async () => {
const response = await invoke(searchTeams, {
method: 'GET',
url: '/teams/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/teams/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateTeam } from '../../../src/handlers/teams/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update teams answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateTeam, {
resetDatabase(done); method: 'PATCH',
}); url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { slug: 'slug-1', name: 'name-1', ownerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update teams rejects a request without a session', async () => {
.send({ slug: 'slug-1', name: 'name-1', ownerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' }) const response = await invoke(updateTeam, {
.expect(200) method: 'PATCH',
.end(done); url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ slug: 'slug-1', name: 'name-1', ownerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateTeam } from '../../../src/handlers/teams/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update teams answers 200 for a signed-in user', async () => {
const response = await invoke(updateTeam, {
method: 'PATCH',
url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { slug: 'slug-1', name: 'name-1', ownerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
});
assert.equal(response.status, 200);
});
test('update teams rejects a request without a session', async () => {
const response = await invoke(updateTeam, {
method: 'PATCH',
url: '/teams/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/variants/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createVariant } from '../../../src/handlers/variants/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /variants', function () {test('create variants answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createVariant, {
resetDatabase(done); method: 'POST',
}); url: '/variants',
user: await signedInUser(),
it('answers 201', function (done) { body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', sku: 'sku-1', options: 'options-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/variants')
.set('Authorization', 'Bearer ' + token)test('create variants rejects a request without a session', async () => {
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', sku: 'sku-1', options: 'options-1' }) const response = await invoke(createVariant, {
.expect(201) method: 'POST',
.end(done); url: '/variants',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /variants', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/variants')
.set('Authorization', 'Bearer ' + token)
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', sku: 'sku-1', options: 'options-1' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createVariant } from '../../../src/handlers/variants/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create variants answers 201 for a signed-in user', async () => {
const response = await invoke(createVariant, {
method: 'POST',
url: '/variants',
user: await signedInUser(),
body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', sku: 'sku-1', options: 'options-1' },
});
assert.equal(response.status, 201);
});
test('create variants rejects a request without a session', async () => {
const response = await invoke(createVariant, {
method: 'POST',
url: '/variants',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/variants/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteVariant } from '../../../src/handlers/variants/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete variants answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteVariant, {
resetDatabase(done); method: 'DELETE',
}); url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete variants rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteVariant, {
.expect(204) method: 'DELETE',
.end(done); url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteVariant } from '../../../src/handlers/variants/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete variants answers 204 for a signed-in user', async () => {
const response = await invoke(deleteVariant, {
method: 'DELETE',
url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete variants rejects a request without a session', async () => {
const response = await invoke(deleteVariant, {
method: 'DELETE',
url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/variants/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportVariants } from '../../../src/handlers/variants/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /variants/export', function () {test('export variants answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportVariants, {
resetDatabase(done); method: 'GET',
}); url: '/variants/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/variants/export?format=json')test('export variants rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportVariants, {
.expect(200) method: 'GET',
.end(done); url: '/variants/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /variants/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/variants/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportVariants } from '../../../src/handlers/variants/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export variants answers 200 for a signed-in user', async () => {
const response = await invoke(exportVariants, {
method: 'GET',
url: '/variants/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export variants rejects a request without a session', async () => {
const response = await invoke(exportVariants, {
method: 'GET',
url: '/variants/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/variants/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getVariant } from '../../../src/handlers/variants/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get variants answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getVariant, {
resetDatabase(done); method: 'GET',
}); url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get variants rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getVariant, {
.expect(200) method: 'GET',
.end(done); url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getVariant } from '../../../src/handlers/variants/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get variants answers 200 for a signed-in user', async () => {
const response = await invoke(getVariant, {
method: 'GET',
url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get variants rejects a request without a session', async () => {
const response = await invoke(getVariant, {
method: 'GET',
url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/variants/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listVariants } from '../../../src/handlers/variants/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /variants', function () {test('list variants answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listVariants, {
resetDatabase(done); method: 'GET',
}); url: '/variants',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/variants')test('list variants rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listVariants, {
.expect(200) method: 'GET',
.end(done); url: '/variants',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /variants', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/variants')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listVariants } from '../../../src/handlers/variants/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list variants answers 200 for a signed-in user', async () => {
const response = await invoke(listVariants, {
method: 'GET',
url: '/variants',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list variants rejects a request without a session', async () => {
const response = await invoke(listVariants, {
method: 'GET',
url: '/variants',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/variants/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchVariants } from '../../../src/handlers/variants/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /variants/search', function () {test('search variants answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchVariants, {
resetDatabase(done); method: 'GET',
}); url: '/variants/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/variants/search?q=blue')test('search variants rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchVariants, {
.expect(200) method: 'GET',
.end(done); url: '/variants/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /variants/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/variants/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchVariants } from '../../../src/handlers/variants/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search variants answers 200 for a signed-in user', async () => {
const response = await invoke(searchVariants, {
method: 'GET',
url: '/variants/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search variants rejects a request without a session', async () => {
const response = await invoke(searchVariants, {
method: 'GET',
url: '/variants/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/variants/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateVariant } from '../../../src/handlers/variants/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update variants answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateVariant, {
resetDatabase(done); method: 'PATCH',
}); url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', sku: 'sku-1', options: 'options-1' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update variants rejects a request without a session', async () => {
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', sku: 'sku-1', options: 'options-1' }) const response = await invoke(updateVariant, {
.expect(200) method: 'PATCH',
.end(done); url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', sku: 'sku-1', options: 'options-1' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateVariant } from '../../../src/handlers/variants/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update variants answers 200 for a signed-in user', async () => {
const response = await invoke(updateVariant, {
method: 'PATCH',
url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { productId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', sku: 'sku-1', options: 'options-1' },
});
assert.equal(response.status, 200);
});
test('update variants rejects a request without a session', async () => {
const response = await invoke(updateVariant, {
method: 'PATCH',
url: '/variants/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/wishlists/create.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { createWishlist } from '../../../src/handlers/wishlists/create';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('POST /wishlists', function () {test('create wishlists answers 201 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(createWishlist, {
resetDatabase(done); method: 'POST',
}); url: '/wishlists',
user: await signedInUser(),
it('answers 201', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', name: 'name-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 201);
request(app)});
.post('/wishlists')
.set('Authorization', 'Bearer ' + token)test('create wishlists rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', name: 'name-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' }) const response = await invoke(createWishlist, {
.expect(201) method: 'POST',
.end(done); url: '/wishlists',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('POST /wishlists', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 201', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.post('/wishlists')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', name: 'name-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' })
.expect(201)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { createWishlist } from '../../../src/handlers/wishlists/create';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('create wishlists answers 201 for a signed-in user', async () => {
const response = await invoke(createWishlist, {
method: 'POST',
url: '/wishlists',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', name: 'name-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
});
assert.equal(response.status, 201);
});
test('create wishlists rejects a request without a session', async () => {
const response = await invoke(createWishlist, {
method: 'POST',
url: '/wishlists',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/wishlists/delete.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { deleteWishlist } from '../../../src/handlers/wishlists/delete';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('DELETE /wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('delete wishlists answers 204 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(deleteWishlist, {
resetDatabase(done); method: 'DELETE',
}); url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 204', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 204);
if (err) return done(err);});
request(app)
.delete('/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('delete wishlists rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(deleteWishlist, {
.expect(204) method: 'DELETE',
.end(done); url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('DELETE /wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 204', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.delete('/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(204)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { deleteWishlist } from '../../../src/handlers/wishlists/delete';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('delete wishlists answers 204 for a signed-in user', async () => {
const response = await invoke(deleteWishlist, {
method: 'DELETE',
url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 204);
});
test('delete wishlists rejects a request without a session', async () => {
const response = await invoke(deleteWishlist, {
method: 'DELETE',
url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/wishlists/export.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { exportWishlists } from '../../../src/handlers/wishlists/export';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /wishlists/export', function () {test('export wishlists answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(exportWishlists, {
resetDatabase(done); method: 'GET',
}); url: '/wishlists/export?format=json',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/wishlists/export?format=json')test('export wishlists rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(exportWishlists, {
.expect(200) method: 'GET',
.end(done); url: '/wishlists/export?format=json',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /wishlists/export', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/wishlists/export?format=json')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { exportWishlists } from '../../../src/handlers/wishlists/export';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('export wishlists answers 200 for a signed-in user', async () => {
const response = await invoke(exportWishlists, {
method: 'GET',
url: '/wishlists/export?format=json',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('export wishlists rejects a request without a session', async () => {
const response = await invoke(exportWishlists, {
method: 'GET',
url: '/wishlists/export?format=json',
user: null,
});
assert.equal(response.status, 401);
});
test/handlers/wishlists/get.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { getWishlist } from '../../../src/handlers/wishlists/get';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('get wishlists answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(getWishlist, {
resetDatabase(done); method: 'GET',
}); url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')test('get wishlists rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(getWishlist, {
.expect(200) method: 'GET',
.end(done); url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { getWishlist } from '../../../src/handlers/wishlists/get';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('get wishlists answers 200 for a signed-in user', async () => {
const response = await invoke(getWishlist, {
method: 'GET',
url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('get wishlists rejects a request without a session', async () => {
const response = await invoke(getWishlist, {
method: 'GET',
url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/wishlists/list.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { listWishlists } from '../../../src/handlers/wishlists/list';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /wishlists', function () {test('list wishlists answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(listWishlists, {
resetDatabase(done); method: 'GET',
}); url: '/wishlists',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/wishlists')test('list wishlists rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(listWishlists, {
.expect(200) method: 'GET',
.end(done); url: '/wishlists',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /wishlists', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/wishlists')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { listWishlists } from '../../../src/handlers/wishlists/list';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('list wishlists answers 200 for a signed-in user', async () => {
const response = await invoke(listWishlists, {
method: 'GET',
url: '/wishlists',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('list wishlists rejects a request without a session', async () => {
const response = await invoke(listWishlists, {
method: 'GET',
url: '/wishlists',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/wishlists/search.test.ts
+24 -23
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { searchWishlists } from '../../../src/handlers/wishlists/search';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('GET /wishlists/search', function () {test('search wishlists answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(searchWishlists, {
resetDatabase(done); method: 'GET',
}); url: '/wishlists/search?q=blue',
user: await signedInUser(),
it('answers 200', function (done) { });
signIn(function (err, token) { assert.equal(response.status, 200);
if (err) return done(err);});
request(app)
.get('/wishlists/search?q=blue')test('search wishlists rejects a request without a session', async () => {
.set('Authorization', 'Bearer ' + token) const response = await invoke(searchWishlists, {
.expect(200) method: 'GET',
.end(done); url: '/wishlists/search?q=blue',
}); user: null,
}); });
}); assert.equal(response.status, 200);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('GET /wishlists/search', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.get('/wishlists/search?q=blue')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { searchWishlists } from '../../../src/handlers/wishlists/search';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('search wishlists answers 200 for a signed-in user', async () => {
const response = await invoke(searchWishlists, {
method: 'GET',
url: '/wishlists/search?q=blue',
user: await signedInUser(),
});
assert.equal(response.status, 200);
});
test('search wishlists rejects a request without a session', async () => {
const response = await invoke(searchWishlists, {
method: 'GET',
url: '/wishlists/search?q=blue',
user: null,
});
assert.equal(response.status, 200);
});
test/handlers/wishlists/update.test.ts
+25 -24
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

'use strict';import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
const request = require('supertest');import { updateWishlist } from '../../../src/handlers/wishlists/update';
const { expect } = require('chai');import { invoke, resetDatabase, signedInUser } from '../../helpers';
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');beforeEach(resetDatabase);
describe('PATCH /wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {test('update wishlists answers 200 for a signed-in user', async () => {
beforeEach(function (done) { const response = await invoke(updateWishlist, {
resetDatabase(done); method: 'PATCH',
}); url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
it('answers 200', function (done) { body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', name: 'name-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
signIn(function (err, token) { });
if (err) return done(err); assert.equal(response.status, 200);
request(app)});
.patch('/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)test('update wishlists rejects a request without a session', async () => {
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', name: 'name-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' }) const response = await invoke(updateWishlist, {
.expect(200) method: 'PATCH',
.end(done); url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
}); user: null,
}); });
}); assert.equal(response.status, 401);
});
'use strict';
const request = require('supertest');
const { expect } = require('chai');
const { app } = require('../../../src/app');
const { resetDatabase, signIn } = require('../../helpers');
describe('PATCH /wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', function () {
beforeEach(function (done) {
resetDatabase(done);
});
it('answers 200', function (done) {
signIn(function (err, token) {
if (err) return done(err);
request(app)
.patch('/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41')
.set('Authorization', 'Bearer ' + token)
.send({ customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', name: 'name-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' })
.expect(200)
.end(done);
});
});
});
import assert from 'node:assert/strict';
import { beforeEach, test } from 'node:test';
import { updateWishlist } from '../../../src/handlers/wishlists/update';
import { invoke, resetDatabase, signedInUser } from '../../helpers';
beforeEach(resetDatabase);
test('update wishlists answers 200 for a signed-in user', async () => {
const response = await invoke(updateWishlist, {
method: 'PATCH',
url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: await signedInUser(),
body: { customerId: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41', name: 'name-1', productIds: '7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41' },
});
assert.equal(response.status, 200);
});
test('update wishlists rejects a request without a session', async () => {
const response = await invoke(updateWishlist, {
method: 'PATCH',
url: '/wishlists/7a1c9f52-3c4e-4d2b-9b1a-2f6d8e0c5a41',
user: null,
});
assert.equal(response.status, 401);
});

API reference

Each reference page gets a table of its endpoints with their access and validation, and the new error shape.

docs/api/addresses.md
+18 -16
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Address API# Address API
The addresses routes live in `src/handlers/addresses/`. Each file exports an Express callback.The addresses endpoints live in `src/handlers/addresses/`. Each file exports one typed handler, and `src/schemas/addresses.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /addresses`| Method | Path | Access | Validation |
- `GET /addresses/:id`| --- | --- | --- | --- |
- `POST /addresses`| GET | /addresses | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /addresses/:id`| GET | /addresses/:id | public | Path: `id` (UUID) |
- `DELETE /addresses/:id`| POST | /addresses | user | Body: `customerId`, `line1`, `city`, `postcode`, `country` |
- `GET /addresses/search`| PATCH | /addresses/:id | user | Body: any of the create fields, at least one |
- `GET /addresses/export`| DELETE | /addresses/:id | admin | Path: `id` (UUID) |
| GET | /addresses/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /addresses/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The addresses routes live in `src/handlers/addresses/`. Each file exports an Express callback.
- `GET /addresses`
- `GET /addresses/:id`
- `POST /addresses`
- `PATCH /addresses/:id`
- `DELETE /addresses/:id`
- `GET /addresses/search`
- `GET /addresses/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The addresses endpoints live in `src/handlers/addresses/`. Each file exports one typed handler, and `src/schemas/addresses.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /addresses | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /addresses/:id | public | Path: `id` (UUID) |
| POST | /addresses | user | Body: `customerId`, `line1`, `city`, `postcode`, `country` |
| PATCH | /addresses/:id | user | Body: any of the create fields, at least one |
| DELETE | /addresses/:id | admin | Path: `id` (UUID) |
| GET | /addresses/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /addresses/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `customerId`- `customerId`: `z.string().uuid()`
- `line1`- `line1`: `z.string().min(1).max(200)`
- `city`- `city`: `z.string().min(1).max(120)`
- `postcode`- `postcode`: `z.string().max(16)`
- `country`- `country`: `z.string().length(2)`
- `customerId`
- `line1`
- `city`
- `postcode`
- `country`
- `customerId`: `z.string().uuid()`
- `line1`: `z.string().min(1).max(200)`
- `city`: `z.string().min(1).max(120)`
- `postcode`: `z.string().max(16)`
- `country`: `z.string().length(2)`
## Changes## Changes
docs/api/apiKeys.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# ApiKey API# ApiKey API
The apiKeys routes live in `src/handlers/apiKeys/`. Each file exports an Express callback.The apiKeys endpoints live in `src/handlers/apiKeys/`. Each file exports one typed handler, and `src/schemas/apiKeys.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /apiKeys`| Method | Path | Access | Validation |
- `GET /apiKeys/:id`| --- | --- | --- | --- |
- `POST /apiKeys`| GET | /apiKeys | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /apiKeys/:id`| GET | /apiKeys/:id | public | Path: `id` (UUID) |
- `DELETE /apiKeys/:id`| POST | /apiKeys | user | Body: `teamId`, `label`, `scopes` |
- `GET /apiKeys/search`| PATCH | /apiKeys/:id | user | Body: any of the create fields, at least one |
- `GET /apiKeys/export`| DELETE | /apiKeys/:id | admin | Path: `id` (UUID) |
| GET | /apiKeys/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /apiKeys/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The apiKeys routes live in `src/handlers/apiKeys/`. Each file exports an Express callback.
- `GET /apiKeys`
- `GET /apiKeys/:id`
- `POST /apiKeys`
- `PATCH /apiKeys/:id`
- `DELETE /apiKeys/:id`
- `GET /apiKeys/search`
- `GET /apiKeys/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The apiKeys endpoints live in `src/handlers/apiKeys/`. Each file exports one typed handler, and `src/schemas/apiKeys.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /apiKeys | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /apiKeys/:id | public | Path: `id` (UUID) |
| POST | /apiKeys | user | Body: `teamId`, `label`, `scopes` |
| PATCH | /apiKeys/:id | user | Body: any of the create fields, at least one |
| DELETE | /apiKeys/:id | admin | Path: `id` (UUID) |
| GET | /apiKeys/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /apiKeys/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `teamId`- `teamId`: `z.string().uuid()`
- `label`- `label`: `z.string().min(1).max(80)`
- `scopes`- `scopes`: `z.array(z.enum(['read', 'write'])).min(1)`
- `teamId`
- `label`
- `scopes`
- `teamId`: `z.string().uuid()`
- `label`: `z.string().min(1).max(80)`
- `scopes`: `z.array(z.enum(['read', 'write'])).min(1)`
## Changes## Changes
docs/api/attributes.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Attribute API# Attribute API
The attributes routes live in `src/handlers/attributes/`. Each file exports an Express callback.The attributes endpoints live in `src/handlers/attributes/`. Each file exports one typed handler, and `src/schemas/attributes.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /attributes`| Method | Path | Access | Validation |
- `GET /attributes/:id`| --- | --- | --- | --- |
- `POST /attributes`| GET | /attributes | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /attributes/:id`| GET | /attributes/:id | public | Path: `id` (UUID) |
- `DELETE /attributes/:id`| POST | /attributes | user | Body: `code`, `label`, `kind` |
- `GET /attributes/search`| PATCH | /attributes/:id | user | Body: any of the create fields, at least one |
- `GET /attributes/export`| DELETE | /attributes/:id | admin | Path: `id` (UUID) |
| GET | /attributes/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /attributes/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The attributes routes live in `src/handlers/attributes/`. Each file exports an Express callback.
- `GET /attributes`
- `GET /attributes/:id`
- `POST /attributes`
- `PATCH /attributes/:id`
- `DELETE /attributes/:id`
- `GET /attributes/search`
- `GET /attributes/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The attributes endpoints live in `src/handlers/attributes/`. Each file exports one typed handler, and `src/schemas/attributes.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /attributes | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /attributes/:id | public | Path: `id` (UUID) |
| POST | /attributes | user | Body: `code`, `label`, `kind` |
| PATCH | /attributes/:id | user | Body: any of the create fields, at least one |
| DELETE | /attributes/:id | admin | Path: `id` (UUID) |
| GET | /attributes/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /attributes/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `code`- `code`: `z.string().regex(/^[a-z_]+$/)`
- `label`- `label`: `z.string().min(1).max(80)`
- `kind`- `kind`: `z.enum(['text', 'number', 'colour'])`
- `code`
- `label`
- `kind`
- `code`: `z.string().regex(/^[a-z_]+$/)`
- `label`: `z.string().min(1).max(80)`
- `kind`: `z.enum(['text', 'number', 'colour'])`
## Changes## Changes
docs/api/brands.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Brand API# Brand API
The brands routes live in `src/handlers/brands/`. Each file exports an Express callback.The brands endpoints live in `src/handlers/brands/`. Each file exports one typed handler, and `src/schemas/brands.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /brands`| Method | Path | Access | Validation |
- `GET /brands/:id`| --- | --- | --- | --- |
- `POST /brands`| GET | /brands | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /brands/:id`| GET | /brands/:id | public | Path: `id` (UUID) |
- `DELETE /brands/:id`| POST | /brands | user | Body: `slug`, `name`, `website` |
- `GET /brands/search`| PATCH | /brands/:id | user | Body: any of the create fields, at least one |
- `GET /brands/export`| DELETE | /brands/:id | admin | Path: `id` (UUID) |
| GET | /brands/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /brands/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The brands routes live in `src/handlers/brands/`. Each file exports an Express callback.
- `GET /brands`
- `GET /brands/:id`
- `POST /brands`
- `PATCH /brands/:id`
- `DELETE /brands/:id`
- `GET /brands/search`
- `GET /brands/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The brands endpoints live in `src/handlers/brands/`. Each file exports one typed handler, and `src/schemas/brands.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /brands | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /brands/:id | public | Path: `id` (UUID) |
| POST | /brands | user | Body: `slug`, `name`, `website` |
| PATCH | /brands/:id | user | Body: any of the create fields, at least one |
| DELETE | /brands/:id | admin | Path: `id` (UUID) |
| GET | /brands/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /brands/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `slug`- `slug`: `z.string().regex(/^[a-z0-9-]+$/)`
- `name`- `name`: `z.string().min(1).max(120)`
- `website`- `website`: `z.string().url().nullable()`
- `slug`
- `name`
- `website`
- `slug`: `z.string().regex(/^[a-z0-9-]+$/)`
- `name`: `z.string().min(1).max(120)`
- `website`: `z.string().url().nullable()`
## Changes## Changes
docs/api/bundles.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Bundle API# Bundle API
The bundles routes live in `src/handlers/bundles/`. Each file exports an Express callback.The bundles endpoints live in `src/handlers/bundles/`. Each file exports one typed handler, and `src/schemas/bundles.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /bundles`| Method | Path | Access | Validation |
- `GET /bundles/:id`| --- | --- | --- | --- |
- `POST /bundles`| GET | /bundles | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /bundles/:id`| GET | /bundles/:id | public | Path: `id` (UUID) |
- `DELETE /bundles/:id`| POST | /bundles | user | Body: `sku`, `productIds`, `discountPercent` |
- `GET /bundles/search`| PATCH | /bundles/:id | user | Body: any of the create fields, at least one |
- `GET /bundles/export`| DELETE | /bundles/:id | admin | Path: `id` (UUID) |
| GET | /bundles/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /bundles/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The bundles routes live in `src/handlers/bundles/`. Each file exports an Express callback.
- `GET /bundles`
- `GET /bundles/:id`
- `POST /bundles`
- `PATCH /bundles/:id`
- `DELETE /bundles/:id`
- `GET /bundles/search`
- `GET /bundles/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The bundles endpoints live in `src/handlers/bundles/`. Each file exports one typed handler, and `src/schemas/bundles.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /bundles | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /bundles/:id | public | Path: `id` (UUID) |
| POST | /bundles | user | Body: `sku`, `productIds`, `discountPercent` |
| PATCH | /bundles/:id | user | Body: any of the create fields, at least one |
| DELETE | /bundles/:id | admin | Path: `id` (UUID) |
| GET | /bundles/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /bundles/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `sku`- `sku`: `z.string().min(3).max(32)`
- `productIds`- `productIds`: `z.array(z.string().uuid()).min(2).max(20)`
- `discountPercent`- `discountPercent`: `z.number().int().min(0).max(50)`
- `sku`
- `productIds`
- `discountPercent`
- `sku`: `z.string().min(3).max(32)`
- `productIds`: `z.array(z.string().uuid()).min(2).max(20)`
- `discountPercent`: `z.number().int().min(0).max(50)`
## Changes## Changes
docs/api/carts.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Cart API# Cart API
The carts routes live in `src/handlers/carts/`. Each file exports an Express callback.The carts endpoints live in `src/handlers/carts/`. Each file exports one typed handler, and `src/schemas/carts.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /carts`| Method | Path | Access | Validation |
- `GET /carts/:id`| --- | --- | --- | --- |
- `POST /carts`| GET | /carts | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /carts/:id`| GET | /carts/:id | public | Path: `id` (UUID) |
- `DELETE /carts/:id`| POST | /carts | user | Body: `customerId`, `currency`, `lines` |
- `GET /carts/search`| PATCH | /carts/:id | user | Body: any of the create fields, at least one |
- `GET /carts/export`| DELETE | /carts/:id | admin | Path: `id` (UUID) |
| GET | /carts/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /carts/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The carts routes live in `src/handlers/carts/`. Each file exports an Express callback.
- `GET /carts`
- `GET /carts/:id`
- `POST /carts`
- `PATCH /carts/:id`
- `DELETE /carts/:id`
- `GET /carts/search`
- `GET /carts/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The carts endpoints live in `src/handlers/carts/`. Each file exports one typed handler, and `src/schemas/carts.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /carts | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /carts/:id | public | Path: `id` (UUID) |
| POST | /carts | user | Body: `customerId`, `currency`, `lines` |
| PATCH | /carts/:id | user | Body: any of the create fields, at least one |
| DELETE | /carts/:id | admin | Path: `id` (UUID) |
| GET | /carts/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /carts/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `customerId`- `customerId`: `z.string().uuid().nullable()`
- `currency`- `currency`: `z.string().length(3)`
- `lines`- `lines`: `z.array(CartLine).max(100)`
- `customerId`
- `currency`
- `lines`
- `customerId`: `z.string().uuid().nullable()`
- `currency`: `z.string().length(3)`
- `lines`: `z.array(CartLine).max(100)`
## Changes## Changes
docs/api/categories.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Category API# Category API
The categories routes live in `src/handlers/categories/`. Each file exports an Express callback.The categories endpoints live in `src/handlers/categories/`. Each file exports one typed handler, and `src/schemas/categories.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /categories`| Method | Path | Access | Validation |
- `GET /categories/:id`| --- | --- | --- | --- |
- `POST /categories`| GET | /categories | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /categories/:id`| GET | /categories/:id | public | Path: `id` (UUID) |
- `DELETE /categories/:id`| POST | /categories | user | Body: `slug`, `name`, `parentId`, `position` |
- `GET /categories/search`| PATCH | /categories/:id | user | Body: any of the create fields, at least one |
- `GET /categories/export`| DELETE | /categories/:id | admin | Path: `id` (UUID) |
| GET | /categories/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /categories/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The categories routes live in `src/handlers/categories/`. Each file exports an Express callback.
- `GET /categories`
- `GET /categories/:id`
- `POST /categories`
- `PATCH /categories/:id`
- `DELETE /categories/:id`
- `GET /categories/search`
- `GET /categories/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The categories endpoints live in `src/handlers/categories/`. Each file exports one typed handler, and `src/schemas/categories.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /categories | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /categories/:id | public | Path: `id` (UUID) |
| POST | /categories | user | Body: `slug`, `name`, `parentId`, `position` |
| PATCH | /categories/:id | user | Body: any of the create fields, at least one |
| DELETE | /categories/:id | admin | Path: `id` (UUID) |
| GET | /categories/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /categories/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `slug`- `slug`: `z.string().regex(/^[a-z0-9-]+$/)`
- `name`- `name`: `z.string().min(1).max(120)`
- `parentId`- `parentId`: `z.string().uuid().nullable()`
- `position`- `position`: `z.number().int().min(0)`
- `slug`
- `name`
- `parentId`
- `position`
- `slug`: `z.string().regex(/^[a-z0-9-]+$/)`
- `name`: `z.string().min(1).max(120)`
- `parentId`: `z.string().uuid().nullable()`
- `position`: `z.number().int().min(0)`
## Changes## Changes
docs/api/collections.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Collection API# Collection API
The collections routes live in `src/handlers/collections/`. Each file exports an Express callback.The collections endpoints live in `src/handlers/collections/`. Each file exports one typed handler, and `src/schemas/collections.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /collections`| Method | Path | Access | Validation |
- `GET /collections/:id`| --- | --- | --- | --- |
- `POST /collections`| GET | /collections | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /collections/:id`| GET | /collections/:id | public | Path: `id` (UUID) |
- `DELETE /collections/:id`| POST | /collections | user | Body: `slug`, `title`, `productIds` |
- `GET /collections/search`| PATCH | /collections/:id | user | Body: any of the create fields, at least one |
- `GET /collections/export`| DELETE | /collections/:id | admin | Path: `id` (UUID) |
| GET | /collections/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /collections/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The collections routes live in `src/handlers/collections/`. Each file exports an Express callback.
- `GET /collections`
- `GET /collections/:id`
- `POST /collections`
- `PATCH /collections/:id`
- `DELETE /collections/:id`
- `GET /collections/search`
- `GET /collections/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The collections endpoints live in `src/handlers/collections/`. Each file exports one typed handler, and `src/schemas/collections.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /collections | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /collections/:id | public | Path: `id` (UUID) |
| POST | /collections | user | Body: `slug`, `title`, `productIds` |
| PATCH | /collections/:id | user | Body: any of the create fields, at least one |
| DELETE | /collections/:id | admin | Path: `id` (UUID) |
| GET | /collections/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /collections/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `slug`- `slug`: `z.string().regex(/^[a-z0-9-]+$/)`
- `title`- `title`: `z.string().min(1).max(160)`
- `productIds`- `productIds`: `z.array(z.string().uuid()).max(500)`
- `slug`
- `title`
- `productIds`
- `slug`: `z.string().regex(/^[a-z0-9-]+$/)`
- `title`: `z.string().min(1).max(160)`
- `productIds`: `z.array(z.string().uuid()).max(500)`
## Changes## Changes
docs/api/consents.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Consent API# Consent API
The consents routes live in `src/handlers/consents/`. Each file exports an Express callback.The consents endpoints live in `src/handlers/consents/`. Each file exports one typed handler, and `src/schemas/consents.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /consents`| Method | Path | Access | Validation |
- `GET /consents/:id`| --- | --- | --- | --- |
- `POST /consents`| GET | /consents | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /consents/:id`| GET | /consents/:id | public | Path: `id` (UUID) |
- `DELETE /consents/:id`| POST | /consents | user | Body: `customerId`, `purpose`, `granted` |
- `GET /consents/search`| PATCH | /consents/:id | user | Body: any of the create fields, at least one |
- `GET /consents/export`| DELETE | /consents/:id | admin | Path: `id` (UUID) |
| GET | /consents/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /consents/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The consents routes live in `src/handlers/consents/`. Each file exports an Express callback.
- `GET /consents`
- `GET /consents/:id`
- `POST /consents`
- `PATCH /consents/:id`
- `DELETE /consents/:id`
- `GET /consents/search`
- `GET /consents/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The consents endpoints live in `src/handlers/consents/`. Each file exports one typed handler, and `src/schemas/consents.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /consents | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /consents/:id | public | Path: `id` (UUID) |
| POST | /consents | user | Body: `customerId`, `purpose`, `granted` |
| PATCH | /consents/:id | user | Body: any of the create fields, at least one |
| DELETE | /consents/:id | admin | Path: `id` (UUID) |
| GET | /consents/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /consents/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `customerId`- `customerId`: `z.string().uuid()`
- `purpose`- `purpose`: `z.enum(['marketing', 'analytics', 'personalisation'])`
- `granted`- `granted`: `z.boolean()`
- `customerId`
- `purpose`
- `granted`
- `customerId`: `z.string().uuid()`
- `purpose`: `z.enum(['marketing', 'analytics', 'personalisation'])`
- `granted`: `z.boolean()`
## Changes## Changes
docs/api/coupons.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Coupon API# Coupon API
The coupons routes live in `src/handlers/coupons/`. Each file exports an Express callback.The coupons endpoints live in `src/handlers/coupons/`. Each file exports one typed handler, and `src/schemas/coupons.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /coupons`| Method | Path | Access | Validation |
- `GET /coupons/:id`| --- | --- | --- | --- |
- `POST /coupons`| GET | /coupons | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /coupons/:id`| GET | /coupons/:id | public | Path: `id` (UUID) |
- `DELETE /coupons/:id`| POST | /coupons | user | Body: `code`, `percentOff`, `expiresAt` |
- `GET /coupons/search`| PATCH | /coupons/:id | user | Body: any of the create fields, at least one |
- `GET /coupons/export`| DELETE | /coupons/:id | admin | Path: `id` (UUID) |
| GET | /coupons/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /coupons/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The coupons routes live in `src/handlers/coupons/`. Each file exports an Express callback.
- `GET /coupons`
- `GET /coupons/:id`
- `POST /coupons`
- `PATCH /coupons/:id`
- `DELETE /coupons/:id`
- `GET /coupons/search`
- `GET /coupons/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The coupons endpoints live in `src/handlers/coupons/`. Each file exports one typed handler, and `src/schemas/coupons.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /coupons | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /coupons/:id | public | Path: `id` (UUID) |
| POST | /coupons | user | Body: `code`, `percentOff`, `expiresAt` |
| PATCH | /coupons/:id | user | Body: any of the create fields, at least one |
| DELETE | /coupons/:id | admin | Path: `id` (UUID) |
| GET | /coupons/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /coupons/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `code`- `code`: `z.string().regex(/^[A-Z0-9]{4,16}$/)`
- `percentOff`- `percentOff`: `z.number().int().min(1).max(90)`
- `expiresAt`- `expiresAt`: `z.string().datetime().nullable()`
- `code`
- `percentOff`
- `expiresAt`
- `code`: `z.string().regex(/^[A-Z0-9]{4,16}$/)`
- `percentOff`: `z.number().int().min(1).max(90)`
- `expiresAt`: `z.string().datetime().nullable()`
## Changes## Changes
docs/api/customers.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Customer API# Customer API
The customers routes live in `src/handlers/customers/`. Each file exports an Express callback.The customers endpoints live in `src/handlers/customers/`. Each file exports one typed handler, and `src/schemas/customers.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /customers`| Method | Path | Access | Validation |
- `GET /customers/:id`| --- | --- | --- | --- |
- `POST /customers`| GET | /customers | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /customers/:id`| GET | /customers/:id | public | Path: `id` (UUID) |
- `DELETE /customers/:id`| POST | /customers | user | Body: `email`, `name`, `marketingOptIn` |
- `GET /customers/search`| PATCH | /customers/:id | user | Body: any of the create fields, at least one |
- `GET /customers/export`| DELETE | /customers/:id | admin | Path: `id` (UUID) |
| GET | /customers/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /customers/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The customers routes live in `src/handlers/customers/`. Each file exports an Express callback.
- `GET /customers`
- `GET /customers/:id`
- `POST /customers`
- `PATCH /customers/:id`
- `DELETE /customers/:id`
- `GET /customers/search`
- `GET /customers/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The customers endpoints live in `src/handlers/customers/`. Each file exports one typed handler, and `src/schemas/customers.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /customers | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /customers/:id | public | Path: `id` (UUID) |
| POST | /customers | user | Body: `email`, `name`, `marketingOptIn` |
| PATCH | /customers/:id | user | Body: any of the create fields, at least one |
| DELETE | /customers/:id | admin | Path: `id` (UUID) |
| GET | /customers/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /customers/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `email`- `email`: `z.string().email()`
- `name`- `name`: `z.string().min(1).max(160)`
- `marketingOptIn`- `marketingOptIn`: `z.boolean()`
- `email`
- `name`
- `marketingOptIn`
- `email`: `z.string().email()`
- `name`: `z.string().min(1).max(160)`
- `marketingOptIn`: `z.boolean()`
## Changes## Changes
docs/api/giftCards.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# GiftCard API# GiftCard API
The giftCards routes live in `src/handlers/giftCards/`. Each file exports an Express callback.The giftCards endpoints live in `src/handlers/giftCards/`. Each file exports one typed handler, and `src/schemas/giftCards.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /giftCards`| Method | Path | Access | Validation |
- `GET /giftCards/:id`| --- | --- | --- | --- |
- `POST /giftCards`| GET | /giftCards | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /giftCards/:id`| GET | /giftCards/:id | public | Path: `id` (UUID) |
- `DELETE /giftCards/:id`| POST | /giftCards | user | Body: `code`, `balanceCents`, `currency` |
- `GET /giftCards/search`| PATCH | /giftCards/:id | user | Body: any of the create fields, at least one |
- `GET /giftCards/export`| DELETE | /giftCards/:id | admin | Path: `id` (UUID) |
| GET | /giftCards/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /giftCards/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The giftCards routes live in `src/handlers/giftCards/`. Each file exports an Express callback.
- `GET /giftCards`
- `GET /giftCards/:id`
- `POST /giftCards`
- `PATCH /giftCards/:id`
- `DELETE /giftCards/:id`
- `GET /giftCards/search`
- `GET /giftCards/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The giftCards endpoints live in `src/handlers/giftCards/`. Each file exports one typed handler, and `src/schemas/giftCards.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /giftCards | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /giftCards/:id | public | Path: `id` (UUID) |
| POST | /giftCards | user | Body: `code`, `balanceCents`, `currency` |
| PATCH | /giftCards/:id | user | Body: any of the create fields, at least one |
| DELETE | /giftCards/:id | admin | Path: `id` (UUID) |
| GET | /giftCards/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /giftCards/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `code`- `code`: `z.string().regex(/^[A-Z0-9]{16}$/)`
- `balanceCents`- `balanceCents`: `z.number().int().nonnegative()`
- `currency`- `currency`: `z.string().length(3)`
- `code`
- `balanceCents`
- `currency`
- `code`: `z.string().regex(/^[A-Z0-9]{16}$/)`
- `balanceCents`: `z.number().int().nonnegative()`
- `currency`: `z.string().length(3)`
## Changes## Changes
docs/api/inventory.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# StockLevel API# StockLevel API
The inventory routes live in `src/handlers/inventory/`. Each file exports an Express callback.The inventory endpoints live in `src/handlers/inventory/`. Each file exports one typed handler, and `src/schemas/inventory.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /inventory`| Method | Path | Access | Validation |
- `GET /inventory/:id`| --- | --- | --- | --- |
- `POST /inventory`| GET | /inventory | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /inventory/:id`| GET | /inventory/:id | public | Path: `id` (UUID) |
- `DELETE /inventory/:id`| POST | /inventory | user | Body: `sku`, `warehouseId`, `onHand`, `reserved` |
- `GET /inventory/search`| PATCH | /inventory/:id | user | Body: any of the create fields, at least one |
- `GET /inventory/export`| DELETE | /inventory/:id | admin | Path: `id` (UUID) |
| GET | /inventory/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /inventory/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The inventory routes live in `src/handlers/inventory/`. Each file exports an Express callback.
- `GET /inventory`
- `GET /inventory/:id`
- `POST /inventory`
- `PATCH /inventory/:id`
- `DELETE /inventory/:id`
- `GET /inventory/search`
- `GET /inventory/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The inventory endpoints live in `src/handlers/inventory/`. Each file exports one typed handler, and `src/schemas/inventory.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /inventory | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /inventory/:id | public | Path: `id` (UUID) |
| POST | /inventory | user | Body: `sku`, `warehouseId`, `onHand`, `reserved` |
| PATCH | /inventory/:id | user | Body: any of the create fields, at least one |
| DELETE | /inventory/:id | admin | Path: `id` (UUID) |
| GET | /inventory/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /inventory/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `sku`- `sku`: `z.string().min(3).max(32)`
- `warehouseId`- `warehouseId`: `z.string().uuid()`
- `onHand`- `onHand`: `z.number().int()`
- `reserved`- `reserved`: `z.number().int().nonnegative()`
- `sku`
- `warehouseId`
- `onHand`
- `reserved`
- `sku`: `z.string().min(3).max(32)`
- `warehouseId`: `z.string().uuid()`
- `onHand`: `z.number().int()`
- `reserved`: `z.number().int().nonnegative()`
## Changes## Changes
docs/api/invoices.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Invoice API# Invoice API
The invoices routes live in `src/handlers/invoices/`. Each file exports an Express callback.The invoices endpoints live in `src/handlers/invoices/`. Each file exports one typed handler, and `src/schemas/invoices.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /invoices`| Method | Path | Access | Validation |
- `GET /invoices/:id`| --- | --- | --- | --- |
- `POST /invoices`| GET | /invoices | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /invoices/:id`| GET | /invoices/:id | public | Path: `id` (UUID) |
- `DELETE /invoices/:id`| POST | /invoices | user | Body: `number`, `orderId`, `dueAt`, `totalCents` |
- `GET /invoices/search`| PATCH | /invoices/:id | user | Body: any of the create fields, at least one |
- `GET /invoices/export`| DELETE | /invoices/:id | admin | Path: `id` (UUID) |
| GET | /invoices/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /invoices/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The invoices routes live in `src/handlers/invoices/`. Each file exports an Express callback.
- `GET /invoices`
- `GET /invoices/:id`
- `POST /invoices`
- `PATCH /invoices/:id`
- `DELETE /invoices/:id`
- `GET /invoices/search`
- `GET /invoices/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The invoices endpoints live in `src/handlers/invoices/`. Each file exports one typed handler, and `src/schemas/invoices.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /invoices | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /invoices/:id | public | Path: `id` (UUID) |
| POST | /invoices | user | Body: `number`, `orderId`, `dueAt`, `totalCents` |
| PATCH | /invoices/:id | user | Body: any of the create fields, at least one |
| DELETE | /invoices/:id | admin | Path: `id` (UUID) |
| GET | /invoices/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /invoices/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `number`- `number`: `z.string().regex(/^INV-\d{8}$/)`
- `orderId`- `orderId`: `z.string().uuid()`
- `dueAt`- `dueAt`: `z.string().datetime()`
- `totalCents`- `totalCents`: `z.number().int().nonnegative()`
- `number`
- `orderId`
- `dueAt`
- `totalCents`
- `number`: `z.string().regex(/^INV-\d{8}$/)`
- `orderId`: `z.string().uuid()`
- `dueAt`: `z.string().datetime()`
- `totalCents`: `z.number().int().nonnegative()`
## Changes## Changes
docs/api/loyalty.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# LoyaltyAccount API# LoyaltyAccount API
The loyalty routes live in `src/handlers/loyalty/`. Each file exports an Express callback.The loyalty endpoints live in `src/handlers/loyalty/`. Each file exports one typed handler, and `src/schemas/loyalty.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /loyalty`| Method | Path | Access | Validation |
- `GET /loyalty/:id`| --- | --- | --- | --- |
- `POST /loyalty`| GET | /loyalty | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /loyalty/:id`| GET | /loyalty/:id | public | Path: `id` (UUID) |
- `DELETE /loyalty/:id`| POST | /loyalty | user | Body: `customerId`, `points`, `tier` |
- `GET /loyalty/search`| PATCH | /loyalty/:id | user | Body: any of the create fields, at least one |
- `GET /loyalty/export`| DELETE | /loyalty/:id | admin | Path: `id` (UUID) |
| GET | /loyalty/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /loyalty/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The loyalty routes live in `src/handlers/loyalty/`. Each file exports an Express callback.
- `GET /loyalty`
- `GET /loyalty/:id`
- `POST /loyalty`
- `PATCH /loyalty/:id`
- `DELETE /loyalty/:id`
- `GET /loyalty/search`
- `GET /loyalty/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The loyalty endpoints live in `src/handlers/loyalty/`. Each file exports one typed handler, and `src/schemas/loyalty.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /loyalty | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /loyalty/:id | public | Path: `id` (UUID) |
| POST | /loyalty | user | Body: `customerId`, `points`, `tier` |
| PATCH | /loyalty/:id | user | Body: any of the create fields, at least one |
| DELETE | /loyalty/:id | admin | Path: `id` (UUID) |
| GET | /loyalty/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /loyalty/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `customerId`- `customerId`: `z.string().uuid()`
- `points`- `points`: `z.number().int().nonnegative()`
- `tier`- `tier`: `z.enum(['bronze', 'silver', 'gold'])`
- `customerId`
- `points`
- `tier`
- `customerId`: `z.string().uuid()`
- `points`: `z.number().int().nonnegative()`
- `tier`: `z.enum(['bronze', 'silver', 'gold'])`
## Changes## Changes
docs/api/media.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# MediaAsset API# MediaAsset API
The media routes live in `src/handlers/media/`. Each file exports an Express callback.The media endpoints live in `src/handlers/media/`. Each file exports one typed handler, and `src/schemas/media.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /media`| Method | Path | Access | Validation |
- `GET /media/:id`| --- | --- | --- | --- |
- `POST /media`| GET | /media | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /media/:id`| GET | /media/:id | public | Path: `id` (UUID) |
- `DELETE /media/:id`| POST | /media | user | Body: `productId`, `url`, `altText`, `position` |
- `GET /media/search`| PATCH | /media/:id | user | Body: any of the create fields, at least one |
- `GET /media/export`| DELETE | /media/:id | admin | Path: `id` (UUID) |
| GET | /media/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /media/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The media routes live in `src/handlers/media/`. Each file exports an Express callback.
- `GET /media`
- `GET /media/:id`
- `POST /media`
- `PATCH /media/:id`
- `DELETE /media/:id`
- `GET /media/search`
- `GET /media/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The media endpoints live in `src/handlers/media/`. Each file exports one typed handler, and `src/schemas/media.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /media | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /media/:id | public | Path: `id` (UUID) |
| POST | /media | user | Body: `productId`, `url`, `altText`, `position` |
| PATCH | /media/:id | user | Body: any of the create fields, at least one |
| DELETE | /media/:id | admin | Path: `id` (UUID) |
| GET | /media/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /media/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `productId`- `productId`: `z.string().uuid()`
- `url`- `url`: `z.string().url()`
- `altText`- `altText`: `z.string().max(300)`
- `position`- `position`: `z.number().int().min(0)`
- `productId`
- `url`
- `altText`
- `position`
- `productId`: `z.string().uuid()`
- `url`: `z.string().url()`
- `altText`: `z.string().max(300)`
- `position`: `z.number().int().min(0)`
## Changes## Changes
docs/api/notifications.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Notification API# Notification API
The notifications routes live in `src/handlers/notifications/`. Each file exports an Express callback.The notifications endpoints live in `src/handlers/notifications/`. Each file exports one typed handler, and `src/schemas/notifications.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /notifications`| Method | Path | Access | Validation |
- `GET /notifications/:id`| --- | --- | --- | --- |
- `POST /notifications`| GET | /notifications | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /notifications/:id`| GET | /notifications/:id | public | Path: `id` (UUID) |
- `DELETE /notifications/:id`| POST | /notifications | user | Body: `customerId`, `channel`, `template` |
- `GET /notifications/search`| PATCH | /notifications/:id | user | Body: any of the create fields, at least one |
- `GET /notifications/export`| DELETE | /notifications/:id | admin | Path: `id` (UUID) |
| GET | /notifications/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /notifications/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The notifications routes live in `src/handlers/notifications/`. Each file exports an Express callback.
- `GET /notifications`
- `GET /notifications/:id`
- `POST /notifications`
- `PATCH /notifications/:id`
- `DELETE /notifications/:id`
- `GET /notifications/search`
- `GET /notifications/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The notifications endpoints live in `src/handlers/notifications/`. Each file exports one typed handler, and `src/schemas/notifications.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /notifications | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /notifications/:id | public | Path: `id` (UUID) |
| POST | /notifications | user | Body: `customerId`, `channel`, `template` |
| PATCH | /notifications/:id | user | Body: any of the create fields, at least one |
| DELETE | /notifications/:id | admin | Path: `id` (UUID) |
| GET | /notifications/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /notifications/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `customerId`- `customerId`: `z.string().uuid()`
- `channel`- `channel`: `z.enum(['email', 'sms', 'push'])`
- `template`- `template`: `z.string().max(80)`
- `customerId`
- `channel`
- `template`
- `customerId`: `z.string().uuid()`
- `channel`: `z.enum(['email', 'sms', 'push'])`
- `template`: `z.string().max(80)`
## Changes## Changes
docs/api/orders.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Order API# Order API
The orders routes live in `src/handlers/orders/`. Each file exports an Express callback.The orders endpoints live in `src/handlers/orders/`. Each file exports one typed handler, and `src/schemas/orders.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /orders`| Method | Path | Access | Validation |
- `GET /orders/:id`| --- | --- | --- | --- |
- `POST /orders`| GET | /orders | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /orders/:id`| GET | /orders/:id | public | Path: `id` (UUID) |
- `DELETE /orders/:id`| POST | /orders | user | Body: `number`, `customerId`, `totalCents`, `status` |
- `GET /orders/search`| PATCH | /orders/:id | user | Body: any of the create fields, at least one |
- `GET /orders/export`| DELETE | /orders/:id | admin | Path: `id` (UUID) |
| GET | /orders/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /orders/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The orders routes live in `src/handlers/orders/`. Each file exports an Express callback.
- `GET /orders`
- `GET /orders/:id`
- `POST /orders`
- `PATCH /orders/:id`
- `DELETE /orders/:id`
- `GET /orders/search`
- `GET /orders/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The orders endpoints live in `src/handlers/orders/`. Each file exports one typed handler, and `src/schemas/orders.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /orders | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /orders/:id | public | Path: `id` (UUID) |
| POST | /orders | user | Body: `number`, `customerId`, `totalCents`, `status` |
| PATCH | /orders/:id | user | Body: any of the create fields, at least one |
| DELETE | /orders/:id | admin | Path: `id` (UUID) |
| GET | /orders/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /orders/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `number`- `number`: `z.string().regex(/^SO-\d{8}$/)`
- `customerId`- `customerId`: `z.string().uuid()`
- `totalCents`- `totalCents`: `z.number().int().nonnegative()`
- `status`- `status`: `z.enum(['pending', 'paid', 'shipped', 'cancelled'])`
- `number`
- `customerId`
- `totalCents`
- `status`
- `number`: `z.string().regex(/^SO-\d{8}$/)`
- `customerId`: `z.string().uuid()`
- `totalCents`: `z.number().int().nonnegative()`
- `status`: `z.enum(['pending', 'paid', 'shipped', 'cancelled'])`
## Changes## Changes
docs/api/payments.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Payment API# Payment API
The payments routes live in `src/handlers/payments/`. Each file exports an Express callback.The payments endpoints live in `src/handlers/payments/`. Each file exports one typed handler, and `src/schemas/payments.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /payments`| Method | Path | Access | Validation |
- `GET /payments/:id`| --- | --- | --- | --- |
- `POST /payments`| GET | /payments | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /payments/:id`| GET | /payments/:id | public | Path: `id` (UUID) |
- `DELETE /payments/:id`| POST | /payments | user | Body: `orderId`, `provider`, `amountCents`, `reference` |
- `GET /payments/search`| PATCH | /payments/:id | user | Body: any of the create fields, at least one |
- `GET /payments/export`| DELETE | /payments/:id | admin | Path: `id` (UUID) |
| GET | /payments/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /payments/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The payments routes live in `src/handlers/payments/`. Each file exports an Express callback.
- `GET /payments`
- `GET /payments/:id`
- `POST /payments`
- `PATCH /payments/:id`
- `DELETE /payments/:id`
- `GET /payments/search`
- `GET /payments/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The payments endpoints live in `src/handlers/payments/`. Each file exports one typed handler, and `src/schemas/payments.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /payments | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /payments/:id | public | Path: `id` (UUID) |
| POST | /payments | user | Body: `orderId`, `provider`, `amountCents`, `reference` |
| PATCH | /payments/:id | user | Body: any of the create fields, at least one |
| DELETE | /payments/:id | admin | Path: `id` (UUID) |
| GET | /payments/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /payments/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `orderId`- `orderId`: `z.string().uuid()`
- `provider`- `provider`: `z.enum(['card', 'paypal', 'invoice'])`
- `amountCents`- `amountCents`: `z.number().int().positive()`
- `reference`- `reference`: `z.string().max(64)`
- `orderId`
- `provider`
- `amountCents`
- `reference`
- `orderId`: `z.string().uuid()`
- `provider`: `z.enum(['card', 'paypal', 'invoice'])`
- `amountCents`: `z.number().int().positive()`
- `reference`: `z.string().max(64)`
## Changes## Changes
docs/api/preferences.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Preference API# Preference API
The preferences routes live in `src/handlers/preferences/`. Each file exports an Express callback.The preferences endpoints live in `src/handlers/preferences/`. Each file exports one typed handler, and `src/schemas/preferences.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /preferences`| Method | Path | Access | Validation |
- `GET /preferences/:id`| --- | --- | --- | --- |
- `POST /preferences`| GET | /preferences | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /preferences/:id`| GET | /preferences/:id | public | Path: `id` (UUID) |
- `DELETE /preferences/:id`| POST | /preferences | user | Body: `customerId`, `locale`, `currency` |
- `GET /preferences/search`| PATCH | /preferences/:id | user | Body: any of the create fields, at least one |
- `GET /preferences/export`| DELETE | /preferences/:id | admin | Path: `id` (UUID) |
| GET | /preferences/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /preferences/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The preferences routes live in `src/handlers/preferences/`. Each file exports an Express callback.
- `GET /preferences`
- `GET /preferences/:id`
- `POST /preferences`
- `PATCH /preferences/:id`
- `DELETE /preferences/:id`
- `GET /preferences/search`
- `GET /preferences/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The preferences endpoints live in `src/handlers/preferences/`. Each file exports one typed handler, and `src/schemas/preferences.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /preferences | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /preferences/:id | public | Path: `id` (UUID) |
| POST | /preferences | user | Body: `customerId`, `locale`, `currency` |
| PATCH | /preferences/:id | user | Body: any of the create fields, at least one |
| DELETE | /preferences/:id | admin | Path: `id` (UUID) |
| GET | /preferences/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /preferences/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `customerId`- `customerId`: `z.string().uuid()`
- `locale`- `locale`: `z.string().max(10)`
- `currency`- `currency`: `z.string().length(3)`
- `customerId`
- `locale`
- `currency`
- `customerId`: `z.string().uuid()`
- `locale`: `z.string().max(10)`
- `currency`: `z.string().length(3)`
## Changes## Changes
docs/api/prices.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Price API# Price API
The prices routes live in `src/handlers/prices/`. Each file exports an Express callback.The prices endpoints live in `src/handlers/prices/`. Each file exports one typed handler, and `src/schemas/prices.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /prices`| Method | Path | Access | Validation |
- `GET /prices/:id`| --- | --- | --- | --- |
- `POST /prices`| GET | /prices | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /prices/:id`| GET | /prices/:id | public | Path: `id` (UUID) |
- `DELETE /prices/:id`| POST | /prices | user | Body: `productId`, `currency`, `amountCents`, `validFrom` |
- `GET /prices/search`| PATCH | /prices/:id | user | Body: any of the create fields, at least one |
- `GET /prices/export`| DELETE | /prices/:id | admin | Path: `id` (UUID) |
| GET | /prices/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /prices/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The prices routes live in `src/handlers/prices/`. Each file exports an Express callback.
- `GET /prices`
- `GET /prices/:id`
- `POST /prices`
- `PATCH /prices/:id`
- `DELETE /prices/:id`
- `GET /prices/search`
- `GET /prices/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The prices endpoints live in `src/handlers/prices/`. Each file exports one typed handler, and `src/schemas/prices.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /prices | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /prices/:id | public | Path: `id` (UUID) |
| POST | /prices | user | Body: `productId`, `currency`, `amountCents`, `validFrom` |
| PATCH | /prices/:id | user | Body: any of the create fields, at least one |
| DELETE | /prices/:id | admin | Path: `id` (UUID) |
| GET | /prices/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /prices/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `productId`- `productId`: `z.string().uuid()`
- `currency`- `currency`: `z.string().length(3)`
- `amountCents`- `amountCents`: `z.number().int().nonnegative()`
- `validFrom`- `validFrom`: `z.string().datetime()`
- `productId`
- `currency`
- `amountCents`
- `validFrom`
- `productId`: `z.string().uuid()`
- `currency`: `z.string().length(3)`
- `amountCents`: `z.number().int().nonnegative()`
- `validFrom`: `z.string().datetime()`
## Changes## Changes
docs/api/products.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Product API# Product API
The products routes live in `src/handlers/products/`. Each file exports an Express callback.The products endpoints live in `src/handlers/products/`. Each file exports one typed handler, and `src/schemas/products.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /products`| Method | Path | Access | Validation |
- `GET /products/:id`| --- | --- | --- | --- |
- `POST /products`| GET | /products | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /products/:id`| GET | /products/:id | public | Path: `id` (UUID) |
- `DELETE /products/:id`| POST | /products | user | Body: `sku`, `name`, `priceCents`, `status` |
- `GET /products/search`| PATCH | /products/:id | user | Body: any of the create fields, at least one |
- `GET /products/export`| DELETE | /products/:id | admin | Path: `id` (UUID) |
| GET | /products/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /products/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The products routes live in `src/handlers/products/`. Each file exports an Express callback.
- `GET /products`
- `GET /products/:id`
- `POST /products`
- `PATCH /products/:id`
- `DELETE /products/:id`
- `GET /products/search`
- `GET /products/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The products endpoints live in `src/handlers/products/`. Each file exports one typed handler, and `src/schemas/products.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /products | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /products/:id | public | Path: `id` (UUID) |
| POST | /products | user | Body: `sku`, `name`, `priceCents`, `status` |
| PATCH | /products/:id | user | Body: any of the create fields, at least one |
| DELETE | /products/:id | admin | Path: `id` (UUID) |
| GET | /products/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /products/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `sku`- `sku`: `z.string().min(3).max(32)`
- `name`- `name`: `z.string().min(1).max(200)`
- `priceCents`- `priceCents`: `z.number().int().nonnegative()`
- `status`- `status`: `z.enum(['draft', 'active', 'archived'])`
- `sku`
- `name`
- `priceCents`
- `status`
- `sku`: `z.string().min(3).max(32)`
- `name`: `z.string().min(1).max(200)`
- `priceCents`: `z.number().int().nonnegative()`
- `status`: `z.enum(['draft', 'active', 'archived'])`
## Changes## Changes
docs/api/quotes.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Quote API# Quote API
The quotes routes live in `src/handlers/quotes/`. Each file exports an Express callback.The quotes endpoints live in `src/handlers/quotes/`. Each file exports one typed handler, and `src/schemas/quotes.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /quotes`| Method | Path | Access | Validation |
- `GET /quotes/:id`| --- | --- | --- | --- |
- `POST /quotes`| GET | /quotes | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /quotes/:id`| GET | /quotes/:id | public | Path: `id` (UUID) |
- `DELETE /quotes/:id`| POST | /quotes | user | Body: `number`, `customerId`, `validUntil` |
- `GET /quotes/search`| PATCH | /quotes/:id | user | Body: any of the create fields, at least one |
- `GET /quotes/export`| DELETE | /quotes/:id | admin | Path: `id` (UUID) |
| GET | /quotes/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /quotes/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The quotes routes live in `src/handlers/quotes/`. Each file exports an Express callback.
- `GET /quotes`
- `GET /quotes/:id`
- `POST /quotes`
- `PATCH /quotes/:id`
- `DELETE /quotes/:id`
- `GET /quotes/search`
- `GET /quotes/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The quotes endpoints live in `src/handlers/quotes/`. Each file exports one typed handler, and `src/schemas/quotes.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /quotes | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /quotes/:id | public | Path: `id` (UUID) |
| POST | /quotes | user | Body: `number`, `customerId`, `validUntil` |
| PATCH | /quotes/:id | user | Body: any of the create fields, at least one |
| DELETE | /quotes/:id | admin | Path: `id` (UUID) |
| GET | /quotes/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /quotes/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `number`- `number`: `z.string().regex(/^QT-\d{8}$/)`
- `customerId`- `customerId`: `z.string().uuid()`
- `validUntil`- `validUntil`: `z.string().datetime()`
- `number`
- `customerId`
- `validUntil`
- `number`: `z.string().regex(/^QT-\d{8}$/)`
- `customerId`: `z.string().uuid()`
- `validUntil`: `z.string().datetime()`
## Changes## Changes
docs/api/refunds.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Refund API# Refund API
The refunds routes live in `src/handlers/refunds/`. Each file exports an Express callback.The refunds endpoints live in `src/handlers/refunds/`. Each file exports one typed handler, and `src/schemas/refunds.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /refunds`| Method | Path | Access | Validation |
- `GET /refunds/:id`| --- | --- | --- | --- |
- `POST /refunds`| GET | /refunds | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /refunds/:id`| GET | /refunds/:id | public | Path: `id` (UUID) |
- `DELETE /refunds/:id`| POST | /refunds | user | Body: `paymentId`, `amountCents`, `reason` |
- `GET /refunds/search`| PATCH | /refunds/:id | user | Body: any of the create fields, at least one |
- `GET /refunds/export`| DELETE | /refunds/:id | admin | Path: `id` (UUID) |
| GET | /refunds/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /refunds/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The refunds routes live in `src/handlers/refunds/`. Each file exports an Express callback.
- `GET /refunds`
- `GET /refunds/:id`
- `POST /refunds`
- `PATCH /refunds/:id`
- `DELETE /refunds/:id`
- `GET /refunds/search`
- `GET /refunds/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The refunds endpoints live in `src/handlers/refunds/`. Each file exports one typed handler, and `src/schemas/refunds.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /refunds | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /refunds/:id | public | Path: `id` (UUID) |
| POST | /refunds | user | Body: `paymentId`, `amountCents`, `reason` |
| PATCH | /refunds/:id | user | Body: any of the create fields, at least one |
| DELETE | /refunds/:id | admin | Path: `id` (UUID) |
| GET | /refunds/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /refunds/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `paymentId`- `paymentId`: `z.string().uuid()`
- `amountCents`- `amountCents`: `z.number().int().positive()`
- `reason`- `reason`: `z.enum(['damaged', 'late', 'other'])`
- `paymentId`
- `amountCents`
- `reason`
- `paymentId`: `z.string().uuid()`
- `amountCents`: `z.number().int().positive()`
- `reason`: `z.enum(['damaged', 'late', 'other'])`
## Changes## Changes
docs/api/returns.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# ReturnRequest API# ReturnRequest API
The returns routes live in `src/handlers/returns/`. Each file exports an Express callback.The returns endpoints live in `src/handlers/returns/`. Each file exports one typed handler, and `src/schemas/returns.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /returns`| Method | Path | Access | Validation |
- `GET /returns/:id`| --- | --- | --- | --- |
- `POST /returns`| GET | /returns | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /returns/:id`| GET | /returns/:id | public | Path: `id` (UUID) |
- `DELETE /returns/:id`| POST | /returns | user | Body: `orderId`, `lineIds`, `reason` |
- `GET /returns/search`| PATCH | /returns/:id | user | Body: any of the create fields, at least one |
- `GET /returns/export`| DELETE | /returns/:id | admin | Path: `id` (UUID) |
| GET | /returns/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /returns/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The returns routes live in `src/handlers/returns/`. Each file exports an Express callback.
- `GET /returns`
- `GET /returns/:id`
- `POST /returns`
- `PATCH /returns/:id`
- `DELETE /returns/:id`
- `GET /returns/search`
- `GET /returns/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The returns endpoints live in `src/handlers/returns/`. Each file exports one typed handler, and `src/schemas/returns.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /returns | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /returns/:id | public | Path: `id` (UUID) |
| POST | /returns | user | Body: `orderId`, `lineIds`, `reason` |
| PATCH | /returns/:id | user | Body: any of the create fields, at least one |
| DELETE | /returns/:id | admin | Path: `id` (UUID) |
| GET | /returns/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /returns/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `orderId`- `orderId`: `z.string().uuid()`
- `lineIds`- `lineIds`: `z.array(z.string().uuid()).min(1)`
- `reason`- `reason`: `z.string().max(500)`
- `orderId`
- `lineIds`
- `reason`
- `orderId`: `z.string().uuid()`
- `lineIds`: `z.array(z.string().uuid()).min(1)`
- `reason`: `z.string().max(500)`
## Changes## Changes
docs/api/reviews.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# ProductReview API# ProductReview API
The reviews routes live in `src/handlers/reviews/`. Each file exports an Express callback.The reviews endpoints live in `src/handlers/reviews/`. Each file exports one typed handler, and `src/schemas/reviews.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /reviews`| Method | Path | Access | Validation |
- `GET /reviews/:id`| --- | --- | --- | --- |
- `POST /reviews`| GET | /reviews | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /reviews/:id`| GET | /reviews/:id | public | Path: `id` (UUID) |
- `DELETE /reviews/:id`| POST | /reviews | user | Body: `productId`, `rating`, `title`, `body` |
- `GET /reviews/search`| PATCH | /reviews/:id | user | Body: any of the create fields, at least one |
- `GET /reviews/export`| DELETE | /reviews/:id | admin | Path: `id` (UUID) |
| GET | /reviews/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /reviews/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The reviews routes live in `src/handlers/reviews/`. Each file exports an Express callback.
- `GET /reviews`
- `GET /reviews/:id`
- `POST /reviews`
- `PATCH /reviews/:id`
- `DELETE /reviews/:id`
- `GET /reviews/search`
- `GET /reviews/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The reviews endpoints live in `src/handlers/reviews/`. Each file exports one typed handler, and `src/schemas/reviews.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /reviews | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /reviews/:id | public | Path: `id` (UUID) |
| POST | /reviews | user | Body: `productId`, `rating`, `title`, `body` |
| PATCH | /reviews/:id | user | Body: any of the create fields, at least one |
| DELETE | /reviews/:id | admin | Path: `id` (UUID) |
| GET | /reviews/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /reviews/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `productId`- `productId`: `z.string().uuid()`
- `rating`- `rating`: `z.number().int().min(1).max(5)`
- `title`- `title`: `z.string().max(120)`
- `body`- `body`: `z.string().max(5000)`
- `productId`
- `rating`
- `title`
- `body`
- `productId`: `z.string().uuid()`
- `rating`: `z.number().int().min(1).max(5)`
- `title`: `z.string().max(120)`
- `body`: `z.string().max(5000)`
## Changes## Changes
docs/api/sessions.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Session API# Session API
The sessions routes live in `src/handlers/sessions/`. Each file exports an Express callback.The sessions endpoints live in `src/handlers/sessions/`. Each file exports one typed handler, and `src/schemas/sessions.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /sessions`| Method | Path | Access | Validation |
- `GET /sessions/:id`| --- | --- | --- | --- |
- `POST /sessions`| GET | /sessions | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /sessions/:id`| GET | /sessions/:id | public | Path: `id` (UUID) |
- `DELETE /sessions/:id`| POST | /sessions | user | Body: `customerId`, `userAgent`, `expiresAt` |
- `GET /sessions/search`| PATCH | /sessions/:id | user | Body: any of the create fields, at least one |
- `GET /sessions/export`| DELETE | /sessions/:id | admin | Path: `id` (UUID) |
| GET | /sessions/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /sessions/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The sessions routes live in `src/handlers/sessions/`. Each file exports an Express callback.
- `GET /sessions`
- `GET /sessions/:id`
- `POST /sessions`
- `PATCH /sessions/:id`
- `DELETE /sessions/:id`
- `GET /sessions/search`
- `GET /sessions/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The sessions endpoints live in `src/handlers/sessions/`. Each file exports one typed handler, and `src/schemas/sessions.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /sessions | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /sessions/:id | public | Path: `id` (UUID) |
| POST | /sessions | user | Body: `customerId`, `userAgent`, `expiresAt` |
| PATCH | /sessions/:id | user | Body: any of the create fields, at least one |
| DELETE | /sessions/:id | admin | Path: `id` (UUID) |
| GET | /sessions/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /sessions/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `customerId`- `customerId`: `z.string().uuid()`
- `userAgent`- `userAgent`: `z.string().max(400)`
- `expiresAt`- `expiresAt`: `z.string().datetime()`
- `customerId`
- `userAgent`
- `expiresAt`
- `customerId`: `z.string().uuid()`
- `userAgent`: `z.string().max(400)`
- `expiresAt`: `z.string().datetime()`
## Changes## Changes
docs/api/shipments.md
+17 -15
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Shipment API# Shipment API
The shipments routes live in `src/handlers/shipments/`. Each file exports an Express callback.The shipments endpoints live in `src/handlers/shipments/`. Each file exports one typed handler, and `src/schemas/shipments.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /shipments`| Method | Path | Access | Validation |
- `GET /shipments/:id`| --- | --- | --- | --- |
- `POST /shipments`| GET | /shipments | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /shipments/:id`| GET | /shipments/:id | public | Path: `id` (UUID) |
- `DELETE /shipments/:id`| POST | /shipments | user | Body: `orderId`, `carrier`, `trackingNumber`, `shippedAt` |
- `GET /shipments/search`| PATCH | /shipments/:id | user | Body: any of the create fields, at least one |
- `GET /shipments/export`| DELETE | /shipments/:id | admin | Path: `id` (UUID) |
| GET | /shipments/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /shipments/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The shipments routes live in `src/handlers/shipments/`. Each file exports an Express callback.
- `GET /shipments`
- `GET /shipments/:id`
- `POST /shipments`
- `PATCH /shipments/:id`
- `DELETE /shipments/:id`
- `GET /shipments/search`
- `GET /shipments/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The shipments endpoints live in `src/handlers/shipments/`. Each file exports one typed handler, and `src/schemas/shipments.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /shipments | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /shipments/:id | public | Path: `id` (UUID) |
| POST | /shipments | user | Body: `orderId`, `carrier`, `trackingNumber`, `shippedAt` |
| PATCH | /shipments/:id | user | Body: any of the create fields, at least one |
| DELETE | /shipments/:id | admin | Path: `id` (UUID) |
| GET | /shipments/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /shipments/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `orderId`- `orderId`: `z.string().uuid()`
- `carrier`- `carrier`: `z.string().max(40)`
- `trackingNumber`- `trackingNumber`: `z.string().max(64)`
- `shippedAt`- `shippedAt`: `z.string().datetime().nullable()`
- `orderId`
- `carrier`
- `trackingNumber`
- `shippedAt`
- `orderId`: `z.string().uuid()`
- `carrier`: `z.string().max(40)`
- `trackingNumber`: `z.string().max(64)`
- `shippedAt`: `z.string().datetime().nullable()`
## Changes## Changes
docs/api/subscriptions.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Subscription API# Subscription API
The subscriptions routes live in `src/handlers/subscriptions/`. Each file exports an Express callback.The subscriptions endpoints live in `src/handlers/subscriptions/`. Each file exports one typed handler, and `src/schemas/subscriptions.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /subscriptions`| Method | Path | Access | Validation |
- `GET /subscriptions/:id`| --- | --- | --- | --- |
- `POST /subscriptions`| GET | /subscriptions | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /subscriptions/:id`| GET | /subscriptions/:id | public | Path: `id` (UUID) |
- `DELETE /subscriptions/:id`| POST | /subscriptions | user | Body: `customerId`, `plan`, `renewsAt` |
- `GET /subscriptions/search`| PATCH | /subscriptions/:id | user | Body: any of the create fields, at least one |
- `GET /subscriptions/export`| DELETE | /subscriptions/:id | admin | Path: `id` (UUID) |
| GET | /subscriptions/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /subscriptions/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The subscriptions routes live in `src/handlers/subscriptions/`. Each file exports an Express callback.
- `GET /subscriptions`
- `GET /subscriptions/:id`
- `POST /subscriptions`
- `PATCH /subscriptions/:id`
- `DELETE /subscriptions/:id`
- `GET /subscriptions/search`
- `GET /subscriptions/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The subscriptions endpoints live in `src/handlers/subscriptions/`. Each file exports one typed handler, and `src/schemas/subscriptions.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /subscriptions | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /subscriptions/:id | public | Path: `id` (UUID) |
| POST | /subscriptions | user | Body: `customerId`, `plan`, `renewsAt` |
| PATCH | /subscriptions/:id | user | Body: any of the create fields, at least one |
| DELETE | /subscriptions/:id | admin | Path: `id` (UUID) |
| GET | /subscriptions/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /subscriptions/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `customerId`- `customerId`: `z.string().uuid()`
- `plan`- `plan`: `z.enum(['monthly', 'quarterly', 'yearly'])`
- `renewsAt`- `renewsAt`: `z.string().datetime()`
- `customerId`
- `plan`
- `renewsAt`
- `customerId`: `z.string().uuid()`
- `plan`: `z.enum(['monthly', 'quarterly', 'yearly'])`
- `renewsAt`: `z.string().datetime()`
## Changes## Changes
docs/api/teams.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Team API# Team API
The teams routes live in `src/handlers/teams/`. Each file exports an Express callback.The teams endpoints live in `src/handlers/teams/`. Each file exports one typed handler, and `src/schemas/teams.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /teams`| Method | Path | Access | Validation |
- `GET /teams/:id`| --- | --- | --- | --- |
- `POST /teams`| GET | /teams | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /teams/:id`| GET | /teams/:id | public | Path: `id` (UUID) |
- `DELETE /teams/:id`| POST | /teams | user | Body: `slug`, `name`, `ownerId` |
- `GET /teams/search`| PATCH | /teams/:id | user | Body: any of the create fields, at least one |
- `GET /teams/export`| DELETE | /teams/:id | admin | Path: `id` (UUID) |
| GET | /teams/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /teams/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The teams routes live in `src/handlers/teams/`. Each file exports an Express callback.
- `GET /teams`
- `GET /teams/:id`
- `POST /teams`
- `PATCH /teams/:id`
- `DELETE /teams/:id`
- `GET /teams/search`
- `GET /teams/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The teams endpoints live in `src/handlers/teams/`. Each file exports one typed handler, and `src/schemas/teams.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /teams | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /teams/:id | public | Path: `id` (UUID) |
| POST | /teams | user | Body: `slug`, `name`, `ownerId` |
| PATCH | /teams/:id | user | Body: any of the create fields, at least one |
| DELETE | /teams/:id | admin | Path: `id` (UUID) |
| GET | /teams/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /teams/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `slug`- `slug`: `z.string().regex(/^[a-z0-9-]+$/)`
- `name`- `name`: `z.string().min(1).max(120)`
- `ownerId`- `ownerId`: `z.string().uuid()`
- `slug`
- `name`
- `ownerId`
- `slug`: `z.string().regex(/^[a-z0-9-]+$/)`
- `name`: `z.string().min(1).max(120)`
- `ownerId`: `z.string().uuid()`
## Changes## Changes
docs/api/variants.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Variant API# Variant API
The variants routes live in `src/handlers/variants/`. Each file exports an Express callback.The variants endpoints live in `src/handlers/variants/`. Each file exports one typed handler, and `src/schemas/variants.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /variants`| Method | Path | Access | Validation |
- `GET /variants/:id`| --- | --- | --- | --- |
- `POST /variants`| GET | /variants | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /variants/:id`| GET | /variants/:id | public | Path: `id` (UUID) |
- `DELETE /variants/:id`| POST | /variants | user | Body: `productId`, `sku`, `options` |
- `GET /variants/search`| PATCH | /variants/:id | user | Body: any of the create fields, at least one |
- `GET /variants/export`| DELETE | /variants/:id | admin | Path: `id` (UUID) |
| GET | /variants/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /variants/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The variants routes live in `src/handlers/variants/`. Each file exports an Express callback.
- `GET /variants`
- `GET /variants/:id`
- `POST /variants`
- `PATCH /variants/:id`
- `DELETE /variants/:id`
- `GET /variants/search`
- `GET /variants/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The variants endpoints live in `src/handlers/variants/`. Each file exports one typed handler, and `src/schemas/variants.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /variants | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /variants/:id | public | Path: `id` (UUID) |
| POST | /variants | user | Body: `productId`, `sku`, `options` |
| PATCH | /variants/:id | user | Body: any of the create fields, at least one |
| DELETE | /variants/:id | admin | Path: `id` (UUID) |
| GET | /variants/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /variants/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `productId`- `productId`: `z.string().uuid()`
- `sku`- `sku`: `z.string().min(3).max(32)`
- `options`- `options`: `z.record(z.string(), z.string())`
- `productId`
- `sku`
- `options`
- `productId`: `z.string().uuid()`
- `sku`: `z.string().min(3).max(32)`
- `options`: `z.record(z.string(), z.string())`
## Changes## Changes
docs/api/wishlists.md
+16 -14
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.

Placing the discussions of this file for the layout of this page…

# Wishlist API# Wishlist API
The wishlists routes live in `src/handlers/wishlists/`. Each file exports an Express callback.The wishlists endpoints live in `src/handlers/wishlists/`. Each file exports one typed handler, and `src/schemas/wishlists.ts` holds the schemas that the pipeline validates before the handler runs.
- `GET /wishlists`| Method | Path | Access | Validation |
- `GET /wishlists/:id`| --- | --- | --- | --- |
- `POST /wishlists`| GET | /wishlists | public | List query: `limit` (1–100, default 20), `cursor` |
- `PATCH /wishlists/:id`| GET | /wishlists/:id | public | Path: `id` (UUID) |
- `DELETE /wishlists/:id`| POST | /wishlists | user | Body: `customerId`, `name`, `productIds` |
- `GET /wishlists/search`| PATCH | /wishlists/:id | user | Body: any of the create fields, at least one |
- `GET /wishlists/export`| DELETE | /wishlists/:id | admin | Path: `id` (UUID) |
| GET | /wishlists/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.| GET | /wishlists/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
The wishlists routes live in `src/handlers/wishlists/`. Each file exports an Express callback.
- `GET /wishlists`
- `GET /wishlists/:id`
- `POST /wishlists`
- `PATCH /wishlists/:id`
- `DELETE /wishlists/:id`
- `GET /wishlists/search`
- `GET /wishlists/export`
Errors are returned as `{ "error": "<message>" }` with a 400, 404 or 500 status.
The wishlists endpoints live in `src/handlers/wishlists/`. Each file exports one typed handler, and `src/schemas/wishlists.ts` holds the schemas that the pipeline validates before the handler runs.
| Method | Path | Access | Validation |
| --- | --- | --- | --- |
| GET | /wishlists | public | List query: `limit` (1–100, default 20), `cursor` |
| GET | /wishlists/:id | public | Path: `id` (UUID) |
| POST | /wishlists | user | Body: `customerId`, `name`, `productIds` |
| PATCH | /wishlists/:id | user | Body: any of the create fields, at least one |
| DELETE | /wishlists/:id | admin | Path: `id` (UUID) |
| GET | /wishlists/search | public | Query: `q` (2–100 characters), `limit` (1–50) |
| GET | /wishlists/export | admin | Query: `format` (`csv` or `json`), `limit` |
An error is `{ "error": { "code": "<code>", "message": "<message>" } }`. A request that fails validation gets a 422 with the field of each problem.
## Fields## Fields
- `customerId`- `customerId`: `z.string().uuid()`
- `name`- `name`: `z.string().min(1).max(80)`
- `productIds`- `productIds`: `z.array(z.string().uuid()).max(200)`
- `customerId`
- `name`
- `productIds`
- `customerId`: `z.string().uuid()`
- `name`: `z.string().min(1).max(80)`
- `productIds`: `z.array(z.string().uuid()).max(200)`
## Changes## Changes

Shared logger import

The 64 scheduled jobs import the shared @storefront/logger package instead of the local log module. The two examples show the whole change; the other jobs repeat it exactly.

Mechanical change · 64 files · 64 hunks

Replace import { log } from '../log'; with import { logger } from '@storefront/logger';, and each log.info( and log.debug( call with logger.info( and logger.debug(. Nothing else changes.

Verification:

Applied the replacements to the captured old side of each job file and compared the result with its captured new side: all 64 files match exactly. No job ran.

2 files below show the representative examples, and 62 matching files wait in the remaining group. A reviewed example marks only its own file.

src/jobs/products-cleanup.ts
+5 -5
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Delete the expired products every night.// Delete the expired products every night.
import { db } from '../db';import { db } from '../db';
import { log } from '../log';import { logger } from '@storefront/logger';
import { log } from '../log';
import { logger } from '@storefront/logger';
export async function run() {export async function run() {
log.info('src/jobs/products-cleanup.ts started'); logger.info('src/jobs/products-cleanup.ts started');
log.info('src/jobs/products-cleanup.ts started');
logger.info('src/jobs/products-cleanup.ts started');
const step1 = await db.products.deleteExpired({ olderThanDays: 90 }); const step1 = await db.products.deleteExpired({ olderThanDays: 90 });
log.debug('src/jobs/products-cleanup.ts step 1', { rows: step1.count }); logger.debug('src/jobs/products-cleanup.ts step 1', { rows: step1.count });
log.debug('src/jobs/products-cleanup.ts step 1', { rows: step1.count });
logger.debug('src/jobs/products-cleanup.ts step 1', { rows: step1.count });
const step2 = await db.products.vacuum(); const step2 = await db.products.vacuum();
log.debug('src/jobs/products-cleanup.ts step 2', { rows: step2.count }); logger.debug('src/jobs/products-cleanup.ts step 2', { rows: step2.count });
log.debug('src/jobs/products-cleanup.ts step 2', { rows: step2.count });
logger.debug('src/jobs/products-cleanup.ts step 2', { rows: step2.count });
log.info('src/jobs/products-cleanup.ts finished'); logger.info('src/jobs/products-cleanup.ts finished');
log.info('src/jobs/products-cleanup.ts finished');
logger.info('src/jobs/products-cleanup.ts finished');
}}
src/jobs/products-reindex.ts
+6 -6
Difftastic 0.69.0 · TypeScript: changed syntax is marked

Placing the discussions of this file for the layout of this page…

// Rebuild the search index of the products every hour.// Rebuild the search index of the products every hour.
import { db } from '../db';import { db } from '../db';
import { log } from '../log';import { logger } from '@storefront/logger';
import { log } from '../log';
import { logger } from '@storefront/logger';
export async function run() {export async function run() {
log.info('src/jobs/products-reindex.ts started'); logger.info('src/jobs/products-reindex.ts started');
log.info('src/jobs/products-reindex.ts started');
logger.info('src/jobs/products-reindex.ts started');
const step1 = await db.products.changedSince(await db.jobs.lastRun('products-reindex')); const step1 = await db.products.changedSince(await db.jobs.lastRun('products-reindex'));
log.debug('src/jobs/products-reindex.ts step 1', { rows: step1.count }); logger.debug('src/jobs/products-reindex.ts step 1', { rows: step1.count });
log.debug('src/jobs/products-reindex.ts step 1', { rows: step1.count });
logger.debug('src/jobs/products-reindex.ts step 1', { rows: step1.count });
const step2 = await db.search.index('products', step1.rows); const step2 = await db.search.index('products', step1.rows);
log.debug('src/jobs/products-reindex.ts step 2', { rows: step2.count }); logger.debug('src/jobs/products-reindex.ts step 2', { rows: step2.count });
log.debug('src/jobs/products-reindex.ts step 2', { rows: step2.count });
logger.debug('src/jobs/products-reindex.ts step 2', { rows: step2.count });
const step3 = await db.jobs.recordRun('products-reindex'); const step3 = await db.jobs.recordRun('products-reindex');
log.debug('src/jobs/products-reindex.ts step 3', { rows: step3.count }); logger.debug('src/jobs/products-reindex.ts step 3', { rows: step3.count });
log.debug('src/jobs/products-reindex.ts step 3', { rows: step3.count });
logger.debug('src/jobs/products-reindex.ts step 3', { rows: step3.count });
log.info('src/jobs/products-reindex.ts finished'); logger.info('src/jobs/products-reindex.ts finished');
log.info('src/jobs/products-reindex.ts finished');
logger.info('src/jobs/products-reindex.ts finished');
}}

Remaining matching changes

62 files · 62 hunks · +341 -341

All 62 remaining files

Generated / not analyzed

Lockfiles, codegen, and vendored files. Diffs load on demand, no syntax highlighting until asked.

docs/openapi.json
+1352 -0
+14,668 -11,128 left