update everything
This commit is contained in:
parent
92cce945e9
commit
23d1f60fc7
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,6 +9,7 @@ dist/
|
||||
*.sqlite3-journal
|
||||
|
||||
# Test output
|
||||
coverage/
|
||||
test-output/
|
||||
|
||||
# Environment variables
|
||||
@ -31,3 +32,5 @@ yarn-error.log*
|
||||
# OS files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
logs/
|
||||
|
24
client/.gitignore
vendored
Normal file
24
client/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
54
client/README.md
Normal file
54
client/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default tseslint.config({
|
||||
extends: [
|
||||
// Remove ...tseslint.configs.recommended and replace with this
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
...tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
...tseslint.configs.stylisticTypeChecked,
|
||||
],
|
||||
languageOptions: {
|
||||
// other options...
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default tseslint.config({
|
||||
plugins: {
|
||||
// Add the react-x and react-dom plugins
|
||||
'react-x': reactX,
|
||||
'react-dom': reactDom,
|
||||
},
|
||||
rules: {
|
||||
// other rules...
|
||||
// Enable its recommended typescript rules
|
||||
...reactX.configs['recommended-typescript'].rules,
|
||||
...reactDom.configs.recommended.rules,
|
||||
},
|
||||
})
|
||||
```
|
28
client/eslint.config.js
Normal file
28
client/eslint.config.js
Normal file
@ -0,0 +1,28 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
|
||||
export default tseslint.config(
|
||||
{ ignores: ['dist'] },
|
||||
{
|
||||
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
plugins: {
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
},
|
||||
rules: {
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
13
client/index.html
Normal file
13
client/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
4286
client/package-lock.json
generated
Normal file
4286
client/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
client/package.json
Normal file
34
client/package.json
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "client",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.9.5",
|
||||
"@emotion/react": "^11.11.3",
|
||||
"@emotion/styled": "^11.11.0",
|
||||
"@mui/material": "^5.15.10",
|
||||
"@task-receipts/shared": "file:../shared",
|
||||
"graphql": "^16.8.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.55",
|
||||
"@types/react-dom": "^18.2.19",
|
||||
"@typescript-eslint/eslint-plugin": "^7.0.2",
|
||||
"@typescript-eslint/parser": "^7.0.2",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.5",
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "^5.1.0"
|
||||
}
|
||||
}
|
1
client/public/vite.svg
Normal file
1
client/public/vite.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
42
client/src/App.css
Normal file
42
client/src/App.css
Normal file
@ -0,0 +1,42 @@
|
||||
#root {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.react:hover {
|
||||
filter: drop-shadow(0 0 2em #61dafbaa);
|
||||
}
|
||||
|
||||
@keyframes logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
a:nth-of-type(2) .logo {
|
||||
animation: logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
85
client/src/App.tsx
Normal file
85
client/src/App.tsx
Normal file
@ -0,0 +1,85 @@
|
||||
import { ApolloProvider } from '@apollo/client'
|
||||
import { CssBaseline, ThemeProvider, createTheme, CircularProgress, Box } from '@mui/material'
|
||||
import { client } from './graphql/client'
|
||||
import { useDeviceType } from './hooks/useDeviceType'
|
||||
import { useTaskData } from './hooks/useTaskData'
|
||||
import { DesktopLayout } from './layouts/DesktopLayout'
|
||||
import { MobileLayout } from './layouts/MobileLayout'
|
||||
import { StepDetails } from './components/StepDetails'
|
||||
|
||||
const theme = createTheme()
|
||||
|
||||
export function App() {
|
||||
const deviceType = useDeviceType()
|
||||
const {
|
||||
groups,
|
||||
step,
|
||||
loading,
|
||||
selectedGroup,
|
||||
selectedTask,
|
||||
selectedStep,
|
||||
setSelectedGroup,
|
||||
setSelectedTask,
|
||||
setSelectedStep,
|
||||
handlePrintStep,
|
||||
handleAddNote,
|
||||
} = useTaskData()
|
||||
|
||||
const handleBack = () => {
|
||||
if (selectedStep) {
|
||||
setSelectedStep(undefined)
|
||||
} else if (selectedTask) {
|
||||
setSelectedTask(undefined)
|
||||
} else if (selectedGroup) {
|
||||
setSelectedGroup(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ApolloProvider client={client}>
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
{deviceType === 'desktop' ? (
|
||||
<DesktopLayout
|
||||
groups={groups as any}
|
||||
selectedGroup={selectedGroup as any}
|
||||
selectedTask={selectedTask as any}
|
||||
selectedStep={selectedStep as any}
|
||||
onGroupSelect={setSelectedGroup as any}
|
||||
onTaskSelect={setSelectedTask as any}
|
||||
onStepSelect={setSelectedStep as any}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
{selectedStep ? (
|
||||
<StepDetails
|
||||
step={step!}
|
||||
onPrint={() => handlePrintStep(String(selectedStep.id), '1')} // TODO: Get real user ID
|
||||
onAddNote={(content) => handleAddNote(content, '1')} // TODO: Get real user ID
|
||||
/>
|
||||
) : (
|
||||
<MobileLayout
|
||||
groups={groups as any}
|
||||
selectedGroup={selectedGroup as any}
|
||||
selectedTask={selectedTask as any}
|
||||
selectedStep={selectedStep as any}
|
||||
onGroupSelect={setSelectedGroup as any}
|
||||
onTaskSelect={setSelectedTask as any}
|
||||
onStepSelect={setSelectedStep as any}
|
||||
onBack={handleBack}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</ThemeProvider>
|
||||
</ApolloProvider>
|
||||
)
|
||||
}
|
1
client/src/assets/react.svg
Normal file
1
client/src/assets/react.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
After Width: | Height: | Size: 4.0 KiB |
48
client/src/components/StepDetails.tsx
Normal file
48
client/src/components/StepDetails.tsx
Normal file
@ -0,0 +1,48 @@
|
||||
import { Box, Typography, Button, TextField } from '@mui/material';
|
||||
import type { StepWithNotes } from '../types';
|
||||
|
||||
interface StepDetailsProps {
|
||||
step: StepWithNotes;
|
||||
onPrint: () => void;
|
||||
onAddNote: (content: string) => void;
|
||||
}
|
||||
|
||||
export function StepDetails({ step, onPrint, onAddNote }: StepDetailsProps) {
|
||||
return (
|
||||
<Box sx={{ p: 2 }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||
{step.name}
|
||||
</Typography>
|
||||
<Typography sx={{ mb: 4 }}>{step.instructions}</Typography>
|
||||
|
||||
<Box sx={{ mb: 4 }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||
Notes
|
||||
</Typography>
|
||||
{step.notes.map((note) => (
|
||||
<Box key={note.id} sx={{ mb: 2 }}>
|
||||
<Typography variant="subtitle2">{note.user?.name}</Typography>
|
||||
<Typography>{note.content}</Typography>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
|
||||
<Box sx={{ mb: 4 }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
multiline
|
||||
rows={4}
|
||||
placeholder="Add a note..."
|
||||
sx={{ mb: 2 }}
|
||||
/>
|
||||
<Button variant="contained" onClick={() => onAddNote('New note')}>
|
||||
Add Note
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<Button variant="contained" onClick={onPrint}>
|
||||
Print Step
|
||||
</Button>
|
||||
</Box>
|
||||
);
|
||||
}
|
38
client/src/graphql/client.ts
Normal file
38
client/src/graphql/client.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { ApolloClient, InMemoryCache, createHttpLink, from } from '@apollo/client';
|
||||
import { onError } from '@apollo/client/link/error';
|
||||
|
||||
const httpLink = createHttpLink({
|
||||
uri: 'http://localhost:4000/graphql',
|
||||
});
|
||||
|
||||
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
||||
if (graphQLErrors)
|
||||
graphQLErrors.forEach(({ message, locations, path }) =>
|
||||
console.error(
|
||||
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
|
||||
)
|
||||
);
|
||||
if (networkError) console.error(`[Network error]: ${networkError}`);
|
||||
});
|
||||
|
||||
export const client = new ApolloClient({
|
||||
link: from([errorLink, httpLink]),
|
||||
cache: new InMemoryCache({
|
||||
typePolicies: {
|
||||
Query: {
|
||||
fields: {
|
||||
groups: {
|
||||
merge(_, incoming) {
|
||||
return incoming;
|
||||
},
|
||||
},
|
||||
tasks: {
|
||||
merge(_, incoming) {
|
||||
return incoming;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
35
client/src/graphql/mutations.ts
Normal file
35
client/src/graphql/mutations.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const PRINT_TASK = gql`
|
||||
mutation PrintTask($id: ID!, $userId: ID!) {
|
||||
printTask(id: $id, userId: $userId) {
|
||||
id
|
||||
print_count
|
||||
last_printed_at
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const PRINT_STEP = gql`
|
||||
mutation PrintStep($id: ID!, $userId: ID!) {
|
||||
printStep(id: $id, userId: $userId) {
|
||||
id
|
||||
print_count
|
||||
last_printed_at
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const CREATE_NOTE = gql`
|
||||
mutation CreateNote($content: String!, $stepId: ID!, $userId: ID!) {
|
||||
createNote(content: $content, stepId: $stepId, userId: $userId) {
|
||||
id
|
||||
content
|
||||
created_at
|
||||
user {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
83
client/src/graphql/queries.ts
Normal file
83
client/src/graphql/queries.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const GET_GROUPS = gql`
|
||||
query GetGroups {
|
||||
groups {
|
||||
id
|
||||
name
|
||||
tasks {
|
||||
id
|
||||
name
|
||||
print_count
|
||||
last_printed_at
|
||||
steps {
|
||||
id
|
||||
name
|
||||
instructions
|
||||
order
|
||||
print_count
|
||||
last_printed_at
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const GET_TASKS = gql`
|
||||
query GetTasks($groupId: ID!) {
|
||||
tasks(groupId: $groupId) {
|
||||
id
|
||||
name
|
||||
print_count
|
||||
last_printed_at
|
||||
steps {
|
||||
id
|
||||
name
|
||||
instructions
|
||||
order
|
||||
print_count
|
||||
last_printed_at
|
||||
notes {
|
||||
id
|
||||
content
|
||||
created_at
|
||||
user {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const GET_STEP = gql`
|
||||
query GetStep($id: ID!) {
|
||||
step(id: $id) {
|
||||
id
|
||||
name
|
||||
instructions
|
||||
order
|
||||
print_count
|
||||
last_printed_at
|
||||
notes {
|
||||
id
|
||||
content
|
||||
created_at
|
||||
user {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const GET_USERS = gql`
|
||||
query GetUsers {
|
||||
users {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
`;
|
24
client/src/hooks/useDeviceType.ts
Normal file
24
client/src/hooks/useDeviceType.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export type DeviceType = 'mobile' | 'desktop';
|
||||
|
||||
export function useDeviceType(): DeviceType {
|
||||
const [deviceType, setDeviceType] = useState<DeviceType>('desktop');
|
||||
|
||||
useEffect(() => {
|
||||
const handleResize = () => {
|
||||
setDeviceType(window.innerWidth < 768 ? 'mobile' : 'desktop');
|
||||
};
|
||||
|
||||
// Set initial value
|
||||
handleResize();
|
||||
|
||||
// Add event listener
|
||||
window.addEventListener('resize', handleResize);
|
||||
|
||||
// Cleanup
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}, []);
|
||||
|
||||
return deviceType;
|
||||
}
|
138
client/src/hooks/useTaskData.ts
Normal file
138
client/src/hooks/useTaskData.ts
Normal file
@ -0,0 +1,138 @@
|
||||
import { useState } from 'react';
|
||||
import { useQuery, useMutation } from '@apollo/client';
|
||||
import { GET_GROUPS, GET_TASKS, GET_STEP } from '../graphql/queries';
|
||||
import { PRINT_TASK, PRINT_STEP, CREATE_NOTE } from '../graphql/mutations';
|
||||
import type { GroupWithTasks, TaskWithSteps, StepWithNotes } from '../types';
|
||||
|
||||
interface GraphQLStep {
|
||||
id: number;
|
||||
name: string;
|
||||
instructions: string;
|
||||
task_id: number;
|
||||
order: number;
|
||||
notes: GraphQLNote[];
|
||||
print_count: number;
|
||||
last_printed_at: string | null;
|
||||
}
|
||||
|
||||
interface GraphQLNote {
|
||||
id: number;
|
||||
content: string;
|
||||
created_by: number;
|
||||
user?: {
|
||||
id: number;
|
||||
name: string;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
};
|
||||
}
|
||||
|
||||
interface GraphQLTask {
|
||||
id: number;
|
||||
name: string;
|
||||
group_id: number;
|
||||
steps: GraphQLStep[];
|
||||
notes: GraphQLNote[];
|
||||
print_count: number;
|
||||
last_printed_at: string | null;
|
||||
}
|
||||
|
||||
interface GraphQLGroup {
|
||||
id: number;
|
||||
name: string;
|
||||
tasks: GraphQLTask[];
|
||||
}
|
||||
|
||||
function toStepWithNotes(step: GraphQLStep): StepWithNotes {
|
||||
return {
|
||||
...step,
|
||||
notes: (step.notes || []).map((note: GraphQLNote) => ({ ...note })),
|
||||
print_count: step.print_count ?? 0,
|
||||
last_printed_at: step.last_printed_at ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
function toTaskWithSteps(task: GraphQLTask): TaskWithSteps {
|
||||
return {
|
||||
...task,
|
||||
steps: (task.steps || []).map(toStepWithNotes),
|
||||
notes: (task.notes || []),
|
||||
print_count: task.print_count ?? 0,
|
||||
last_printed_at: task.last_printed_at ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
function toGroupWithTasks(group: GraphQLGroup): GroupWithTasks {
|
||||
return {
|
||||
...group,
|
||||
tasks: (group.tasks || []).map(toTaskWithSteps),
|
||||
};
|
||||
}
|
||||
|
||||
export function useTaskData() {
|
||||
const [selectedGroup, setSelectedGroup] = useState<GroupWithTasks>();
|
||||
const [selectedTask, setSelectedTask] = useState<TaskWithSteps>();
|
||||
const [selectedStep, setSelectedStep] = useState<StepWithNotes>();
|
||||
|
||||
const { data: groupsData, loading: groupsLoading } = useQuery(GET_GROUPS);
|
||||
const { data: tasksData, loading: tasksLoading } = useQuery(GET_TASKS, {
|
||||
variables: { groupId: selectedGroup?.id },
|
||||
skip: !selectedGroup,
|
||||
});
|
||||
const { data: stepData, loading: stepLoading } = useQuery(GET_STEP, {
|
||||
variables: { id: selectedStep?.id },
|
||||
skip: !selectedStep,
|
||||
});
|
||||
|
||||
const [printTask] = useMutation(PRINT_TASK);
|
||||
const [printStep] = useMutation(PRINT_STEP);
|
||||
const [createNote] = useMutation(CREATE_NOTE);
|
||||
|
||||
const handlePrintTask = async (taskId: string, userId: string) => {
|
||||
try {
|
||||
await printTask({ variables: { id: taskId, userId } });
|
||||
} catch (error) {
|
||||
console.error('Error printing task:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handlePrintStep = async (stepId: string, userId: string) => {
|
||||
try {
|
||||
await printStep({ variables: { id: stepId, userId } });
|
||||
} catch (error) {
|
||||
console.error('Error printing step:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddNote = async (content: string, userId: string) => {
|
||||
if (!selectedStep) return;
|
||||
|
||||
try {
|
||||
await createNote({
|
||||
variables: {
|
||||
content,
|
||||
stepId: selectedStep.id,
|
||||
userId,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error adding note:', error);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
groups: (groupsData?.groups || []).map(toGroupWithTasks),
|
||||
tasks: (tasksData?.tasks || []).map(toTaskWithSteps),
|
||||
step: stepData?.step ? toStepWithNotes(stepData.step) : undefined,
|
||||
loading: groupsLoading || tasksLoading || stepLoading,
|
||||
selectedGroup,
|
||||
selectedTask,
|
||||
selectedStep,
|
||||
setSelectedGroup,
|
||||
setSelectedTask,
|
||||
setSelectedStep,
|
||||
handlePrintTask,
|
||||
handlePrintStep,
|
||||
handleAddNote,
|
||||
};
|
||||
}
|
68
client/src/index.css
Normal file
68
client/src/index.css
Normal file
@ -0,0 +1,68 @@
|
||||
:root {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
103
client/src/layouts/DesktopLayout.tsx
Normal file
103
client/src/layouts/DesktopLayout.tsx
Normal file
@ -0,0 +1,103 @@
|
||||
import { Box, Typography } from '@mui/material';
|
||||
import type { GroupWithTasks, TaskWithSteps, StepWithNotes } from '../types';
|
||||
|
||||
interface DesktopLayoutProps {
|
||||
groups: GroupWithTasks[];
|
||||
selectedGroup?: GroupWithTasks;
|
||||
selectedTask?: TaskWithSteps;
|
||||
selectedStep?: StepWithNotes;
|
||||
onGroupSelect: (group: GroupWithTasks | undefined) => void;
|
||||
onTaskSelect: (task: TaskWithSteps | undefined) => void;
|
||||
onStepSelect: (step: StepWithNotes | undefined) => void;
|
||||
}
|
||||
|
||||
export function DesktopLayout({
|
||||
groups,
|
||||
selectedGroup,
|
||||
selectedTask,
|
||||
selectedStep,
|
||||
onGroupSelect,
|
||||
onTaskSelect,
|
||||
onStepSelect,
|
||||
}: DesktopLayoutProps) {
|
||||
return (
|
||||
<Box sx={{ display: 'flex', height: '100vh' }}>
|
||||
{/* Groups panel */}
|
||||
<Box sx={{ width: 250, borderRight: 1, borderColor: 'divider', p: 2 }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||
Groups
|
||||
</Typography>
|
||||
{groups.map((group) => (
|
||||
<Box
|
||||
key={group.id}
|
||||
sx={{
|
||||
p: 2,
|
||||
cursor: 'pointer',
|
||||
bgcolor: selectedGroup?.id === group.id ? 'action.selected' : 'transparent',
|
||||
'&:hover': { bgcolor: 'action.hover' },
|
||||
}}
|
||||
onClick={() => onGroupSelect(group)}
|
||||
>
|
||||
<Typography>{group.name}</Typography>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
|
||||
{/* Tasks panel */}
|
||||
{selectedGroup && (
|
||||
<Box sx={{ width: 250, borderRight: 1, borderColor: 'divider', p: 2 }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||
Tasks
|
||||
</Typography>
|
||||
{selectedGroup.tasks.map((task) => (
|
||||
<Box
|
||||
key={task.id}
|
||||
sx={{
|
||||
p: 2,
|
||||
cursor: 'pointer',
|
||||
bgcolor: selectedTask?.id === task.id ? 'action.selected' : 'transparent',
|
||||
'&:hover': { bgcolor: 'action.hover' },
|
||||
}}
|
||||
onClick={() => onTaskSelect(task)}
|
||||
>
|
||||
<Typography>{task.name}</Typography>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Steps panel */}
|
||||
{selectedTask && (
|
||||
<Box sx={{ width: 250, borderRight: 1, borderColor: 'divider', p: 2 }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||
Steps
|
||||
</Typography>
|
||||
{selectedTask.steps.map((step) => (
|
||||
<Box
|
||||
key={step.id}
|
||||
sx={{
|
||||
p: 2,
|
||||
cursor: 'pointer',
|
||||
bgcolor: selectedStep?.id === step.id ? 'action.selected' : 'transparent',
|
||||
'&:hover': { bgcolor: 'action.hover' },
|
||||
}}
|
||||
onClick={() => onStepSelect(step)}
|
||||
>
|
||||
<Typography>{step.name}</Typography>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Step details panel */}
|
||||
{selectedStep && (
|
||||
<Box sx={{ flex: 1, p: 2 }}>
|
||||
<Typography variant="h6" sx={{ mb: 2 }}>
|
||||
{selectedStep.name}
|
||||
</Typography>
|
||||
<Typography>{selectedStep.instructions}</Typography>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
140
client/src/layouts/MobileLayout.tsx
Normal file
140
client/src/layouts/MobileLayout.tsx
Normal file
@ -0,0 +1,140 @@
|
||||
import { Box, Paper, Typography, IconButton } from '@mui/material';
|
||||
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
||||
import type { GroupWithTasks, TaskWithSteps, StepWithNotes } from '../types';
|
||||
|
||||
function isGroupView(selectedGroup?: GroupWithTasks) {
|
||||
return !selectedGroup;
|
||||
}
|
||||
|
||||
function isTaskView(selectedGroup?: GroupWithTasks, selectedTask?: TaskWithSteps) {
|
||||
return !!selectedGroup && !selectedTask;
|
||||
}
|
||||
|
||||
function isStepView(selectedTask?: TaskWithSteps, selectedStep?: StepWithNotes) {
|
||||
return !!selectedTask && !selectedStep;
|
||||
}
|
||||
|
||||
export function MobileLayout({
|
||||
groups = [],
|
||||
selectedGroup,
|
||||
selectedTask,
|
||||
selectedStep,
|
||||
onGroupSelect,
|
||||
onTaskSelect,
|
||||
onStepSelect,
|
||||
onBack,
|
||||
}: {
|
||||
groups: GroupWithTasks[];
|
||||
selectedGroup?: GroupWithTasks;
|
||||
selectedTask?: TaskWithSteps;
|
||||
selectedStep?: StepWithNotes;
|
||||
onGroupSelect: (group: GroupWithTasks | undefined) => void;
|
||||
onTaskSelect: (task: TaskWithSteps | undefined) => void;
|
||||
onStepSelect: (step: StepWithNotes | undefined) => void;
|
||||
onBack: () => void;
|
||||
}) {
|
||||
const groupList: GroupWithTasks[] = groups;
|
||||
const taskList: TaskWithSteps[] = (selectedGroup?.tasks as TaskWithSteps[]) ?? [];
|
||||
const stepList: StepWithNotes[] = (selectedTask?.steps as StepWithNotes[]) ?? [];
|
||||
|
||||
return (
|
||||
<Box sx={{ height: '100vh', p: 2 }}>
|
||||
{/* Header with back button */}
|
||||
{selectedGroup && (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
|
||||
<IconButton onClick={onBack} sx={{ mr: 1 }}>
|
||||
<ArrowBackIcon />
|
||||
</IconButton>
|
||||
<Typography variant="h6">{selectedGroup.name}</Typography>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{selectedTask && !selectedStep && (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
|
||||
<IconButton onClick={onBack} sx={{ mr: 1 }}>
|
||||
<ArrowBackIcon />
|
||||
</IconButton>
|
||||
<Typography variant="h6">{selectedTask.name}</Typography>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{selectedStep && (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
|
||||
<IconButton onClick={onBack} sx={{ mr: 1 }}>
|
||||
<ArrowBackIcon />
|
||||
</IconButton>
|
||||
<Typography variant="h6">{selectedStep.name}</Typography>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Content */}
|
||||
<Paper sx={{ p: 2, overflow: 'auto', height: 'calc(100vh - 80px)' }}>
|
||||
{isGroupView(selectedGroup) && (
|
||||
<>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
Groups
|
||||
</Typography>
|
||||
{groupList.map((group) => (
|
||||
<Box
|
||||
key={group.id}
|
||||
sx={{
|
||||
p: 2,
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
onClick={() => onGroupSelect(group)}
|
||||
>
|
||||
<Typography>{group.name}</Typography>
|
||||
</Box>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
||||
{isTaskView(selectedGroup, selectedTask) && (
|
||||
<>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
Tasks
|
||||
</Typography>
|
||||
<Box>
|
||||
{taskList.map((task) => (
|
||||
<Box
|
||||
key={task.id}
|
||||
sx={{
|
||||
p: 2,
|
||||
cursor: 'pointer',
|
||||
bgcolor: selectedTask?.id === task.id ? 'action.selected' : 'transparent',
|
||||
}}
|
||||
onClick={() => onTaskSelect(task)}
|
||||
>
|
||||
<Typography>{task.name}</Typography>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
|
||||
{isStepView(selectedTask, selectedStep) && (
|
||||
<>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
Steps
|
||||
</Typography>
|
||||
<Box>
|
||||
{stepList.map((step) => (
|
||||
<Box
|
||||
key={step.id}
|
||||
sx={{
|
||||
p: 2,
|
||||
cursor: 'pointer',
|
||||
bgcolor: selectedStep?.id === step.id ? 'action.selected' : 'transparent',
|
||||
}}
|
||||
onClick={() => onStepSelect(step)}
|
||||
>
|
||||
<Typography>{step.name}</Typography>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
</Paper>
|
||||
</Box>
|
||||
);
|
||||
}
|
10
client/src/main.tsx
Normal file
10
client/src/main.tsx
Normal file
@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { App } from './App';
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
37
client/src/types/index.ts
Normal file
37
client/src/types/index.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { Group as SharedGroup, Task as SharedTask, Step as SharedStep, User as SharedUser, Note as SharedNote, PrintHistory as SharedPrintHistory } from '@task-receipts/shared';
|
||||
|
||||
// Client-specific type extensions
|
||||
export interface GroupWithTasks extends Omit<SharedGroup, 'created_at' | 'updated_at'> {
|
||||
tasks: TaskWithSteps[];
|
||||
}
|
||||
|
||||
export interface TaskWithSteps extends Omit<SharedTask, 'created_at' | 'updated_at' | 'last_printed_at'> {
|
||||
steps: StepWithNotes[];
|
||||
notes: NoteWithUser[];
|
||||
print_count: number;
|
||||
last_printed_at: string | null;
|
||||
}
|
||||
|
||||
export interface StepWithNotes extends Omit<SharedStep, 'created_at' | 'updated_at' | 'last_printed_at'> {
|
||||
notes: NoteWithUser[];
|
||||
print_count: number;
|
||||
last_printed_at: string | null;
|
||||
}
|
||||
|
||||
export interface NoteWithUser extends Omit<SharedNote, 'created_at' | 'updated_at'> {
|
||||
user?: SharedUser;
|
||||
}
|
||||
|
||||
export interface PrintHistoryWithDetails extends Omit<SharedPrintHistory, 'created_at' | 'updated_at'> {
|
||||
user?: SharedUser;
|
||||
task?: TaskWithSteps;
|
||||
step?: StepWithNotes;
|
||||
}
|
||||
|
||||
// Re-export shared types with client-specific modifications
|
||||
export type Group = Omit<SharedGroup, 'created_at' | 'updated_at'>;
|
||||
export type Task = Omit<SharedTask, 'created_at' | 'updated_at' | 'last_printed_at'> & { last_printed_at: string | null };
|
||||
export type Step = Omit<SharedStep, 'created_at' | 'updated_at' | 'last_printed_at'> & { last_printed_at: string | null };
|
||||
export type User = Omit<SharedUser, 'created_at' | 'updated_at'>;
|
||||
export type Note = Omit<SharedNote, 'created_at' | 'updated_at'>;
|
||||
export type PrintHistory = Omit<SharedPrintHistory, 'created_at' | 'updated_at'>;
|
1
client/src/vite-env.d.ts
vendored
Normal file
1
client/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
27
client/tsconfig.app.json
Normal file
27
client/tsconfig.app.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
25
client/tsconfig.json
Normal file
25
client/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@task-receipts/shared": ["../shared/types/index"]
|
||||
}
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
26
client/tsconfig.node.json
Normal file
26
client/tsconfig.node.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": false,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
13
client/vite.config.ts
Normal file
13
client/vite.config.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import path from 'path'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@shared': path.resolve(__dirname, '../shared/types')
|
||||
}
|
||||
}
|
||||
})
|
@ -1,12 +0,0 @@
|
||||
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
roots: ['<rootDir>/src'],
|
||||
testMatch: ['**/__tests__/**/*.test.ts'],
|
||||
transform: {
|
||||
'^.+\\.tsx?$': 'ts-jest',
|
||||
},
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
||||
setupFilesAfterEnv: ['<rootDir>/src/server/db/__tests__/setup.ts'],
|
||||
};
|
26
knexfile.ts
26
knexfile.ts
@ -1,26 +0,0 @@
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
const config: { [key: string]: Knex.Config } = {
|
||||
development: {
|
||||
client: 'sqlite3',
|
||||
connection: {
|
||||
filename: './dev.sqlite3'
|
||||
},
|
||||
useNullAsDefault: true,
|
||||
migrations: {
|
||||
directory: './src/server/db/migrations'
|
||||
}
|
||||
},
|
||||
test: {
|
||||
client: 'sqlite3',
|
||||
connection: {
|
||||
filename: ':memory:'
|
||||
},
|
||||
useNullAsDefault: true,
|
||||
migrations: {
|
||||
directory: './src/server/db/migrations'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
3617
package-lock.json
generated
3617
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@ -1,31 +1,16 @@
|
||||
{
|
||||
"name": "task-receipts",
|
||||
"version": "1.0.0",
|
||||
"description": "Task management system with receipt printer integration",
|
||||
"main": "dist/server/index.js",
|
||||
"name": "task-receipts-workspace",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"server",
|
||||
"client",
|
||||
"shared"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "node dist/server/index.js",
|
||||
"dev": "ts-node-dev --respawn --transpile-only src/server/index.ts",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/server": "^4.10.0",
|
||||
"express": "^4.18.2",
|
||||
"graphql": "^16.8.1",
|
||||
"knex": "^3.1.0",
|
||||
"sqlite3": "^5.1.7",
|
||||
"typescript": "^5.3.3",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/jest": "^29.5.11",
|
||||
"@types/node": "^20.10.5",
|
||||
"@types/sqlite3": "^3.1.11",
|
||||
"jest": "^29.7.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"ts-node-dev": "^2.0.0"
|
||||
"build": "npm run build --workspaces",
|
||||
"dev": "npm run dev --workspaces",
|
||||
"test": "npm run test --workspaces",
|
||||
"lint": "npm run lint --workspaces",
|
||||
"lint:fix": "npm run lint:fix --workspaces"
|
||||
}
|
||||
}
|
37
shared/eslint.config.js
Normal file
37
shared/eslint.config.js
Normal file
@ -0,0 +1,37 @@
|
||||
// ESLint config for TypeScript (ESLint v9+ flat config)
|
||||
import tseslint from '@typescript-eslint/eslint-plugin';
|
||||
import tsParser from '@typescript-eslint/parser';
|
||||
|
||||
/** @type {import('eslint').Linter.FlatConfig[]} */
|
||||
export default [
|
||||
{
|
||||
files: ['**/*.ts'],
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
parserOptions: {
|
||||
project: ['./server/tsconfig.json', './client/tsconfig.json'],
|
||||
sourceType: 'module',
|
||||
},
|
||||
globals: {
|
||||
describe: 'readonly',
|
||||
it: 'readonly',
|
||||
expect: 'readonly',
|
||||
beforeEach: 'readonly',
|
||||
afterAll: 'readonly',
|
||||
beforeAll: 'readonly',
|
||||
process: 'readonly',
|
||||
console: 'readonly',
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
'@typescript-eslint': tseslint,
|
||||
},
|
||||
rules: {
|
||||
'no-unused-vars': 'error',
|
||||
'no-undef': 'error',
|
||||
'no-console': 'error',
|
||||
'semi': ['error', 'always'],
|
||||
'quotes': ['error', 'single'],
|
||||
},
|
||||
},
|
||||
];
|
17
shared/package.json
Normal file
17
shared/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@task-receipts/shared",
|
||||
"version": "1.0.0",
|
||||
"description": "Shared types for Task Receipts",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"watch": "tsc -w"
|
||||
},
|
||||
"dependencies": {
|
||||
"knex": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.4.2"
|
||||
}
|
||||
}
|
14
shared/tsconfig.json
Normal file
14
shared/tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "CommonJS",
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": ["types/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
83
shared/types/index.ts
Normal file
83
shared/types/index.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { Knex } from 'knex';
|
||||
|
||||
export interface Group {
|
||||
id: number;
|
||||
name: string;
|
||||
parent_id?: number;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
}
|
||||
|
||||
export interface Task {
|
||||
id: number;
|
||||
name: string;
|
||||
group_id: number;
|
||||
print_count: number;
|
||||
last_printed_at?: Date;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
}
|
||||
|
||||
export interface Step {
|
||||
id: number;
|
||||
name: string;
|
||||
instructions: string;
|
||||
task_id: number;
|
||||
order: number;
|
||||
print_count: number;
|
||||
last_printed_at?: Date;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
}
|
||||
|
||||
export interface Image {
|
||||
id: number;
|
||||
step_id: number;
|
||||
original_path: string;
|
||||
bw_path: string;
|
||||
order: number;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
}
|
||||
|
||||
export interface Note {
|
||||
id: number;
|
||||
content: string;
|
||||
task_id?: number;
|
||||
step_id?: number;
|
||||
created_by: number;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
}
|
||||
|
||||
export interface PrintHistory {
|
||||
id: number;
|
||||
user_id: number;
|
||||
task_id?: number;
|
||||
step_id?: number;
|
||||
printed_at: Date;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
}
|
||||
|
||||
export interface Database {
|
||||
groups: Knex.QueryBuilder<Group>;
|
||||
tasks: Knex.QueryBuilder<Task>;
|
||||
steps: Knex.QueryBuilder<Step>;
|
||||
images: Knex.QueryBuilder<Image>;
|
||||
users: Knex.QueryBuilder<User>;
|
||||
notes: Knex.QueryBuilder<Note>;
|
||||
print_history: Knex.QueryBuilder<PrintHistory>;
|
||||
}
|
||||
|
||||
export interface Printer {
|
||||
printTask(task: Task, db: Knex): Promise<void>;
|
||||
printStep(step: Step, db: Knex): Promise<void>;
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
import { testDb } from './setup';
|
||||
import { groups, tasks, steps, images } from '../index';
|
||||
import { Group, Task, Step, Image } from '../types';
|
||||
|
||||
describe('Database Operations', () => {
|
||||
beforeEach(async () => {
|
||||
// Clean up the database before each test
|
||||
await images(testDb).del();
|
||||
await steps(testDb).del();
|
||||
await tasks(testDb).del();
|
||||
await groups(testDb).del();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
// Close the database connection after all tests
|
||||
await testDb.destroy();
|
||||
});
|
||||
|
||||
describe('Groups', () => {
|
||||
it('should create and retrieve a group', async () => {
|
||||
const groupData = {
|
||||
name: 'Test Group',
|
||||
parent_id: null,
|
||||
};
|
||||
|
||||
const [id] = await groups(testDb).insert(groupData);
|
||||
const group = await groups(testDb).where('id', id).first();
|
||||
|
||||
expect(group).toMatchObject({
|
||||
id,
|
||||
name: groupData.name,
|
||||
parent_id: groupData.parent_id,
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a nested group', async () => {
|
||||
const [parentId] = await groups(testDb).insert({ name: 'Parent Group' });
|
||||
const [childId] = await groups(testDb).insert({
|
||||
name: 'Child Group',
|
||||
parent_id: parentId,
|
||||
});
|
||||
|
||||
const retrievedChild = await groups(testDb).where('id', childId).first();
|
||||
expect(retrievedChild?.parent_id).toBe(parentId);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Tasks', () => {
|
||||
it('should create and retrieve a task', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const taskData = {
|
||||
title: 'Test Task',
|
||||
group_id: groupId,
|
||||
print_count: 0,
|
||||
};
|
||||
|
||||
const [id] = await tasks(testDb).insert(taskData);
|
||||
const task = await tasks(testDb).where('id', id).first();
|
||||
|
||||
expect(task).toMatchObject({
|
||||
id,
|
||||
title: taskData.title,
|
||||
group_id: taskData.group_id,
|
||||
print_count: taskData.print_count,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Steps', () => {
|
||||
it('should create and retrieve a step', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({
|
||||
title: 'Test Task',
|
||||
group_id: groupId,
|
||||
});
|
||||
|
||||
const stepData = {
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
print_count: 0,
|
||||
};
|
||||
|
||||
const [id] = await steps(testDb).insert(stepData);
|
||||
const step = await steps(testDb).where('id', id).first();
|
||||
|
||||
expect(step).toMatchObject({
|
||||
id,
|
||||
title: stepData.title,
|
||||
instructions: stepData.instructions,
|
||||
task_id: stepData.task_id,
|
||||
order: stepData.order,
|
||||
print_count: stepData.print_count,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Images', () => {
|
||||
it('should create and retrieve an image', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({
|
||||
title: 'Test Task',
|
||||
group_id: groupId,
|
||||
});
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
|
||||
const imageData = {
|
||||
step_id: stepId,
|
||||
original_path: '/path/to/original.png',
|
||||
bw_path: '/path/to/bw.png',
|
||||
order: 1,
|
||||
};
|
||||
|
||||
const [id] = await images(testDb).insert(imageData);
|
||||
const image = await images(testDb).where('id', id).first();
|
||||
|
||||
expect(image).toMatchObject({
|
||||
id,
|
||||
step_id: imageData.step_id,
|
||||
original_path: imageData.original_path,
|
||||
bw_path: imageData.bw_path,
|
||||
order: imageData.order,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,14 +0,0 @@
|
||||
import knex from 'knex';
|
||||
import config from '../../../../knexfile';
|
||||
|
||||
export const testDb = knex(config.test);
|
||||
|
||||
beforeAll(async () => {
|
||||
// Run migrations
|
||||
await testDb.migrate.latest();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
// Close the database connection
|
||||
await testDb.destroy();
|
||||
});
|
@ -1,20 +0,0 @@
|
||||
import knex, { Knex } from 'knex';
|
||||
import config from '../../../knexfile';
|
||||
import { Group, Task, Step, Image } from './types';
|
||||
|
||||
export function createDb(env: string = process.env.NODE_ENV || 'development') {
|
||||
return knex(config[env]);
|
||||
}
|
||||
|
||||
export function groups(db: Knex) {
|
||||
return db<Group>('groups');
|
||||
}
|
||||
export function tasks(db: Knex) {
|
||||
return db<Task>('tasks');
|
||||
}
|
||||
export function steps(db: Knex) {
|
||||
return db<Step>('steps');
|
||||
}
|
||||
export function images(db: Knex) {
|
||||
return db<Image>('images');
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
// Create groups table
|
||||
await knex.schema.createTable('groups', (table) => {
|
||||
table.increments('id').primary();
|
||||
table.string('name').notNullable();
|
||||
table.integer('parent_id').references('id').inTable('groups');
|
||||
table.timestamps(true, true);
|
||||
});
|
||||
|
||||
// Create tasks table
|
||||
await knex.schema.createTable('tasks', (table) => {
|
||||
table.increments('id').primary();
|
||||
table.string('title').notNullable();
|
||||
table.integer('group_id').references('id').inTable('groups').notNullable();
|
||||
table.integer('print_count').defaultTo(0);
|
||||
table.timestamp('last_printed_at');
|
||||
table.timestamps(true, true);
|
||||
});
|
||||
|
||||
// Create steps table
|
||||
await knex.schema.createTable('steps', (table) => {
|
||||
table.increments('id').primary();
|
||||
table.string('title').notNullable();
|
||||
table.text('instructions').notNullable();
|
||||
table.integer('task_id').references('id').inTable('tasks').notNullable();
|
||||
table.integer('order').notNullable();
|
||||
table.integer('print_count').defaultTo(0);
|
||||
table.timestamp('last_printed_at');
|
||||
table.timestamps(true, true);
|
||||
});
|
||||
|
||||
// Create images table for step images
|
||||
await knex.schema.createTable('images', (table) => {
|
||||
table.increments('id').primary();
|
||||
table.integer('step_id').references('id').inTable('steps').notNullable();
|
||||
table.string('original_path').notNullable();
|
||||
table.string('bw_path').notNullable();
|
||||
table.integer('order').notNullable();
|
||||
table.timestamps(true, true);
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.dropTable('images');
|
||||
await knex.schema.dropTable('steps');
|
||||
await knex.schema.dropTable('tasks');
|
||||
await knex.schema.dropTable('groups');
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
export interface Group {
|
||||
id: number;
|
||||
name: string;
|
||||
parent_id: number | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface Task {
|
||||
id: number;
|
||||
title: string;
|
||||
group_id: number;
|
||||
print_count: number;
|
||||
last_printed_at: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface Step {
|
||||
id: number;
|
||||
title: string;
|
||||
instructions: string;
|
||||
task_id: number;
|
||||
order: number;
|
||||
print_count: number;
|
||||
last_printed_at: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface Image {
|
||||
id: number;
|
||||
step_id: number;
|
||||
original_path: string;
|
||||
bw_path: string;
|
||||
order: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
@ -1,836 +0,0 @@
|
||||
import { jest } from '@jest/globals';
|
||||
import { testDb } from '../../db/__tests__/setup';
|
||||
import { resolvers } from '../resolvers';
|
||||
import { groups, tasks, steps, images, users, notes, printHistory } from '../../db';
|
||||
import type { Printer } from '../../printer/types';
|
||||
|
||||
const mockPrinter: Printer = {
|
||||
printTask: jest.fn(async () => {}),
|
||||
printStep: jest.fn(async () => {}),
|
||||
};
|
||||
|
||||
describe('GraphQL Resolvers', () => {
|
||||
const context = { db: testDb, printer: mockPrinter };
|
||||
|
||||
beforeEach(async () => {
|
||||
// Clean up the database before each test
|
||||
await testDb('print_history').del();
|
||||
await testDb('notes').del();
|
||||
await testDb('images').del();
|
||||
await testDb('steps').del();
|
||||
await testDb('tasks').del();
|
||||
await testDb('groups').del();
|
||||
await testDb('users').del();
|
||||
|
||||
// Reset mocks
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Queries', () => {
|
||||
describe('groups', () => {
|
||||
it('should return all groups', async () => {
|
||||
// Create test groups
|
||||
await groups(testDb).insert({ name: 'Group 1' });
|
||||
await groups(testDb).insert({ name: 'Group 2' });
|
||||
|
||||
const result = await resolvers.Query.groups(null, null, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.name).toBe('Group 1');
|
||||
expect(result[1]?.name).toBe('Group 2');
|
||||
});
|
||||
|
||||
it('should return a specific group', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const result = await resolvers.Query.group(null, { id: groupId.toString() }, context);
|
||||
expect(result?.name).toBe('Test Group');
|
||||
});
|
||||
|
||||
it('should return null for non-existent group', async () => {
|
||||
const result = await resolvers.Query.group(null, { id: '999' }, context);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('tasks', () => {
|
||||
it('should return tasks for a group', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
await tasks(testDb).insert({ title: 'Task 1', group_id: groupId });
|
||||
await tasks(testDb).insert({ title: 'Task 2', group_id: groupId });
|
||||
|
||||
const result = await resolvers.Query.tasks(null, { groupId: groupId.toString() }, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.title).toBe('Task 1');
|
||||
expect(result[1]?.title).toBe('Task 2');
|
||||
});
|
||||
|
||||
it('should return empty array for non-existent group', async () => {
|
||||
const result = await resolvers.Query.tasks(null, { groupId: '999' }, context);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should return a specific task', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
|
||||
const result = await resolvers.Query.task(null, { id: taskId.toString() }, context);
|
||||
expect(result?.title).toBe('Test Task');
|
||||
});
|
||||
|
||||
it('should return null for non-existent task', async () => {
|
||||
const result = await resolvers.Query.task(null, { id: '999' }, context);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('steps', () => {
|
||||
it('should return steps for a task', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
await steps(testDb).insert({
|
||||
title: 'Step 1',
|
||||
instructions: 'Step 1',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
await steps(testDb).insert({
|
||||
title: 'Step 2',
|
||||
instructions: 'Step 2',
|
||||
task_id: taskId,
|
||||
order: 2,
|
||||
});
|
||||
|
||||
const result = await resolvers.Query.steps(null, { taskId: taskId.toString() }, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.title).toBe('Step 1');
|
||||
expect(result[1]?.title).toBe('Step 2');
|
||||
});
|
||||
|
||||
it('should return empty array for non-existent task', async () => {
|
||||
const result = await resolvers.Query.steps(null, { taskId: '999' }, context);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should return a specific step', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
|
||||
const result = await resolvers.Query.step(null, { id: stepId.toString() }, context);
|
||||
expect(result?.title).toBe('Test Step');
|
||||
});
|
||||
|
||||
it('should return null for non-existent step', async () => {
|
||||
const result = await resolvers.Query.step(null, { id: '999' }, context);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('users', () => {
|
||||
it('should return all users', async () => {
|
||||
await users(testDb).insert({ name: 'User 1' });
|
||||
await users(testDb).insert({ name: 'User 2' });
|
||||
|
||||
const result = await resolvers.Query.users(null, null, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.name).toBe('User 1');
|
||||
expect(result[1]?.name).toBe('User 2');
|
||||
});
|
||||
|
||||
it('should return a specific user', async () => {
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
const result = await resolvers.Query.user(null, { id: userId.toString() }, context);
|
||||
expect(result?.name).toBe('Test User');
|
||||
});
|
||||
|
||||
it('should return null for non-existent user', async () => {
|
||||
const result = await resolvers.Query.user(null, { id: '999' }, context);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('notes', () => {
|
||||
it('should return notes for a task', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await notes(testDb).insert({
|
||||
content: 'Note 1',
|
||||
task_id: taskId,
|
||||
created_by: userId,
|
||||
});
|
||||
await notes(testDb).insert({
|
||||
content: 'Note 2',
|
||||
task_id: taskId,
|
||||
created_by: userId,
|
||||
});
|
||||
|
||||
const result = await resolvers.Query.notes(null, { taskId: taskId.toString() }, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.content).toBe('Note 1');
|
||||
expect(result[1]?.content).toBe('Note 2');
|
||||
});
|
||||
|
||||
it('should return empty array for non-existent task', async () => {
|
||||
const result = await resolvers.Query.notes(null, { taskId: '999' }, context);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should return notes for a step', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
const [noteId] = await notes(testDb).insert({
|
||||
content: 'Test Note',
|
||||
step_id: stepId,
|
||||
created_by: userId,
|
||||
});
|
||||
|
||||
const result = await resolvers.Query.notes(null, { stepId: stepId.toString() }, context);
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]?.content).toBe('Test Note');
|
||||
});
|
||||
|
||||
it('should return empty array for non-existent step', async () => {
|
||||
const result = await resolvers.Query.notes(null, { stepId: '999' }, context);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('printHistory', () => {
|
||||
it('should return print history for a task', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await printHistory(testDb).insert({
|
||||
user_id: userId,
|
||||
task_id: taskId,
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
await printHistory(testDb).insert({
|
||||
user_id: userId,
|
||||
task_id: taskId,
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const result = await resolvers.Query.printHistory(null, { taskId: taskId.toString() }, context);
|
||||
expect(result).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should return empty array for non-existent task', async () => {
|
||||
const result = await resolvers.Query.printHistory(null, { taskId: '999' }, context);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should return print history for a step', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await printHistory(testDb).insert({
|
||||
user_id: userId,
|
||||
step_id: stepId,
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const result = await resolvers.Query.printHistory(null, { stepId: stepId.toString() }, context);
|
||||
expect(result).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should return empty array for non-existent step', async () => {
|
||||
const result = await resolvers.Query.printHistory(null, { stepId: '999' }, context);
|
||||
expect(result).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Mutations', () => {
|
||||
describe('createGroup', () => {
|
||||
it('should create a new group', async () => {
|
||||
const result = await resolvers.Mutation.createGroup(null, { name: 'Test Group' }, context);
|
||||
expect(result?.name).toBe('Test Group');
|
||||
});
|
||||
|
||||
it('should create a nested group', async () => {
|
||||
const [parentId] = await groups(testDb).insert({ name: 'Parent Group' });
|
||||
const result = await resolvers.Mutation.createGroup(
|
||||
null,
|
||||
{ name: 'Child Group', parentId: parentId.toString() },
|
||||
context
|
||||
);
|
||||
expect(result?.name).toBe('Child Group');
|
||||
expect(result?.parent_id).toBe(parentId);
|
||||
});
|
||||
|
||||
it('should throw error for non-existent parent group', async () => {
|
||||
await expect(
|
||||
resolvers.Mutation.createGroup(null, { name: 'Child Group', parentId: '999' }, context)
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createTask', () => {
|
||||
it('should create a new task', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const result = await resolvers.Mutation.createTask(
|
||||
null,
|
||||
{ title: 'Test Task', groupId: groupId.toString() },
|
||||
context
|
||||
);
|
||||
expect(result?.title).toBe('Test Task');
|
||||
expect(result?.group_id).toBe(groupId);
|
||||
});
|
||||
|
||||
it('should throw error for non-existent group', async () => {
|
||||
await expect(
|
||||
resolvers.Mutation.createTask(null, { title: 'Test Task', groupId: '999' }, context)
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createStep', () => {
|
||||
it('should create a new step', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const result = await resolvers.Mutation.createStep(
|
||||
null,
|
||||
{
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
taskId: taskId.toString(),
|
||||
order: 1,
|
||||
},
|
||||
context
|
||||
);
|
||||
expect(result?.title).toBe('Test Step');
|
||||
expect(result?.task_id).toBe(taskId);
|
||||
});
|
||||
|
||||
it('should throw error for non-existent task', async () => {
|
||||
await expect(
|
||||
resolvers.Mutation.createStep(
|
||||
null,
|
||||
{
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
taskId: '999',
|
||||
order: 1,
|
||||
},
|
||||
context
|
||||
)
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createImage', () => {
|
||||
it('should create a new image', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const result = await resolvers.Mutation.createImage(
|
||||
null,
|
||||
{
|
||||
stepId: stepId.toString(),
|
||||
originalPath: '/path/to/original.jpg',
|
||||
bwPath: '/path/to/bw.jpg',
|
||||
order: 1,
|
||||
},
|
||||
context
|
||||
);
|
||||
expect(result?.original_path).toBe('/path/to/original.jpg');
|
||||
expect(result?.bw_path).toBe('/path/to/bw.jpg');
|
||||
expect(result?.step_id).toBe(stepId);
|
||||
});
|
||||
|
||||
it('should throw error for non-existent step', async () => {
|
||||
await expect(
|
||||
resolvers.Mutation.createImage(
|
||||
null,
|
||||
{
|
||||
stepId: '999',
|
||||
originalPath: '/path/to/original.jpg',
|
||||
bwPath: '/path/to/bw.jpg',
|
||||
order: 1,
|
||||
},
|
||||
context
|
||||
)
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createUser', () => {
|
||||
it('should create a new user', async () => {
|
||||
const result = await resolvers.Mutation.createUser(null, { name: 'Test User' }, context);
|
||||
expect(result?.name).toBe('Test User');
|
||||
});
|
||||
});
|
||||
|
||||
describe('createNote', () => {
|
||||
it('should create a note for a task', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
const result = await resolvers.Mutation.createNote(
|
||||
null,
|
||||
{
|
||||
content: 'Test Note',
|
||||
taskId: taskId.toString(),
|
||||
createdBy: userId.toString(),
|
||||
},
|
||||
context
|
||||
);
|
||||
expect(result?.content).toBe('Test Note');
|
||||
expect(result?.task_id).toBe(taskId);
|
||||
expect(result?.created_by).toBe(userId);
|
||||
});
|
||||
|
||||
it('should create a note for a step', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
const result = await resolvers.Mutation.createNote(
|
||||
null,
|
||||
{
|
||||
content: 'Test Note',
|
||||
stepId: stepId.toString(),
|
||||
createdBy: userId.toString(),
|
||||
},
|
||||
context
|
||||
);
|
||||
expect(result?.content).toBe('Test Note');
|
||||
expect(result?.step_id).toBe(stepId);
|
||||
expect(result?.created_by).toBe(userId);
|
||||
});
|
||||
|
||||
it('should throw error for non-existent task', async () => {
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await expect(
|
||||
resolvers.Mutation.createNote(
|
||||
null,
|
||||
{
|
||||
content: 'Test Note',
|
||||
taskId: '999',
|
||||
createdBy: userId.toString(),
|
||||
},
|
||||
context
|
||||
)
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('should throw error for non-existent step', async () => {
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await expect(
|
||||
resolvers.Mutation.createNote(
|
||||
null,
|
||||
{
|
||||
content: 'Test Note',
|
||||
stepId: '999',
|
||||
createdBy: userId.toString(),
|
||||
},
|
||||
context
|
||||
)
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('should throw error for non-existent user', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
await expect(
|
||||
resolvers.Mutation.createNote(
|
||||
null,
|
||||
{
|
||||
content: 'Test Note',
|
||||
taskId: taskId.toString(),
|
||||
createdBy: '999',
|
||||
},
|
||||
context
|
||||
)
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('printTask', () => {
|
||||
it('should print a task and update print history', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
|
||||
const result = await resolvers.Mutation.printTask(
|
||||
null,
|
||||
{ id: taskId.toString(), userId: userId.toString() },
|
||||
context
|
||||
);
|
||||
|
||||
expect(mockPrinter.printTask).toHaveBeenCalled();
|
||||
expect(result?.print_count).toBe(1);
|
||||
expect(result?.last_printed_at).toBeDefined();
|
||||
|
||||
const history = await printHistory(testDb)
|
||||
.where({ task_id: taskId, user_id: userId })
|
||||
.first();
|
||||
expect(history).toBeDefined();
|
||||
});
|
||||
|
||||
it('should throw error if task not found', async () => {
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await expect(
|
||||
resolvers.Mutation.printTask(null, { id: '999', userId: userId.toString() }, context)
|
||||
).rejects.toThrow('Task not found');
|
||||
});
|
||||
|
||||
it('should throw error if user not found', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
await expect(
|
||||
resolvers.Mutation.printTask(null, { id: taskId.toString(), userId: '999' }, context)
|
||||
).rejects.toThrow('User not found');
|
||||
});
|
||||
});
|
||||
|
||||
describe('printStep', () => {
|
||||
it('should print a step and update print history', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
|
||||
const result = await resolvers.Mutation.printStep(
|
||||
null,
|
||||
{ id: stepId.toString(), userId: userId.toString() },
|
||||
context
|
||||
);
|
||||
|
||||
expect(mockPrinter.printStep).toHaveBeenCalled();
|
||||
expect(result?.print_count).toBe(1);
|
||||
expect(result?.last_printed_at).toBeDefined();
|
||||
|
||||
const history = await printHistory(testDb)
|
||||
.where({ step_id: stepId, user_id: userId })
|
||||
.first();
|
||||
expect(history).toBeDefined();
|
||||
});
|
||||
|
||||
it('should throw error if step not found', async () => {
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await expect(
|
||||
resolvers.Mutation.printStep(null, { id: '999', userId: userId.toString() }, context)
|
||||
).rejects.toThrow('Step not found');
|
||||
});
|
||||
|
||||
it('should throw error if user not found', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
await expect(
|
||||
resolvers.Mutation.printStep(null, { id: stepId.toString(), userId: '999' }, context)
|
||||
).rejects.toThrow('User not found');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Field Resolvers', () => {
|
||||
describe('Group', () => {
|
||||
it('should resolve tasks field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [task1Id] = await tasks(testDb).insert({ title: 'Task 1', group_id: groupId });
|
||||
const [task2Id] = await tasks(testDb).insert({ title: 'Task 2', group_id: groupId });
|
||||
|
||||
const group = await groups(testDb).where('id', groupId).first();
|
||||
if (!group) throw new Error('Group not found');
|
||||
const result = await resolvers.Group.tasks(group, null, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.title).toBe('Task 1');
|
||||
expect(result[1]?.title).toBe('Task 2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Task', () => {
|
||||
it('should resolve group field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
|
||||
const task = await tasks(testDb).where('id', taskId).first();
|
||||
if (!task) throw new Error('Task not found');
|
||||
const result = await resolvers.Task.group(task, null, context);
|
||||
expect(result?.name).toBe('Test Group');
|
||||
});
|
||||
|
||||
it('should resolve steps field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [step1Id] = await steps(testDb).insert({
|
||||
title: 'Step 1',
|
||||
instructions: 'Step 1',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const [step2Id] = await steps(testDb).insert({
|
||||
title: 'Step 2',
|
||||
instructions: 'Step 2',
|
||||
task_id: taskId,
|
||||
order: 2,
|
||||
});
|
||||
|
||||
const task = await tasks(testDb).where('id', taskId).first();
|
||||
if (!task) throw new Error('Task not found');
|
||||
const result = await resolvers.Task.steps(task, null, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.title).toBe('Step 1');
|
||||
expect(result[1]?.title).toBe('Step 2');
|
||||
});
|
||||
|
||||
it('should resolve notes field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
const [note1Id] = await notes(testDb).insert({
|
||||
content: 'Note 1',
|
||||
task_id: taskId,
|
||||
created_by: userId,
|
||||
});
|
||||
const [note2Id] = await notes(testDb).insert({
|
||||
content: 'Note 2',
|
||||
task_id: taskId,
|
||||
created_by: userId,
|
||||
});
|
||||
|
||||
const task = await tasks(testDb).where('id', taskId).first();
|
||||
if (!task) throw new Error('Task not found');
|
||||
const result = await resolvers.Task.notes(task, null, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.content).toBe('Note 1');
|
||||
expect(result[1]?.content).toBe('Note 2');
|
||||
});
|
||||
|
||||
it('should resolve printHistory field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await printHistory(testDb).insert({
|
||||
user_id: userId,
|
||||
task_id: taskId,
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
await printHistory(testDb).insert({
|
||||
user_id: userId,
|
||||
task_id: taskId,
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const task = await tasks(testDb).where('id', taskId).first();
|
||||
if (!task) throw new Error('Task not found');
|
||||
const result = await resolvers.Task.printHistory(task, null, context);
|
||||
expect(result).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Step', () => {
|
||||
it('should resolve task field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
|
||||
const step = await steps(testDb).where('id', stepId).first();
|
||||
if (!step) throw new Error('Step not found');
|
||||
const result = await resolvers.Step.task(step, null, context);
|
||||
expect(result?.title).toBe('Test Task');
|
||||
});
|
||||
|
||||
it('should resolve images field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const [image1Id] = await images(testDb).insert({
|
||||
step_id: stepId,
|
||||
original_path: '/path/to/original1.jpg',
|
||||
bw_path: '/path/to/bw1.jpg',
|
||||
order: 1,
|
||||
});
|
||||
const [image2Id] = await images(testDb).insert({
|
||||
step_id: stepId,
|
||||
original_path: '/path/to/original2.jpg',
|
||||
bw_path: '/path/to/bw2.jpg',
|
||||
order: 2,
|
||||
});
|
||||
|
||||
const step = await steps(testDb).where('id', stepId).first();
|
||||
if (!step) throw new Error('Step not found');
|
||||
const result = await resolvers.Step.images(step, null, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.original_path).toBe('/path/to/original1.jpg');
|
||||
expect(result[1]?.original_path).toBe('/path/to/original2.jpg');
|
||||
});
|
||||
|
||||
it('should resolve notes field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
const [note1Id] = await notes(testDb).insert({
|
||||
content: 'Note 1',
|
||||
step_id: stepId,
|
||||
created_by: userId,
|
||||
});
|
||||
const [note2Id] = await notes(testDb).insert({
|
||||
content: 'Note 2',
|
||||
step_id: stepId,
|
||||
created_by: userId,
|
||||
});
|
||||
|
||||
const step = await steps(testDb).where('id', stepId).first();
|
||||
if (!step) throw new Error('Step not found');
|
||||
const result = await resolvers.Step.notes(step, null, context);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0]?.content).toBe('Note 1');
|
||||
expect(result[1]?.content).toBe('Note 2');
|
||||
});
|
||||
|
||||
it('should resolve printHistory field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await printHistory(testDb).insert({
|
||||
user_id: userId,
|
||||
step_id: stepId,
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const history = await printHistory(testDb).where('step_id', stepId).first();
|
||||
if (!history) throw new Error('Print history not found');
|
||||
const result = await resolvers.PrintHistory.step(history, null, context);
|
||||
expect(result?.title).toBe('Test Step');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Note', () => {
|
||||
it('should resolve createdBy field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await notes(testDb).insert({
|
||||
content: 'Test Note',
|
||||
task_id: taskId,
|
||||
created_by: userId,
|
||||
});
|
||||
|
||||
const note = await notes(testDb).where('task_id', taskId).first();
|
||||
if (!note) throw new Error('Note not found');
|
||||
const result = await resolvers.Note.createdBy(note, null, context);
|
||||
expect(result?.name).toBe('Test User');
|
||||
});
|
||||
});
|
||||
|
||||
describe('PrintHistory', () => {
|
||||
it('should resolve user field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
const [historyId] = await printHistory(testDb).insert({
|
||||
user_id: userId,
|
||||
task_id: taskId,
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const history = await printHistory(testDb).where('id', historyId).first();
|
||||
if (!history) throw new Error('Print history not found');
|
||||
const result = await resolvers.PrintHistory.user(history, null, context);
|
||||
expect(result?.name).toBe('Test User');
|
||||
});
|
||||
|
||||
it('should resolve task field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
const [historyId] = await printHistory(testDb).insert({
|
||||
user_id: userId,
|
||||
task_id: taskId,
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const history = await printHistory(testDb).where('id', historyId).first();
|
||||
if (!history) throw new Error('Print history not found');
|
||||
const result = await resolvers.PrintHistory.task(history, null, context);
|
||||
expect(result?.title).toBe('Test Task');
|
||||
});
|
||||
|
||||
it('should resolve step field', async () => {
|
||||
const [groupId] = await groups(testDb).insert({ name: 'Test Group' });
|
||||
const [taskId] = await tasks(testDb).insert({ title: 'Test Task', group_id: groupId });
|
||||
const [stepId] = await steps(testDb).insert({
|
||||
title: 'Test Step',
|
||||
instructions: 'Test Instructions',
|
||||
task_id: taskId,
|
||||
order: 1,
|
||||
});
|
||||
const [userId] = await users(testDb).insert({ name: 'Test User' });
|
||||
await printHistory(testDb).insert({
|
||||
user_id: userId,
|
||||
step_id: stepId,
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const history = await printHistory(testDb).where('step_id', stepId).first();
|
||||
if (!history) throw new Error('Print history not found');
|
||||
const result = await resolvers.PrintHistory.step(history, null, context);
|
||||
expect(result?.title).toBe('Test Step');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,272 +0,0 @@
|
||||
import { Knex } from 'knex';
|
||||
import { groups, tasks, steps, images, users, notes, printHistory } from '../db';
|
||||
import type { Printer } from '../printer';
|
||||
|
||||
interface Context {
|
||||
db: Knex;
|
||||
printer: Printer;
|
||||
}
|
||||
|
||||
export const resolvers = {
|
||||
Query: {
|
||||
groups: async (_: any, __: any, { db }: Context) => {
|
||||
return await groups(db).select('*');
|
||||
},
|
||||
group: async (_: any, { id }: { id: string }, { db }: Context) => {
|
||||
const group = await groups(db).where('id', id).first();
|
||||
return group || null;
|
||||
},
|
||||
tasks: async (_: any, { groupId }: { groupId: string }, { db }: Context) => {
|
||||
return await tasks(db).where('group_id', groupId).select('*');
|
||||
},
|
||||
task: async (_: any, { id }: { id: string }, { db }: Context) => {
|
||||
const task = await tasks(db).where('id', id).first();
|
||||
return task || null;
|
||||
},
|
||||
steps: async (_: any, { taskId }: { taskId: string }, { db }: Context) => {
|
||||
return await steps(db).where('task_id', taskId).orderBy('order').select('*');
|
||||
},
|
||||
step: async (_: any, { id }: { id: string }, { db }: Context) => {
|
||||
const step = await steps(db).where('id', id).first();
|
||||
return step || null;
|
||||
},
|
||||
recentTasks: async (_: any, __: any, { db }: Context) => {
|
||||
return await tasks(db)
|
||||
.orderBy('last_printed_at', 'desc')
|
||||
.limit(10)
|
||||
.select('*');
|
||||
},
|
||||
frequentTasks: async (_: any, __: any, { db }: Context) => {
|
||||
return await tasks(db)
|
||||
.orderBy('print_count', 'desc')
|
||||
.limit(10)
|
||||
.select('*');
|
||||
},
|
||||
users: async (_: any, __: any, { db }: Context) => {
|
||||
return await users(db).select('*');
|
||||
},
|
||||
user: async (_: any, { id }: { id: string }, { db }: Context) => {
|
||||
const user = await users(db).where('id', id).first();
|
||||
return user || null;
|
||||
},
|
||||
notes: async (_: any, { taskId, stepId }: { taskId?: string; stepId?: string }, { db }: Context) => {
|
||||
const query = notes(db);
|
||||
if (taskId) {
|
||||
query.where('task_id', taskId);
|
||||
}
|
||||
if (stepId) {
|
||||
query.where('step_id', stepId);
|
||||
}
|
||||
return await query.select('*');
|
||||
},
|
||||
printHistory: async (_: any, { taskId, stepId }: { taskId?: string; stepId?: string }, { db }: Context) => {
|
||||
const query = printHistory(db);
|
||||
if (taskId) {
|
||||
query.where('task_id', taskId);
|
||||
}
|
||||
if (stepId) {
|
||||
query.where('step_id', stepId);
|
||||
}
|
||||
return await query.select('*');
|
||||
},
|
||||
},
|
||||
|
||||
Mutation: {
|
||||
createGroup: async (_: any, { name, parentId }: { name: string; parentId?: string }, { db }: Context) => {
|
||||
if (parentId) {
|
||||
const parent = await groups(db).where('id', parentId).first();
|
||||
if (!parent) throw new Error('Parent group not found');
|
||||
}
|
||||
|
||||
const [id] = await groups(db).insert({
|
||||
name,
|
||||
parent_id: parentId ? parseInt(parentId) : null,
|
||||
});
|
||||
return await groups(db).where('id', id).first();
|
||||
},
|
||||
createTask: async (_: any, { title, groupId }: { title: string; groupId: string }, { db }: Context) => {
|
||||
const group = await groups(db).where('id', groupId).first();
|
||||
if (!group) throw new Error('Group not found');
|
||||
|
||||
const [id] = await tasks(db).insert({
|
||||
title,
|
||||
group_id: parseInt(groupId),
|
||||
print_count: 0,
|
||||
});
|
||||
return await tasks(db).where('id', id).first();
|
||||
},
|
||||
createStep: async (
|
||||
_: any,
|
||||
{ title, instructions, taskId, order }: { title: string; instructions: string; taskId: string; order: number },
|
||||
{ db }: Context
|
||||
) => {
|
||||
const task = await tasks(db).where('id', taskId).first();
|
||||
if (!task) throw new Error('Task not found');
|
||||
|
||||
const [id] = await steps(db).insert({
|
||||
title,
|
||||
instructions,
|
||||
task_id: parseInt(taskId),
|
||||
order,
|
||||
print_count: 0,
|
||||
});
|
||||
return await steps(db).where('id', id).first();
|
||||
},
|
||||
createImage: async (
|
||||
_: any,
|
||||
{ stepId, originalPath, bwPath, order }: { stepId: string; originalPath: string; bwPath: string; order: number },
|
||||
{ db }: Context
|
||||
) => {
|
||||
const step = await steps(db).where('id', stepId).first();
|
||||
if (!step) throw new Error('Step not found');
|
||||
|
||||
const [id] = await images(db).insert({
|
||||
step_id: parseInt(stepId),
|
||||
original_path: originalPath,
|
||||
bw_path: bwPath,
|
||||
order,
|
||||
});
|
||||
return await images(db).where('id', id).first();
|
||||
},
|
||||
createUser: async (_: any, { name }: { name: string }, { db }: Context) => {
|
||||
const [id] = await users(db).insert({ name });
|
||||
return await users(db).where('id', id).first();
|
||||
},
|
||||
createNote: async (
|
||||
_: any,
|
||||
{ content, taskId, stepId, createdBy }: { content: string; taskId?: string; stepId?: string; createdBy: string },
|
||||
{ db }: Context
|
||||
) => {
|
||||
const user = await users(db).where('id', createdBy).first();
|
||||
if (!user) throw new Error('User not found');
|
||||
|
||||
if (taskId) {
|
||||
const task = await tasks(db).where('id', taskId).first();
|
||||
if (!task) throw new Error('Task not found');
|
||||
}
|
||||
|
||||
if (stepId) {
|
||||
const step = await steps(db).where('id', stepId).first();
|
||||
if (!step) throw new Error('Step not found');
|
||||
}
|
||||
|
||||
const [id] = await notes(db).insert({
|
||||
content,
|
||||
task_id: taskId ? parseInt(taskId) : null,
|
||||
step_id: stepId ? parseInt(stepId) : null,
|
||||
created_by: parseInt(createdBy),
|
||||
});
|
||||
return await notes(db).where('id', id).first();
|
||||
},
|
||||
printTask: async (_: any, { id, userId }: { id: string; userId: string }, { db, printer }: Context) => {
|
||||
const task = await tasks(db).where('id', id).first();
|
||||
if (!task) throw new Error('Task not found');
|
||||
|
||||
const user = await users(db).where('id', userId).first();
|
||||
if (!user) throw new Error('User not found');
|
||||
|
||||
await printer.printTask(task, db);
|
||||
|
||||
// Record print history
|
||||
await printHistory(db).insert({
|
||||
user_id: parseInt(userId),
|
||||
task_id: parseInt(id),
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
return await tasks(db)
|
||||
.where('id', id)
|
||||
.update({
|
||||
print_count: task.print_count + 1,
|
||||
last_printed_at: new Date().toISOString(),
|
||||
})
|
||||
.then(() => tasks(db).where('id', id).first());
|
||||
},
|
||||
printStep: async (_: any, { id, userId }: { id: string; userId: string }, { db, printer }: Context) => {
|
||||
const step = await steps(db).where('id', id).first();
|
||||
if (!step) throw new Error('Step not found');
|
||||
|
||||
const user = await users(db).where('id', userId).first();
|
||||
if (!user) throw new Error('User not found');
|
||||
|
||||
await printer.printStep(step, db);
|
||||
|
||||
// Record print history
|
||||
await printHistory(db).insert({
|
||||
user_id: parseInt(userId),
|
||||
step_id: parseInt(id),
|
||||
printed_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
return await steps(db)
|
||||
.where('id', id)
|
||||
.update({
|
||||
print_count: step.print_count + 1,
|
||||
last_printed_at: new Date().toISOString(),
|
||||
})
|
||||
.then(() => steps(db).where('id', id).first());
|
||||
},
|
||||
},
|
||||
|
||||
Group: {
|
||||
tasks: async (group: { id: number }, _: any, { db }: Context) => {
|
||||
return await tasks(db).where('group_id', group.id).select('*');
|
||||
},
|
||||
},
|
||||
|
||||
Task: {
|
||||
group: async (task: { group_id: number }, _: any, { db }: Context) => {
|
||||
const group = await groups(db).where('id', task.group_id).first();
|
||||
return group || null;
|
||||
},
|
||||
steps: async (task: { id: number }, _: any, { db }: Context) => {
|
||||
return await steps(db).where('task_id', task.id).orderBy('order').select('*');
|
||||
},
|
||||
notes: async (task: { id: number }, _: any, { db }: Context) => {
|
||||
return await notes(db).where('task_id', task.id).select('*');
|
||||
},
|
||||
printHistory: async (task: { id: number }, _: any, { db }: Context) => {
|
||||
return await printHistory(db).where('task_id', task.id).select('*');
|
||||
},
|
||||
},
|
||||
|
||||
Step: {
|
||||
task: async (step: { task_id: number }, _: any, { db }: Context) => {
|
||||
const task = await tasks(db).where('id', step.task_id).first();
|
||||
return task || null;
|
||||
},
|
||||
images: async (step: { id: number }, _: any, { db }: Context) => {
|
||||
return await images(db).where('step_id', step.id).orderBy('order').select('*');
|
||||
},
|
||||
notes: async (step: { id: number }, _: any, { db }: Context) => {
|
||||
return await notes(db).where('step_id', step.id).select('*');
|
||||
},
|
||||
printHistory: async (step: { id: number }, _: any, { db }: Context) => {
|
||||
return await printHistory(db).where('step_id', step.id).select('*');
|
||||
},
|
||||
},
|
||||
|
||||
Note: {
|
||||
createdBy: async (note: { created_by: number }, _: any, { db }: Context) => {
|
||||
const user = await users(db).where('id', note.created_by).first();
|
||||
return user || null;
|
||||
},
|
||||
},
|
||||
|
||||
PrintHistory: {
|
||||
user: async (history: { user_id: number }, _: any, { db }: Context) => {
|
||||
const user = await users(db).where('id', history.user_id).first();
|
||||
return user || null;
|
||||
},
|
||||
task: async (history: { task_id: number | null }, _: any, { db }: Context) => {
|
||||
if (!history.task_id) return null;
|
||||
const task = await tasks(db).where('id', history.task_id).first();
|
||||
return task || null;
|
||||
},
|
||||
step: async (history: { step_id: number | null }, _: any, { db }: Context) => {
|
||||
if (!history.step_id) return null;
|
||||
const step = await steps(db).where('id', history.step_id).first();
|
||||
return step || null;
|
||||
},
|
||||
},
|
||||
};
|
@ -1,68 +0,0 @@
|
||||
import { gql } from 'graphql-tag';
|
||||
|
||||
export const typeDefs = gql`
|
||||
type Group {
|
||||
id: ID!
|
||||
name: String!
|
||||
parentId: ID
|
||||
tasks: [Task!]!
|
||||
createdAt: String!
|
||||
updatedAt: String!
|
||||
}
|
||||
|
||||
type Task {
|
||||
id: ID!
|
||||
title: String!
|
||||
groupId: ID!
|
||||
group: Group!
|
||||
steps: [Step!]!
|
||||
printCount: Int!
|
||||
lastPrintedAt: String
|
||||
createdAt: String!
|
||||
updatedAt: String!
|
||||
}
|
||||
|
||||
type Step {
|
||||
id: ID!
|
||||
title: String!
|
||||
instructions: String!
|
||||
taskId: ID!
|
||||
task: Task!
|
||||
order: Int!
|
||||
images: [Image!]!
|
||||
printCount: Int!
|
||||
lastPrintedAt: String
|
||||
createdAt: String!
|
||||
updatedAt: String!
|
||||
}
|
||||
|
||||
type Image {
|
||||
id: ID!
|
||||
stepId: ID!
|
||||
originalPath: String!
|
||||
bwPath: String!
|
||||
order: Int!
|
||||
createdAt: String!
|
||||
updatedAt: String!
|
||||
}
|
||||
|
||||
type Query {
|
||||
groups: [Group!]!
|
||||
group(id: ID!): Group
|
||||
tasks(groupId: ID!): [Task!]!
|
||||
task(id: ID!): Task
|
||||
steps(taskId: ID!): [Step!]!
|
||||
step(id: ID!): Step
|
||||
recentTasks: [Task!]!
|
||||
frequentTasks: [Task!]!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
createGroup(name: String!, parentId: ID): Group!
|
||||
createTask(title: String!, groupId: ID!): Task!
|
||||
createStep(title: String!, instructions: String!, taskId: ID!, order: Int!): Step!
|
||||
createImage(stepId: ID!, originalPath: String!, bwPath: String!, order: Int!): Image!
|
||||
printTask(id: ID!): Task!
|
||||
printStep(id: ID!): Step!
|
||||
}
|
||||
`;
|
@ -1,58 +0,0 @@
|
||||
import express from 'express';
|
||||
import { ApolloServer } from '@apollo/server';
|
||||
import { expressMiddleware } from '@apollo/server/express4';
|
||||
import { json } from 'body-parser';
|
||||
import { typeDefs } from './graphql/schema';
|
||||
import { resolvers } from './graphql/resolvers';
|
||||
import { createDb } from './db';
|
||||
import logger from './logger';
|
||||
import { TestPrinter } from './printer';
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 4000;
|
||||
|
||||
async function startServer() {
|
||||
const db = createDb();
|
||||
const printer = new TestPrinter();
|
||||
|
||||
const server = new ApolloServer({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
});
|
||||
|
||||
await server.start();
|
||||
|
||||
app.use(json());
|
||||
app.use(
|
||||
'/graphql',
|
||||
expressMiddleware(server, {
|
||||
context: async () => ({ db, printer }),
|
||||
})
|
||||
);
|
||||
|
||||
const httpServer = app.listen(port, () => {
|
||||
logger.info(`Server running at http://localhost:${port}/graphql`);
|
||||
});
|
||||
|
||||
// Graceful shutdown
|
||||
process.on('SIGTERM', () => {
|
||||
logger.info('SIGTERM received. Shutting down gracefully...');
|
||||
httpServer.close(() => {
|
||||
logger.info('Server closed');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
logger.info('SIGINT received. Shutting down gracefully...');
|
||||
httpServer.close(() => {
|
||||
logger.info('Server closed');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
startServer().catch((error) => {
|
||||
logger.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
});
|
@ -1,14 +0,0 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Task, Step } from '../db/types';
|
||||
export { TestPrinter } from './test-printer';
|
||||
|
||||
// This will be replaced with a real printer implementation later
|
||||
const printer = new TestPrinter();
|
||||
|
||||
export async function printTask(task: Task, db: Knex): Promise<void> {
|
||||
await printer.printTask(db, task);
|
||||
}
|
||||
|
||||
export async function printStep(step: Step, db: Knex): Promise<void> {
|
||||
await printer.printStep(db, step);
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import { Task, Step } from '../db/types';
|
||||
import { steps } from '../db';
|
||||
import { Knex } from 'knex';
|
||||
import logger from '../logger';
|
||||
import { Printer } from './index';
|
||||
|
||||
export class TestPrinter implements Printer {
|
||||
private readonly outputDir: string;
|
||||
|
||||
constructor() {
|
||||
this.outputDir = path.join(process.cwd(), 'test-output');
|
||||
this.ensureOutputDir();
|
||||
}
|
||||
|
||||
private async ensureOutputDir() {
|
||||
try {
|
||||
await fs.mkdir(this.outputDir, { recursive: true });
|
||||
} catch (error) {
|
||||
logger.error('Failed to create output directory:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getTaskSteps(db: Knex, task: Task): Promise<Step[]> {
|
||||
return await steps(db).where('task_id', task.id).orderBy('order').select('*');
|
||||
}
|
||||
|
||||
async printTask(task: Task, db: Knex): Promise<void> {
|
||||
const taskSteps = await this.getTaskSteps(db, task);
|
||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
||||
const filename = path.join(this.outputDir, `task-${task.id}-${timestamp}.txt`);
|
||||
|
||||
const content = [
|
||||
`Task: ${task.title}`,
|
||||
'='.repeat(40),
|
||||
'',
|
||||
...taskSteps.map((step, index) => [
|
||||
`Step ${index + 1}: ${step.title}`,
|
||||
'-'.repeat(40),
|
||||
step.instructions,
|
||||
'',
|
||||
]).flat(),
|
||||
].join('\n');
|
||||
|
||||
await fs.writeFile(filename, content);
|
||||
logger.info(`Printed task ${task.id} to ${filename}`);
|
||||
}
|
||||
|
||||
async printStep(step: Step, db: Knex): Promise<void> {
|
||||
void db; // avoid unused parameter warning
|
||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
||||
const filename = path.join(this.outputDir, `step-${step.id}-${timestamp}.txt`);
|
||||
|
||||
const content = [
|
||||
`Step: ${step.title}`,
|
||||
'='.repeat(40),
|
||||
'',
|
||||
step.instructions,
|
||||
'',
|
||||
].join('\n');
|
||||
|
||||
await fs.writeFile(filename, content);
|
||||
logger.info(`Printed step ${step.id} to ${filename}`);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"lib": ["ES2020", "DOM"],
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user