Compare commits
21 commits
learner-de
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e02da48f7c | ||
|
|
ae32cfebe4 | ||
|
|
ea442d7815 | ||
|
|
ac768a3df4 | ||
|
|
9e4fcbf04e | ||
|
|
853c141910 | ||
|
|
b0b665f588 | ||
|
|
0205aab461 | ||
|
|
000f9eea5c | ||
|
|
522a0eec8a | ||
|
|
b6c1aebe30 | ||
|
|
1c63e79db1 | ||
|
|
9bb941b45e | ||
|
|
ebcae0b3e7 | ||
|
|
a3b2e55443 | ||
|
|
9bc24fbe8a | ||
|
|
734d922393 | ||
|
|
03f16cf2fd | ||
|
|
c8ef372d4e | ||
|
|
dccf808c2b | ||
|
|
ad11c6b7c5 |
277 changed files with 13575 additions and 5709 deletions
22
Backend/jest.config.js
Normal file
22
Backend/jest.config.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/** @type {import('jest').Config} */
|
||||
const config = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
roots: ['<rootDir>/tests'],
|
||||
testMatch: ['**/*.test.ts'],
|
||||
moduleNameMapper: {
|
||||
'^@/(.*)$': '<rootDir>/src/$1'
|
||||
},
|
||||
clearMocks: true,
|
||||
collectCoverageFrom: [
|
||||
'src/**/*.ts',
|
||||
'!src/**/*.d.ts',
|
||||
'!src/generated/**',
|
||||
'!src/server.ts'
|
||||
],
|
||||
transform: {
|
||||
'^.+\\.tsx?$': ['ts-jest', { tsconfig: './tsconfig.test.json' }]
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
962
Backend/package-lock.json
generated
962
Backend/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -44,6 +44,7 @@
|
|||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/cors": "^2.8.17",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/jsonwebtoken": "^9.0.7",
|
||||
"@types/multer": "^1.4.12",
|
||||
"@types/node": "^22.10.5",
|
||||
|
|
|
|||
171
Backend/pnpm-lock.yaml
generated
171
Backend/pnpm-lock.yaml
generated
|
|
@ -78,6 +78,9 @@ importers:
|
|||
'@types/express':
|
||||
specifier: ^5.0.0
|
||||
version: 5.0.6
|
||||
'@types/jest':
|
||||
specifier: ^30.0.0
|
||||
version: 30.0.0
|
||||
'@types/jsonwebtoken':
|
||||
specifier: ^9.0.7
|
||||
version: 9.0.10
|
||||
|
|
@ -119,7 +122,7 @@ importers:
|
|||
version: 7.2.2
|
||||
ts-jest:
|
||||
specifier: ^29.2.5
|
||||
version: 29.4.6(@babel/core@7.28.5)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.5))(jest-util@29.7.0)(jest@29.7.0(@types/node@22.19.5))(typescript@5.9.3)
|
||||
version: 29.4.6(@babel/core@7.28.5)(@jest/transform@29.7.0)(@jest/types@30.2.0)(babel-jest@29.7.0(@babel/core@7.28.5))(jest-util@30.2.0)(jest@29.7.0(@types/node@22.19.5))(typescript@5.9.3)
|
||||
tsconfig-paths:
|
||||
specifier: ^4.2.0
|
||||
version: 4.2.0
|
||||
|
|
@ -615,6 +618,10 @@ packages:
|
|||
node-notifier:
|
||||
optional: true
|
||||
|
||||
'@jest/diff-sequences@30.0.1':
|
||||
resolution: {integrity: sha512-n5H8QLDJ47QqbCNn5SuFjCRDrOLEZ0h8vAHCK5RL9Ls7Xa8AQLa/YxAc9UjFqoEDM48muwtBGjtMY5cr0PLDCw==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
'@jest/environment@29.7.0':
|
||||
resolution: {integrity: sha512-aQIfHDq33ExsN4jP1NWGXhxgQ/wixs60gDiKO+XVMd8Mn0NWPWgc34ZQDTb2jKaUWQ7MuwoitXAsN2XVXNMpAw==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
|
@ -623,6 +630,10 @@ packages:
|
|||
resolution: {integrity: sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
'@jest/expect-utils@30.2.0':
|
||||
resolution: {integrity: sha512-1JnRfhqpD8HGpOmQp180Fo9Zt69zNtC+9lR+kT7NVL05tNXIi+QC8Csz7lfidMoVLPD3FnOtcmp0CEFnxExGEA==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
'@jest/expect@29.7.0':
|
||||
resolution: {integrity: sha512-8uMeAMycttpva3P1lBHB8VciS9V0XAr3GymPpipdyQXbBcuhkLQOSe8E/p92RyAdToS6ZD1tFkX+CkhoECE0dQ==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
|
@ -631,10 +642,18 @@ packages:
|
|||
resolution: {integrity: sha512-q4DH1Ha4TTFPdxLsqDXK1d3+ioSL7yL5oCMJZgDYm6i+6CygW5E5xVr/D1HdsGxjt1ZWSfUAs9OxSB/BNelWrQ==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
'@jest/get-type@30.1.0':
|
||||
resolution: {integrity: sha512-eMbZE2hUnx1WV0pmURZY9XoXPkUYjpc55mb0CrhtdWLtzMQPFvu/rZkTLZFTsdaVQa+Tr4eWAteqcUzoawq/uA==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
'@jest/globals@29.7.0':
|
||||
resolution: {integrity: sha512-mpiz3dutLbkW2MNFubUGUEVLkTGiqW6yLVTA+JbP6fI6J5iL9Y0Nlg8k95pcF8ctKwCS7WVxteBs29hhfAotzQ==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
'@jest/pattern@30.0.1':
|
||||
resolution: {integrity: sha512-gWp7NfQW27LaBQz3TITS8L7ZCQ0TLvtmI//4OwlQRx4rnWxcPNIYjxZpDcN4+UlGxgm3jS5QPz8IPTCkb59wZA==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
'@jest/reporters@29.7.0':
|
||||
resolution: {integrity: sha512-DApq0KJbJOEzAFYjHADNNxAE3KbhxQB1y5Kplb5Waqw6zVbuWatSnMjE5gs8FUgEPmNsnZA3NCWl9NG0ia04Pg==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
|
@ -648,6 +667,10 @@ packages:
|
|||
resolution: {integrity: sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
'@jest/schemas@30.0.5':
|
||||
resolution: {integrity: sha512-DmdYgtezMkh3cpU8/1uyXakv3tJRcmcXxBOcO0tbaozPwpmh4YMsnWrQm9ZmZMfa5ocbxzbFk6O4bDPEc/iAnA==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
'@jest/source-map@29.6.3':
|
||||
resolution: {integrity: sha512-MHjT95QuipcPrpLM+8JMSzFx6eHp5Bm+4XeFDJlwsvVBjmKNiIAvasGK2fxz2WbGRlnvqehFbh07MMa7n3YJnw==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
|
@ -668,6 +691,10 @@ packages:
|
|||
resolution: {integrity: sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
'@jest/types@30.2.0':
|
||||
resolution: {integrity: sha512-H9xg1/sfVvyfU7o3zMfBEjQ1gcsdeTMgqHoYdN79tuLqfTtuu7WckRA1R5whDwOzxaZAeMKTYWqP+WCAi0CHsg==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
'@jridgewell/gen-mapping@0.3.13':
|
||||
resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==}
|
||||
|
||||
|
|
@ -862,6 +889,9 @@ packages:
|
|||
'@sinclair/typebox@0.27.8':
|
||||
resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==}
|
||||
|
||||
'@sinclair/typebox@0.34.48':
|
||||
resolution: {integrity: sha512-kKJTNuK3AQOrgjjotVxMrCn1sUJwM76wMszfq1kdU4uYVJjvEWuFQ6HgvLt4Xz3fSmZlTOxJ/Ie13KnIcWQXFA==}
|
||||
|
||||
'@sinonjs/commons@3.0.1':
|
||||
resolution: {integrity: sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==}
|
||||
|
||||
|
|
@ -1115,6 +1145,9 @@ packages:
|
|||
'@types/istanbul-reports@3.0.4':
|
||||
resolution: {integrity: sha512-pk2B1NWalF9toCRu6gjBzR69syFjP4Od8WRAX+0mmf9lAjCRicLOWc+ZrxZHx/0XRjotgkF9t6iaMJ+aXcOdZQ==}
|
||||
|
||||
'@types/jest@30.0.0':
|
||||
resolution: {integrity: sha512-XTYugzhuwqWjws0CVz8QpM36+T+Dz5mTEBKhNs/esGLnCIlGdRy+Dq78NRjd7ls7r8BC8ZRMOrKlkO1hU0JOwA==}
|
||||
|
||||
'@types/json-schema@7.0.15':
|
||||
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
|
||||
|
||||
|
|
@ -1433,6 +1466,10 @@ packages:
|
|||
resolution: {integrity: sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
ci-info@4.4.0:
|
||||
resolution: {integrity: sha512-77PSwercCZU2Fc4sX94eF8k8Pxte6JAwL4/ICZLFjJLqegs7kCuAsqqj/70NQF6TvDpgFjkubQB2FW2ZZddvQg==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
cjs-module-lexer@1.4.3:
|
||||
resolution: {integrity: sha512-9z8TZaGM1pfswYeXrUpzPrkx8UnWYdhJclsiYMm6x/w5+nN+8Tf/LnAgfLGQCm59qAOxU8WwHEq2vNwF6i4j+Q==}
|
||||
|
||||
|
|
@ -1729,6 +1766,10 @@ packages:
|
|||
resolution: {integrity: sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
expect@30.2.0:
|
||||
resolution: {integrity: sha512-u/feCi0GPsI+988gU2FLcsHyAHTU0MX1Wg68NhAnN7z/+C5wqG+CY8J53N9ioe8RXgaoz0nBR/TYMf3AycUuPw==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
express-rate-limit@7.5.1:
|
||||
resolution: {integrity: sha512-7iN8iPMDzOMHPUYllBEsQdWVB6fPDMPqwjBaFrgr4Jgr/+okjvzAy+UHlYYL/Vs0OsOrMkwS6PJDkFlJwoxUnw==}
|
||||
engines: {node: '>= 16'}
|
||||
|
|
@ -2118,6 +2159,10 @@ packages:
|
|||
resolution: {integrity: sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
jest-diff@30.2.0:
|
||||
resolution: {integrity: sha512-dQHFo3Pt4/NLlG5z4PxZ/3yZTZ1C7s9hveiOj+GCN+uT109NC2QgsoVZsVOAvbJ3RgKkvyLGXZV9+piDpWbm6A==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
jest-docblock@29.7.0:
|
||||
resolution: {integrity: sha512-q617Auw3A612guyaFgsbFeYpNP5t2aoUNLwBUbc/0kD1R4t9ixDbyFTHd1nok4epoVFpr7PmeWHrhvuV3XaJ4g==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
|
@ -2146,14 +2191,26 @@ packages:
|
|||
resolution: {integrity: sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
jest-matcher-utils@30.2.0:
|
||||
resolution: {integrity: sha512-dQ94Nq4dbzmUWkQ0ANAWS9tBRfqCrn0bV9AMYdOi/MHW726xn7eQmMeRTpX2ViC00bpNaWXq+7o4lIQ3AX13Hg==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
jest-message-util@29.7.0:
|
||||
resolution: {integrity: sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
jest-message-util@30.2.0:
|
||||
resolution: {integrity: sha512-y4DKFLZ2y6DxTWD4cDe07RglV88ZiNEdlRfGtqahfbIjfsw1nMCPx49Uev4IA/hWn3sDKyAnSPwoYSsAEdcimw==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
jest-mock@29.7.0:
|
||||
resolution: {integrity: sha512-ITOMZn+UkYS4ZFh83xYAOzWStloNzJFO2s8DWrE4lhtGD+AorgnbkiKERe4wQVBydIGPx059g6riW5Btp6Llnw==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
jest-mock@30.2.0:
|
||||
resolution: {integrity: sha512-JNNNl2rj4b5ICpmAcq+WbLH83XswjPbjH4T7yvGzfAGCPh1rw+xVNbtk+FnRslvt9lkCcdn9i1oAoKUuFsOxRw==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
jest-pnp-resolver@1.2.3:
|
||||
resolution: {integrity: sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==}
|
||||
engines: {node: '>=6'}
|
||||
|
|
@ -2167,6 +2224,10 @@ packages:
|
|||
resolution: {integrity: sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
jest-regex-util@30.0.1:
|
||||
resolution: {integrity: sha512-jHEQgBXAgc+Gh4g0p3bCevgRCVRkB4VB70zhoAE48gxeSr1hfUOsM/C2WoJgVL7Eyg//hudYENbm3Ne+/dRVVA==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
jest-resolve-dependencies@29.7.0:
|
||||
resolution: {integrity: sha512-un0zD/6qxJ+S0et7WxeI3H5XSe9lTBBR7bOHCHXkKR6luG5mwDDlIzVQ0V5cZCuoTgEdcdwzTghYkTWfubi+nA==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
|
@ -2191,6 +2252,10 @@ packages:
|
|||
resolution: {integrity: sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
jest-util@30.2.0:
|
||||
resolution: {integrity: sha512-QKNsM0o3Xe6ISQU869e+DhG+4CK/48aHYdJZGlFQVTjnbvgpcKyxpzk29fGiO7i/J8VENZ+d2iGnSsvmuHywlA==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
jest-validate@29.7.0:
|
||||
resolution: {integrity: sha512-ZB7wHqaRGVw/9hST/OuFUReG7M8vKeq0/J2egIGLdvjHCmYqGARhzXmtgi+gVeZ5uXFF219aOc3Ls2yLg27tkw==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
|
@ -2584,6 +2649,10 @@ packages:
|
|||
resolution: {integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==}
|
||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||
|
||||
pretty-format@30.2.0:
|
||||
resolution: {integrity: sha512-9uBdv/B4EefsuAL+pWqueZyZS2Ba+LxfFeQ9DN14HU4bN8bhaxKdkpjpB6fs9+pSjIBu+FXQHImEg8j/Lw0+vA==}
|
||||
engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
|
||||
prisma@5.22.0:
|
||||
resolution: {integrity: sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A==}
|
||||
engines: {node: '>=16.13'}
|
||||
|
|
@ -4027,6 +4096,8 @@ snapshots:
|
|||
- supports-color
|
||||
- ts-node
|
||||
|
||||
'@jest/diff-sequences@30.0.1': {}
|
||||
|
||||
'@jest/environment@29.7.0':
|
||||
dependencies:
|
||||
'@jest/fake-timers': 29.7.0
|
||||
|
|
@ -4038,6 +4109,10 @@ snapshots:
|
|||
dependencies:
|
||||
jest-get-type: 29.6.3
|
||||
|
||||
'@jest/expect-utils@30.2.0':
|
||||
dependencies:
|
||||
'@jest/get-type': 30.1.0
|
||||
|
||||
'@jest/expect@29.7.0':
|
||||
dependencies:
|
||||
expect: 29.7.0
|
||||
|
|
@ -4054,6 +4129,8 @@ snapshots:
|
|||
jest-mock: 29.7.0
|
||||
jest-util: 29.7.0
|
||||
|
||||
'@jest/get-type@30.1.0': {}
|
||||
|
||||
'@jest/globals@29.7.0':
|
||||
dependencies:
|
||||
'@jest/environment': 29.7.0
|
||||
|
|
@ -4063,6 +4140,11 @@ snapshots:
|
|||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@jest/pattern@30.0.1':
|
||||
dependencies:
|
||||
'@types/node': 22.19.5
|
||||
jest-regex-util: 30.0.1
|
||||
|
||||
'@jest/reporters@29.7.0':
|
||||
dependencies:
|
||||
'@bcoe/v8-coverage': 0.2.3
|
||||
|
|
@ -4096,6 +4178,10 @@ snapshots:
|
|||
dependencies:
|
||||
'@sinclair/typebox': 0.27.8
|
||||
|
||||
'@jest/schemas@30.0.5':
|
||||
dependencies:
|
||||
'@sinclair/typebox': 0.34.48
|
||||
|
||||
'@jest/source-map@29.6.3':
|
||||
dependencies:
|
||||
'@jridgewell/trace-mapping': 0.3.31
|
||||
|
|
@ -4145,6 +4231,16 @@ snapshots:
|
|||
'@types/yargs': 17.0.35
|
||||
chalk: 4.1.2
|
||||
|
||||
'@jest/types@30.2.0':
|
||||
dependencies:
|
||||
'@jest/pattern': 30.0.1
|
||||
'@jest/schemas': 30.0.5
|
||||
'@types/istanbul-lib-coverage': 2.0.6
|
||||
'@types/istanbul-reports': 3.0.4
|
||||
'@types/node': 22.19.5
|
||||
'@types/yargs': 17.0.35
|
||||
chalk: 4.1.2
|
||||
|
||||
'@jridgewell/gen-mapping@0.3.13':
|
||||
dependencies:
|
||||
'@jridgewell/sourcemap-codec': 1.5.5
|
||||
|
|
@ -4316,6 +4412,8 @@ snapshots:
|
|||
|
||||
'@sinclair/typebox@0.27.8': {}
|
||||
|
||||
'@sinclair/typebox@0.34.48': {}
|
||||
|
||||
'@sinonjs/commons@3.0.1':
|
||||
dependencies:
|
||||
type-detect: 4.0.8
|
||||
|
|
@ -4721,6 +4819,11 @@ snapshots:
|
|||
dependencies:
|
||||
'@types/istanbul-lib-report': 3.0.3
|
||||
|
||||
'@types/jest@30.0.0':
|
||||
dependencies:
|
||||
expect: 30.2.0
|
||||
pretty-format: 30.2.0
|
||||
|
||||
'@types/json-schema@7.0.15': {}
|
||||
|
||||
'@types/jsonwebtoken@9.0.10':
|
||||
|
|
@ -5116,6 +5219,8 @@ snapshots:
|
|||
|
||||
ci-info@3.9.0: {}
|
||||
|
||||
ci-info@4.4.0: {}
|
||||
|
||||
cjs-module-lexer@1.4.3: {}
|
||||
|
||||
cliui@8.0.1:
|
||||
|
|
@ -5398,6 +5503,15 @@ snapshots:
|
|||
jest-message-util: 29.7.0
|
||||
jest-util: 29.7.0
|
||||
|
||||
expect@30.2.0:
|
||||
dependencies:
|
||||
'@jest/expect-utils': 30.2.0
|
||||
'@jest/get-type': 30.1.0
|
||||
jest-matcher-utils: 30.2.0
|
||||
jest-message-util: 30.2.0
|
||||
jest-mock: 30.2.0
|
||||
jest-util: 30.2.0
|
||||
|
||||
express-rate-limit@7.5.1(express@4.22.1):
|
||||
dependencies:
|
||||
express: 4.22.1
|
||||
|
|
@ -5872,6 +5986,13 @@ snapshots:
|
|||
jest-get-type: 29.6.3
|
||||
pretty-format: 29.7.0
|
||||
|
||||
jest-diff@30.2.0:
|
||||
dependencies:
|
||||
'@jest/diff-sequences': 30.0.1
|
||||
'@jest/get-type': 30.1.0
|
||||
chalk: 4.1.2
|
||||
pretty-format: 30.2.0
|
||||
|
||||
jest-docblock@29.7.0:
|
||||
dependencies:
|
||||
detect-newline: 3.1.0
|
||||
|
|
@ -5923,6 +6044,13 @@ snapshots:
|
|||
jest-get-type: 29.6.3
|
||||
pretty-format: 29.7.0
|
||||
|
||||
jest-matcher-utils@30.2.0:
|
||||
dependencies:
|
||||
'@jest/get-type': 30.1.0
|
||||
chalk: 4.1.2
|
||||
jest-diff: 30.2.0
|
||||
pretty-format: 30.2.0
|
||||
|
||||
jest-message-util@29.7.0:
|
||||
dependencies:
|
||||
'@babel/code-frame': 7.27.1
|
||||
|
|
@ -5935,18 +6063,38 @@ snapshots:
|
|||
slash: 3.0.0
|
||||
stack-utils: 2.0.6
|
||||
|
||||
jest-message-util@30.2.0:
|
||||
dependencies:
|
||||
'@babel/code-frame': 7.27.1
|
||||
'@jest/types': 30.2.0
|
||||
'@types/stack-utils': 2.0.3
|
||||
chalk: 4.1.2
|
||||
graceful-fs: 4.2.11
|
||||
micromatch: 4.0.8
|
||||
pretty-format: 30.2.0
|
||||
slash: 3.0.0
|
||||
stack-utils: 2.0.6
|
||||
|
||||
jest-mock@29.7.0:
|
||||
dependencies:
|
||||
'@jest/types': 29.6.3
|
||||
'@types/node': 22.19.5
|
||||
jest-util: 29.7.0
|
||||
|
||||
jest-mock@30.2.0:
|
||||
dependencies:
|
||||
'@jest/types': 30.2.0
|
||||
'@types/node': 22.19.5
|
||||
jest-util: 30.2.0
|
||||
|
||||
jest-pnp-resolver@1.2.3(jest-resolve@29.7.0):
|
||||
optionalDependencies:
|
||||
jest-resolve: 29.7.0
|
||||
|
||||
jest-regex-util@29.6.3: {}
|
||||
|
||||
jest-regex-util@30.0.1: {}
|
||||
|
||||
jest-resolve-dependencies@29.7.0:
|
||||
dependencies:
|
||||
jest-regex-util: 29.6.3
|
||||
|
|
@ -6053,6 +6201,15 @@ snapshots:
|
|||
graceful-fs: 4.2.11
|
||||
picomatch: 2.3.1
|
||||
|
||||
jest-util@30.2.0:
|
||||
dependencies:
|
||||
'@jest/types': 30.2.0
|
||||
'@types/node': 22.19.5
|
||||
chalk: 4.1.2
|
||||
ci-info: 4.4.0
|
||||
graceful-fs: 4.2.11
|
||||
picomatch: 4.0.3
|
||||
|
||||
jest-validate@29.7.0:
|
||||
dependencies:
|
||||
'@jest/types': 29.6.3
|
||||
|
|
@ -6444,6 +6601,12 @@ snapshots:
|
|||
ansi-styles: 5.2.0
|
||||
react-is: 18.3.1
|
||||
|
||||
pretty-format@30.2.0:
|
||||
dependencies:
|
||||
'@jest/schemas': 30.0.5
|
||||
ansi-styles: 5.2.0
|
||||
react-is: 18.3.1
|
||||
|
||||
prisma@5.22.0:
|
||||
dependencies:
|
||||
'@prisma/engines': 5.22.0
|
||||
|
|
@ -6797,7 +6960,7 @@ snapshots:
|
|||
|
||||
ts-deepmerge@7.0.3: {}
|
||||
|
||||
ts-jest@29.4.6(@babel/core@7.28.5)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.5))(jest-util@29.7.0)(jest@29.7.0(@types/node@22.19.5))(typescript@5.9.3):
|
||||
ts-jest@29.4.6(@babel/core@7.28.5)(@jest/transform@29.7.0)(@jest/types@30.2.0)(babel-jest@29.7.0(@babel/core@7.28.5))(jest-util@30.2.0)(jest@29.7.0(@types/node@22.19.5))(typescript@5.9.3):
|
||||
dependencies:
|
||||
bs-logger: 0.2.6
|
||||
fast-json-stable-stringify: 2.1.0
|
||||
|
|
@ -6813,9 +6976,9 @@ snapshots:
|
|||
optionalDependencies:
|
||||
'@babel/core': 7.28.5
|
||||
'@jest/transform': 29.7.0
|
||||
'@jest/types': 29.6.3
|
||||
'@jest/types': 30.2.0
|
||||
babel-jest: 29.7.0(@babel/core@7.28.5)
|
||||
jest-util: 29.7.0
|
||||
jest-util: 30.2.0
|
||||
|
||||
tsconfig-paths@4.2.0:
|
||||
dependencies:
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@ export class AdminCourseApprovalController {
|
|||
@Response('401', 'Unauthorized')
|
||||
@Response('403', 'Forbidden - Admin only')
|
||||
public async listPendingCourses(@Request() request: any): Promise<ListPendingCoursesResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await AdminCourseApprovalService.listPendingCourses(token);
|
||||
return await AdminCourseApprovalService.listPendingCourses(request.user.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -41,9 +39,7 @@ export class AdminCourseApprovalController {
|
|||
@Response('403', 'Forbidden - Admin only')
|
||||
@Response('404', 'Course not found')
|
||||
public async getCourseDetail(@Request() request: any, @Path() courseId: number): Promise<GetCourseDetailForAdminResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await AdminCourseApprovalService.getCourseDetail(token, courseId);
|
||||
return await AdminCourseApprovalService.getCourseDetail(request.user.id, courseId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,10 +58,7 @@ export class AdminCourseApprovalController {
|
|||
@Request() request: any,
|
||||
@Path() courseId: number
|
||||
): Promise<ApproveCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
return await AdminCourseApprovalService.approveCourse(token, courseId, undefined);
|
||||
return await AdminCourseApprovalService.approveCourse(request.user.id, courseId, undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,13 +78,10 @@ export class AdminCourseApprovalController {
|
|||
@Path() courseId: number,
|
||||
@Body() body: RejectCourseBody
|
||||
): Promise<RejectCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
// Validate body
|
||||
const { error } = RejectCourseValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await AdminCourseApprovalService.rejectCourse(token, courseId, body.comment);
|
||||
return await AdminCourseApprovalService.rejectCourse(request.user.id, courseId, body.comment);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,11 +40,6 @@ export class AuditController {
|
|||
@Query() page?: number,
|
||||
@Query() limit?: number
|
||||
): Promise<ListAuditLogsResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
|
||||
return await auditService.getLogs({
|
||||
userId,
|
||||
action,
|
||||
|
|
@ -72,11 +67,6 @@ export class AuditController {
|
|||
@Request() request: any,
|
||||
@Path() logId: number
|
||||
): Promise<AuditLogResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
|
||||
const log = await auditService.getLogById(logId);
|
||||
if (!log) {
|
||||
throw new ValidationError('Audit log not found');
|
||||
|
|
@ -94,11 +84,6 @@ export class AuditController {
|
|||
@Response('401', 'Unauthorized')
|
||||
@Response('403', 'Forbidden - Admin only')
|
||||
public async getAuditStats(@Request() request: any): Promise<AuditLogStats> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
|
||||
return await auditService.getStats();
|
||||
}
|
||||
|
||||
|
|
@ -118,11 +103,6 @@ export class AuditController {
|
|||
@Path() entityType: string,
|
||||
@Path() entityId: number
|
||||
): Promise<AuditLogResponse[]> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
|
||||
return await auditService.getEntityHistory(entityType, entityId);
|
||||
}
|
||||
|
||||
|
|
@ -142,11 +122,6 @@ export class AuditController {
|
|||
@Path() userId: number,
|
||||
@Query() limit?: number
|
||||
): Promise<AuditLogResponse[]> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
|
||||
return await auditService.getUserActivity(userId, limit || 50);
|
||||
}
|
||||
|
||||
|
|
@ -164,11 +139,6 @@ export class AuditController {
|
|||
@Request() request: any,
|
||||
@Query() days: number = 90
|
||||
): Promise<{ deleted: number; message: string }> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
|
||||
if (days < 6) {
|
||||
throw new ValidationError('Cannot delete logs newer than 6 days');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,32 +33,6 @@ export class AuthController {
|
|||
data: {
|
||||
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||
refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||
user: {
|
||||
id: 1,
|
||||
username: 'admin',
|
||||
email: 'admin@elearning.local',
|
||||
email_verified_at: new Date('2024-01-01T00:00:00Z'),
|
||||
updated_at: new Date('2024-01-01T00:00:00Z'),
|
||||
created_at: new Date('2024-01-01T00:00:00Z'),
|
||||
role: {
|
||||
code: 'ADMIN',
|
||||
name: {
|
||||
th: 'ผู้ดูแลระบบ',
|
||||
en: 'Administrator'
|
||||
}
|
||||
},
|
||||
profile: {
|
||||
prefix: {
|
||||
th: 'นาย',
|
||||
en: 'Mr.'
|
||||
},
|
||||
first_name: 'Admin',
|
||||
last_name: 'User',
|
||||
phone: null,
|
||||
avatar_url: null,
|
||||
birth_date: null
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
public async login(@Body() body: LoginRequest): Promise<LoginResponse> {
|
||||
|
|
|
|||
|
|
@ -27,13 +27,11 @@ export class CategoriesAdminController {
|
|||
@SuccessResponse('200', 'Category created successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async createCategory(@Request() request: any, @Body() body: createCategory): Promise<createCategoryResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '') || '';
|
||||
|
||||
// Validate body
|
||||
const { error } = CreateCategoryValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await this.categoryService.createCategory(token, body);
|
||||
return await this.categoryService.createCategory(request.user.id, body);
|
||||
}
|
||||
|
||||
@Put('{id}')
|
||||
|
|
@ -41,13 +39,11 @@ export class CategoriesAdminController {
|
|||
@SuccessResponse('200', 'Category updated successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async updateCategory(@Request() request: any, @Body() body: updateCategory): Promise<updateCategoryResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '') || '';
|
||||
|
||||
// Validate body
|
||||
const { error } = UpdateCategoryValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await this.categoryService.updateCategory(token, body.id, body);
|
||||
return await this.categoryService.updateCategory(request.user.id, body.id, body);
|
||||
}
|
||||
|
||||
@Delete('{id}')
|
||||
|
|
@ -55,7 +51,6 @@ export class CategoriesAdminController {
|
|||
@SuccessResponse('200', 'Category deleted successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async deleteCategory(@Request() request: any, @Path() id: number): Promise<deleteCategoryResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '') || '';
|
||||
return await this.categoryService.deleteCategory(token, id);
|
||||
return await this.categoryService.deleteCategory(request.user.id, id);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
import { Get, Post, Route, Tags, SuccessResponse, Response, Security, Path, Request } from 'tsoa';
|
||||
import { ValidationError } from '../middleware/errorHandler';
|
||||
import { CertificateService } from '../services/certificate.service';
|
||||
import {
|
||||
GenerateCertificateResponse,
|
||||
|
|
@ -21,9 +20,7 @@ export class CertificateController {
|
|||
@SuccessResponse('200', 'Certificates retrieved successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async listMyCertificates(@Request() request: any): Promise<ListMyCertificatesResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await this.certificateService.listMyCertificates({ token });
|
||||
return await this.certificateService.listMyCertificates({ userId: request.user.id });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -37,9 +34,7 @@ export class CertificateController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Certificate not found')
|
||||
public async getCertificate(@Request() request: any, @Path() courseId: number): Promise<GetCertificateResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await this.certificateService.getCertificate({ token, course_id: courseId });
|
||||
return await this.certificateService.getCertificate({ userId: request.user.id, course_id: courseId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,8 +49,6 @@ export class CertificateController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Enrollment not found')
|
||||
public async generateCertificate(@Request() request: any, @Path() courseId: number): Promise<GenerateCertificateResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await this.certificateService.generateCertificate({ token, course_id: courseId });
|
||||
return await this.certificateService.generateCertificate({ userId: request.user.id, course_id: courseId });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,14 +65,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() courseId: number,
|
||||
@Body() body: CreateChapterBody
|
||||
): Promise<CreateChapterResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = CreateChapterValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.createChapter({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
title: body.title,
|
||||
description: body.description,
|
||||
|
|
@ -96,14 +93,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() chapterId: number,
|
||||
@Body() body: UpdateChapterBody
|
||||
): Promise<UpdateChapterResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = UpdateChapterValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.updateChapter({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
chapter_id: chapterId,
|
||||
...body,
|
||||
|
|
@ -125,9 +119,7 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() courseId: number,
|
||||
@Path() chapterId: number
|
||||
): Promise<DeleteChapterResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await chaptersLessonService.deleteChapter({ token, course_id: courseId, chapter_id: chapterId });
|
||||
return await chaptersLessonService.deleteChapter({ userId: request.user.id, course_id: courseId, chapter_id: chapterId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,14 +135,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() chapterId: number,
|
||||
@Body() body: ReorderChapterBody
|
||||
): Promise<ReorderChapterResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = ReorderChapterValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.reorderChapter({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
chapter_id: chapterId,
|
||||
sort_order: body.sort_order,
|
||||
|
|
@ -174,9 +163,7 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() chapterId: number,
|
||||
@Path() lessonId: number
|
||||
): Promise<GetLessonResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await chaptersLessonService.getLesson({ token, course_id: courseId, chapter_id: chapterId, lesson_id: lessonId });
|
||||
return await chaptersLessonService.getLesson({ userId: request.user.id, course_id: courseId, chapter_id: chapterId, lesson_id: lessonId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -192,14 +179,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() chapterId: number,
|
||||
@Body() body: CreateLessonBody
|
||||
): Promise<CreateLessonResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = CreateLessonValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.createLesson({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
chapter_id: chapterId,
|
||||
title: body.title,
|
||||
|
|
@ -223,14 +207,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() lessonId: number,
|
||||
@Body() body: UpdateLessonBody
|
||||
): Promise<UpdateLessonResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = UpdateLessonValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.updateLesson({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
chapter_id: chapterId,
|
||||
lesson_id: lessonId,
|
||||
|
|
@ -258,9 +239,7 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() chapterId: number,
|
||||
@Path() lessonId: number
|
||||
): Promise<DeleteLessonResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await chaptersLessonService.deleteLesson({ token, course_id: courseId, chapter_id: chapterId, lesson_id: lessonId });
|
||||
return await chaptersLessonService.deleteLesson({ userId: request.user.id, course_id: courseId, chapter_id: chapterId, lesson_id: lessonId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -276,14 +255,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() chapterId: number,
|
||||
@Body() body: ReorderLessonsBody
|
||||
): Promise<ReorderLessonsResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = ReorderLessonsValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.reorderLessons({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
chapter_id: chapterId,
|
||||
lesson_id: body.lesson_id,
|
||||
|
|
@ -309,14 +285,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() lessonId: number,
|
||||
@Body() body: AddQuestionBody
|
||||
): Promise<AddQuestionResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = AddQuestionValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.addQuestion({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
...body,
|
||||
|
|
@ -338,14 +311,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() questionId: number,
|
||||
@Body() body: UpdateQuestionBody
|
||||
): Promise<UpdateQuestionResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = UpdateQuestionValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.updateQuestion({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
question_id: questionId,
|
||||
|
|
@ -364,14 +334,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() questionId: number,
|
||||
@Body() body: ReorderQuestionBody
|
||||
): Promise<ReorderQuestionResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = ReorderQuestionValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.reorderQuestion({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
question_id: questionId,
|
||||
|
|
@ -393,10 +360,8 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() lessonId: number,
|
||||
@Path() questionId: number
|
||||
): Promise<DeleteQuestionResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await chaptersLessonService.deleteQuestion({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
question_id: questionId,
|
||||
|
|
@ -417,14 +382,11 @@ export class ChaptersLessonInstructorController {
|
|||
@Path() lessonId: number,
|
||||
@Body() body: UpdateQuizBody
|
||||
): Promise<UpdateQuizResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = UpdateQuizValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.updateQuiz({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
...body,
|
||||
|
|
|
|||
|
|
@ -22,12 +22,10 @@ import {
|
|||
GetCourseApprovalHistoryResponse,
|
||||
setCourseDraftResponse,
|
||||
CloneCourseResponse,
|
||||
GetAllMyStudentsResponse,
|
||||
} from '../types/CoursesInstructor.types';
|
||||
import { CreateCourseValidator, UpdateCourseValidator, CloneCourseValidator } from "../validators/CoursesInstructor.validator";
|
||||
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { config } from '../config';
|
||||
|
||||
@Route('api/instructors/courses')
|
||||
@Tags('CoursesInstructor')
|
||||
export class CoursesInstructorController {
|
||||
|
|
@ -45,11 +43,7 @@ export class CoursesInstructorController {
|
|||
@Request() request: any,
|
||||
@Query() status?: 'DRAFT' | 'PENDING' | 'APPROVED' | 'REJECTED' | 'ARCHIVED'
|
||||
): Promise<ListMyCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await CoursesInstructorService.listMyCourses({ token, status });
|
||||
return await CoursesInstructorService.listMyCourses({ userId: request.user.id, status });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -67,9 +61,23 @@ export class CoursesInstructorController {
|
|||
@Path() courseId: number,
|
||||
@Query() query: string
|
||||
): Promise<SearchInstructorResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await CoursesInstructorService.searchInstructors({ token, query, course_id: courseId });
|
||||
return await CoursesInstructorService.searchInstructors({ userId: request.user.id, query, course_id: courseId });
|
||||
}
|
||||
|
||||
/**
|
||||
* ดึงผู้เรียนทั้งหมดของ instructor ทุกคอร์ส
|
||||
* Get all students enrolled in all of instructor's courses
|
||||
*
|
||||
* @returns รายการผู้เรียนแยกตามคอร์ส พร้อม total_enrolled และ total_completed ต่อคอร์ส
|
||||
*/
|
||||
@Get('my-students')
|
||||
@Security('jwt', ['instructor'])
|
||||
@SuccessResponse('200', 'Students retrieved successfully')
|
||||
@Response('401', 'Unauthorized')
|
||||
public async getMyAllStudents(
|
||||
@Request() request: any
|
||||
): Promise<GetAllMyStudentsResponse> {
|
||||
return await CoursesInstructorService.getMyAllStudents(request.user.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,11 +91,7 @@ export class CoursesInstructorController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Course not found')
|
||||
public async getMyCourse(@Request() request: any, @Path() courseId: number): Promise<GetMyCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await CoursesInstructorService.getmyCourse({ token, course_id: courseId });
|
||||
return await CoursesInstructorService.getmyCourse({ userId: request.user.id, course_id: courseId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -101,13 +105,10 @@ export class CoursesInstructorController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Course not found')
|
||||
public async updateCourse(@Request() request: any, @Path() courseId: number, @Body() body: UpdateMyCourse): Promise<UpdateMyCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = UpdateCourseValidator.validate(body.data);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await CoursesInstructorService.updateCourse(token, courseId, body.data);
|
||||
return await CoursesInstructorService.updateCourse(request.user.id, courseId, body.data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,10 +127,6 @@ export class CoursesInstructorController {
|
|||
@FormField() data: string,
|
||||
@UploadedFile() thumbnail?: Express.Multer.File
|
||||
): Promise<createCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const parsed = JSON.parse(data);
|
||||
const { error, value } = CreateCourseValidator.validate(parsed);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
|
@ -137,7 +134,7 @@ export class CoursesInstructorController {
|
|||
// Validate thumbnail file type if provided
|
||||
if (thumbnail && !thumbnail.mimetype?.startsWith('image/')) throw new ValidationError('Only image files are allowed for thumbnail');
|
||||
|
||||
return await CoursesInstructorService.createCourse(value, decoded.id, thumbnail);
|
||||
return await CoursesInstructorService.createCourse(value, request.user.id, thumbnail);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -156,11 +153,9 @@ export class CoursesInstructorController {
|
|||
@Path() courseId: number,
|
||||
@UploadedFile() file: Express.Multer.File
|
||||
): Promise<{ code: number; message: string; data: { course_id: number; thumbnail_url: string } }> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
if (!file.mimetype?.startsWith('image/')) throw new ValidationError('Only image files are allowed');
|
||||
|
||||
return await CoursesInstructorService.uploadThumbnail(token, courseId, file);
|
||||
return await CoursesInstructorService.uploadThumbnail(request.user.id, courseId, file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -174,9 +169,7 @@ export class CoursesInstructorController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Course not found')
|
||||
public async deleteCourse(@Request() request: any, @Path() courseId: number): Promise<DeleteMyCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided')
|
||||
return await CoursesInstructorService.deleteCourse(token, courseId);
|
||||
return await CoursesInstructorService.deleteCourse(request.user.id, courseId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -196,14 +189,11 @@ export class CoursesInstructorController {
|
|||
@Path() courseId: number,
|
||||
@Body() body: { title: { th: string; en: string } }
|
||||
): Promise<CloneCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = CloneCourseValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
const result = await CoursesInstructorService.cloneCourse({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
title: body.title
|
||||
});
|
||||
|
|
@ -220,9 +210,7 @@ export class CoursesInstructorController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Course not found')
|
||||
public async submitCourse(@Request() request: any, @Path() courseId: number): Promise<submitCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided')
|
||||
return await CoursesInstructorService.sendCourseForReview({ token, course_id: courseId });
|
||||
return await CoursesInstructorService.sendCourseForReview({ userId: request.user.id, course_id: courseId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -236,9 +224,7 @@ export class CoursesInstructorController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Course not found')
|
||||
public async setCourseDraft(@Request() request: any, @Path() courseId: number): Promise<setCourseDraftResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided')
|
||||
return await CoursesInstructorService.setCourseDraft({ token, course_id: courseId });
|
||||
return await CoursesInstructorService.setCourseDraft({ userId: request.user.id, course_id: courseId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -253,9 +239,7 @@ export class CoursesInstructorController {
|
|||
@Response('403', 'You are not an instructor of this course')
|
||||
@Response('404', 'Course not found')
|
||||
public async getCourseApprovals(@Request() request: any, @Path() courseId: number): Promise<GetCourseApprovalsResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided')
|
||||
return await CoursesInstructorService.getCourseApprovals(token, courseId);
|
||||
return await CoursesInstructorService.getCourseApprovals(request.user.id, courseId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -269,9 +253,7 @@ export class CoursesInstructorController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Instructors not found')
|
||||
public async listInstructorCourses(@Request() request: any, @Path() courseId: number): Promise<listinstructorCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided')
|
||||
return await CoursesInstructorService.listInstructorsOfCourse({ token, course_id: courseId });
|
||||
return await CoursesInstructorService.listInstructorsOfCourse({ userId: request.user.id, course_id: courseId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -286,9 +268,7 @@ export class CoursesInstructorController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Instructor not found')
|
||||
public async addInstructor(@Request() request: any, @Path() courseId: number, @Path() emailOrUsername: string): Promise<addinstructorCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided')
|
||||
return await CoursesInstructorService.addInstructorToCourse({ token, course_id: courseId, email_or_username: emailOrUsername });
|
||||
return await CoursesInstructorService.addInstructorToCourse({ userId: request.user.id, course_id: courseId, email_or_username: emailOrUsername });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -303,9 +283,7 @@ export class CoursesInstructorController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Instructor not found')
|
||||
public async removeInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<removeinstructorCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided')
|
||||
return await CoursesInstructorService.removeInstructorFromCourse({ token, course_id: courseId, user_id: userId });
|
||||
return await CoursesInstructorService.removeInstructorFromCourse({ userId: request.user.id, course_id: courseId, user_id: userId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -320,9 +298,7 @@ export class CoursesInstructorController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('404', 'Primary instructor not found')
|
||||
public async setPrimaryInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<setprimaryCourseInstructorResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided')
|
||||
return await CoursesInstructorService.setPrimaryInstructor({ token, course_id: courseId, user_id: userId });
|
||||
return await CoursesInstructorService.setPrimaryInstructor({ userId: request.user.id, course_id: courseId, user_id: userId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -347,10 +323,8 @@ export class CoursesInstructorController {
|
|||
@Query() search?: string,
|
||||
@Query() status?: 'ENROLLED' | 'COMPLETED'
|
||||
): Promise<GetEnrolledStudentsResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await CoursesInstructorService.getEnrolledStudents({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
page,
|
||||
limit,
|
||||
|
|
@ -376,10 +350,8 @@ export class CoursesInstructorController {
|
|||
@Path() courseId: number,
|
||||
@Path() studentId: number
|
||||
): Promise<GetEnrolledStudentDetailResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await CoursesInstructorService.getEnrolledStudentDetail({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
student_id: studentId,
|
||||
});
|
||||
|
|
@ -410,10 +382,8 @@ export class CoursesInstructorController {
|
|||
@Query() search?: string,
|
||||
@Query() isPassed?: boolean
|
||||
): Promise<GetQuizScoresResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await CoursesInstructorService.getQuizScores({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
page,
|
||||
|
|
@ -442,10 +412,8 @@ export class CoursesInstructorController {
|
|||
@Path() lessonId: number,
|
||||
@Path() studentId: number
|
||||
): Promise<GetQuizAttemptDetailResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await CoursesInstructorService.getQuizAttemptDetail({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
student_id: studentId,
|
||||
|
|
@ -467,8 +435,6 @@ export class CoursesInstructorController {
|
|||
@Request() request: any,
|
||||
@Path() courseId: number
|
||||
): Promise<GetCourseApprovalHistoryResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await CoursesInstructorService.getCourseApprovalHistory(token, courseId);
|
||||
return await CoursesInstructorService.getCourseApprovalHistory(request.user.id, courseId);
|
||||
}
|
||||
}
|
||||
|
|
@ -36,11 +36,7 @@ export class CoursesStudentController {
|
|||
@Response('404', 'Course not found')
|
||||
@Response('409', 'Already enrolled in this course')
|
||||
public async enrollCourse(@Request() request: any, @Path() courseId: number): Promise<EnrollCourseResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.service.enrollCourse({ token, course_id: courseId });
|
||||
return await this.service.enrollCourse({ userId: request.user.id, course_id: courseId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,11 +56,7 @@ export class CoursesStudentController {
|
|||
@Query() limit?: number,
|
||||
@Query() status?: EnrollmentStatus
|
||||
): Promise<ListEnrolledCoursesResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.service.GetEnrolledCourses({ token, page, limit, status });
|
||||
return await this.service.GetEnrolledCourses({ userId: request.user.id, page, limit, status });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -79,11 +71,7 @@ export class CoursesStudentController {
|
|||
@Response('403', 'Not enrolled in this course')
|
||||
@Response('404', 'Course not found')
|
||||
public async getCourseLearning(@Request() request: any, @Path() courseId: number): Promise<GetCourseLearningResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.service.getCourseLearning({ token, course_id: courseId });
|
||||
return await this.service.getCourseLearning({ userId: request.user.id, course_id: courseId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -103,11 +91,7 @@ export class CoursesStudentController {
|
|||
@Path() courseId: number,
|
||||
@Path() lessonId: number
|
||||
): Promise<GetLessonContentResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.service.getlessonContent({ token, course_id: courseId, lesson_id: lessonId });
|
||||
return await this.service.getlessonContent({ userId: request.user.id, course_id: courseId, lesson_id: lessonId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,11 +110,7 @@ export class CoursesStudentController {
|
|||
@Path() courseId: number,
|
||||
@Path() lessonId: number
|
||||
): Promise<CheckLessonAccessResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.service.checkAccessLesson({ token, course_id: courseId, lesson_id: lessonId });
|
||||
return await this.service.checkAccessLesson({ userId: request.user.id, course_id: courseId, lesson_id: lessonId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -149,14 +129,12 @@ export class CoursesStudentController {
|
|||
@Path() lessonId: number,
|
||||
@Body() body: SaveVideoProgressBody
|
||||
): Promise<SaveVideoProgressResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = SaveVideoProgressValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await this.service.saveVideoProgress({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
lesson_id: lessonId,
|
||||
video_progress_seconds: body.video_progress_seconds,
|
||||
video_duration_seconds: body.video_duration_seconds,
|
||||
|
|
@ -178,11 +156,7 @@ export class CoursesStudentController {
|
|||
@Request() request: any,
|
||||
@Path() lessonId: number
|
||||
): Promise<GetVideoProgressResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.service.getVideoProgress({ token, lesson_id: lessonId });
|
||||
return await this.service.getVideoProgress({ userId: request.user.id, lesson_id: lessonId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -202,11 +176,7 @@ export class CoursesStudentController {
|
|||
@Path() courseId: number,
|
||||
@Path() lessonId: number
|
||||
): Promise<CompleteLessonResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.service.completeLesson({ token, lesson_id: lessonId });
|
||||
return await this.service.completeLesson({ userId: request.user.id, lesson_id: lessonId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -227,14 +197,12 @@ export class CoursesStudentController {
|
|||
@Path() lessonId: number,
|
||||
@Body() body: SubmitQuizBody
|
||||
): Promise<SubmitQuizResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = SubmitQuizValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await this.service.submitQuiz({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
answers: body.answers,
|
||||
|
|
@ -258,12 +226,8 @@ export class CoursesStudentController {
|
|||
@Path() courseId: number,
|
||||
@Path() lessonId: number
|
||||
): Promise<GetQuizAttemptsResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.service.getQuizAttempts({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -42,8 +42,6 @@ export class LessonsController {
|
|||
@Path() lessonId: number,
|
||||
@UploadedFile() video: Express.Multer.File
|
||||
): Promise<VideoOperationResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
if (!video) {
|
||||
throw new ValidationError('Video file is required');
|
||||
|
|
@ -57,7 +55,7 @@ export class LessonsController {
|
|||
};
|
||||
|
||||
return await chaptersLessonService.uploadVideo({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
video: videoInfo,
|
||||
|
|
@ -87,8 +85,6 @@ export class LessonsController {
|
|||
@Path() lessonId: number,
|
||||
@UploadedFile() video: Express.Multer.File
|
||||
): Promise<VideoOperationResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
if (!video) {
|
||||
throw new ValidationError('Video file is required');
|
||||
|
|
@ -102,7 +98,7 @@ export class LessonsController {
|
|||
};
|
||||
|
||||
return await chaptersLessonService.updateVideo({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
video: videoInfo,
|
||||
|
|
@ -132,8 +128,6 @@ export class LessonsController {
|
|||
@Path() lessonId: number,
|
||||
@UploadedFile() attachment: Express.Multer.File
|
||||
): Promise<AttachmentOperationResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
if (!attachment) {
|
||||
throw new ValidationError('Attachment file is required');
|
||||
|
|
@ -147,7 +141,7 @@ export class LessonsController {
|
|||
};
|
||||
|
||||
return await chaptersLessonService.uploadAttachment({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
attachment: attachmentInfo,
|
||||
|
|
@ -177,11 +171,9 @@ export class LessonsController {
|
|||
@Path() lessonId: number,
|
||||
@Path() attachmentId: number
|
||||
): Promise<DeleteAttachmentResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
return await chaptersLessonService.deleteAttachment({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
attachment_id: attachmentId,
|
||||
|
|
@ -211,14 +203,12 @@ export class LessonsController {
|
|||
@Path() lessonId: number,
|
||||
@Body() body: SetYouTubeVideoBody
|
||||
): Promise<YouTubeVideoResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
const { error } = SetYouTubeVideoValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await chaptersLessonService.setYouTubeVideo({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
lesson_id: lessonId,
|
||||
youtube_video_id: body.youtube_video_id,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { Get, Path, Put, Query, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa';
|
||||
import { ValidationError } from '../middleware/errorHandler';
|
||||
import { RecommendedCoursesService } from '../services/RecommendedCourses.service';
|
||||
import {
|
||||
ListApprovedCoursesResponse,
|
||||
|
|
@ -25,9 +24,7 @@ export class RecommendedCoursesController {
|
|||
@Query() search?: string,
|
||||
@Query() categoryId?: number
|
||||
): Promise<ListApprovedCoursesResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await RecommendedCoursesService.listApprovedCourses(token, { search, categoryId });
|
||||
return await RecommendedCoursesService.listApprovedCourses(request.user.id, { search, categoryId });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -43,9 +40,7 @@ export class RecommendedCoursesController {
|
|||
@Response('403', 'Forbidden - Admin only')
|
||||
@Response('404', 'Course not found')
|
||||
public async getCourseById(@Request() request: any, @Path() courseId: number): Promise<GetCourseByIdResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await RecommendedCoursesService.getCourseById(token, courseId);
|
||||
return await RecommendedCoursesService.getCourseById(request.user.id, courseId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -65,8 +60,6 @@ export class RecommendedCoursesController {
|
|||
@Path() courseId: number,
|
||||
@Query() is_recommended: boolean
|
||||
): Promise<ToggleRecommendedResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await RecommendedCoursesService.toggleRecommended(token, courseId, is_recommended);
|
||||
return await RecommendedCoursesService.toggleRecommended(request.user.id, courseId, is_recommended);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller, Security, Request, Put, UploadedFile } from 'tsoa';
|
||||
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Security, Request, Put, UploadedFile } from 'tsoa';
|
||||
import { ValidationError } from '../middleware/errorHandler';
|
||||
import { UserService } from '../services/user.service';
|
||||
import {
|
||||
UserResponse,
|
||||
ProfileResponse,
|
||||
ProfileUpdate,
|
||||
ProfileUpdateResponse,
|
||||
ChangePasswordRequest,
|
||||
ChangePasswordResponse,
|
||||
updateAvatarResponse,
|
||||
SendVerifyEmailResponse,
|
||||
|
|
@ -23,8 +21,6 @@ export class UserController {
|
|||
|
||||
/**
|
||||
* Get current user profile
|
||||
* @summary Retrieve authenticated user's profile information
|
||||
* @param request Express request object with JWT token in Authorization header
|
||||
*/
|
||||
@Get('me')
|
||||
@SuccessResponse('200', 'User found')
|
||||
|
|
@ -32,12 +28,7 @@ export class UserController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Security('jwt')
|
||||
public async getMe(@Request() request: any): Promise<UserResponse> {
|
||||
// Extract token from Authorization header
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.userService.getUserProfile(token);
|
||||
return await this.userService.getUserProfile(request.user.id);
|
||||
}
|
||||
|
||||
@Put('me')
|
||||
|
|
@ -47,34 +38,20 @@ export class UserController {
|
|||
@Response('400', 'Validation error')
|
||||
public async updateProfile(@Request() request: any, @Body() body: ProfileUpdate): Promise<ProfileUpdateResponse> {
|
||||
const { error } = profileUpdateSchema.validate(body);
|
||||
if (error) {
|
||||
throw new ValidationError(error.details[0].message);
|
||||
}
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.userService.updateProfile(token, body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
return await this.userService.updateProfile(request.user.id, body);
|
||||
}
|
||||
|
||||
@Get('roles')
|
||||
@Security('jwt')
|
||||
@SuccessResponse('200', 'Roles retrieved successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async getRoles(@Request() request: any): Promise<rolesResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
return await this.userService.getRoles(token);
|
||||
public async getRoles(): Promise<rolesResponse> {
|
||||
return await this.userService.getRoles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change password
|
||||
* @summary Change user password using old password
|
||||
* @param request Express request object with JWT token in Authorization header
|
||||
* @param body Old password and new password
|
||||
* @returns Success message
|
||||
*/
|
||||
@Post('change-password')
|
||||
@Security('jwt')
|
||||
|
|
@ -83,22 +60,12 @@ export class UserController {
|
|||
@Response('400', 'Validation error')
|
||||
public async changePassword(@Request() request: any, @Body() body: ChangePassword): Promise<ChangePasswordResponse> {
|
||||
const { error } = changePasswordSchema.validate(body);
|
||||
if (error) {
|
||||
throw new ValidationError(error.details[0].message);
|
||||
}
|
||||
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) {
|
||||
throw new ValidationError('No token provided');
|
||||
}
|
||||
|
||||
return await this.userService.changePassword(token, body.oldPassword, body.newPassword);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
return await this.userService.changePassword(request.user.id, body.oldPassword, body.newPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload user avatar picture
|
||||
* @param request Express request object with JWT token in Authorization header
|
||||
* @param file Avatar image file
|
||||
*/
|
||||
@Post('upload-avatar')
|
||||
@Security('jwt')
|
||||
|
|
@ -109,9 +76,6 @@ export class UserController {
|
|||
@Request() request: any,
|
||||
@UploadedFile() file: Express.Multer.File
|
||||
): Promise<updateAvatarResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
// Validate file type (images only)
|
||||
if (!file.mimetype?.startsWith('image/')) throw new ValidationError('Only image files are allowed');
|
||||
|
||||
|
|
@ -119,13 +83,11 @@ export class UserController {
|
|||
const maxSize = 5 * 1024 * 1024; // 5MB
|
||||
if (file.size > maxSize) throw new ValidationError('File size must be less than 5MB');
|
||||
|
||||
return await this.userService.uploadAvatarPicture(token, file);
|
||||
return await this.userService.uploadAvatarPicture(request.user.id, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send verification email to user
|
||||
* @summary Send email verification link to authenticated user's email
|
||||
* @param request Express request object with JWT token in Authorization header
|
||||
*/
|
||||
@Post('send-verify-email')
|
||||
@Security('jwt')
|
||||
|
|
@ -133,9 +95,7 @@ export class UserController {
|
|||
@Response('401', 'Invalid or expired token')
|
||||
@Response('400', 'Email already verified')
|
||||
public async sendVerifyEmail(@Request() request: any): Promise<SendVerifyEmailResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await this.userService.sendVerifyEmail(token);
|
||||
return await this.userService.sendVerifyEmail(request.user.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -37,10 +37,8 @@ export class AnnouncementsController {
|
|||
@Query() page?: number,
|
||||
@Query() limit?: number
|
||||
): Promise<ListAnnouncementResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await announcementsService.listAnnouncement({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
page,
|
||||
limit,
|
||||
|
|
@ -63,9 +61,6 @@ export class AnnouncementsController {
|
|||
@FormField() data: string,
|
||||
@UploadedFiles() files?: Express.Multer.File[]
|
||||
): Promise<CreateAnnouncementResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
// Parse JSON data field
|
||||
const parsed = JSON.parse(data) as CreateAnnouncementBody;
|
||||
|
||||
|
|
@ -74,7 +69,7 @@ export class AnnouncementsController {
|
|||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await announcementsService.createAnnouncement({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
title: parsed.title,
|
||||
content: parsed.content,
|
||||
|
|
@ -103,15 +98,12 @@ export class AnnouncementsController {
|
|||
@Path() announcementId: number,
|
||||
@Body() body: UpdateAnnouncementBody
|
||||
): Promise<UpdateAnnouncementResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
|
||||
// Validate body
|
||||
const { error } = UpdateAnnouncementValidator.validate(body);
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
|
||||
return await announcementsService.updateAnnouncement({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
announcement_id: announcementId,
|
||||
title: body.title,
|
||||
|
|
@ -139,10 +131,8 @@ export class AnnouncementsController {
|
|||
@Path() courseId: number,
|
||||
@Path() announcementId: number
|
||||
): Promise<DeleteAnnouncementResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await announcementsService.deleteAnnouncement({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
announcement_id: announcementId,
|
||||
});
|
||||
|
|
@ -166,10 +156,8 @@ export class AnnouncementsController {
|
|||
@Path() announcementId: number,
|
||||
@UploadedFile() file: Express.Multer.File
|
||||
): Promise<UploadAnnouncementAttachmentResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await announcementsService.uploadAttachment({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
announcement_id: announcementId,
|
||||
file: file as any,
|
||||
|
|
@ -195,10 +183,8 @@ export class AnnouncementsController {
|
|||
@Path() announcementId: number,
|
||||
@Path() attachmentId: number
|
||||
): Promise<DeleteAnnouncementAttachmentResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await announcementsService.deleteAttachment({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
announcement_id: announcementId,
|
||||
attachment_id: attachmentId,
|
||||
|
|
@ -228,10 +214,8 @@ export class AnnouncementsStudentController {
|
|||
@Query() page?: number,
|
||||
@Query() limit?: number
|
||||
): Promise<ListAnnouncementResponse> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
return await announcementsService.listAnnouncement({
|
||||
token,
|
||||
userId: request.user.id,
|
||||
course_id: courseId,
|
||||
page,
|
||||
limit,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import { prisma } from '../config/database';
|
||||
import { config } from '../config';
|
||||
import { logger } from '../config/logger';
|
||||
import { UnauthorizedError, ValidationError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { ValidationError, NotFoundError } from '../middleware/errorHandler';
|
||||
import { getPresignedUrl } from '../config/minio';
|
||||
import {
|
||||
ListPendingCoursesResponse,
|
||||
|
|
@ -18,7 +16,7 @@ export class AdminCourseApprovalService {
|
|||
/**
|
||||
* Get all pending courses for admin review
|
||||
*/
|
||||
static async listPendingCourses(token: string): Promise<ListPendingCoursesResponse> {
|
||||
static async listPendingCourses(userId: number): Promise<ListPendingCoursesResponse> {
|
||||
try {
|
||||
const courses = await prisma.course.findMany({
|
||||
where: { status: 'PENDING' },
|
||||
|
|
@ -96,9 +94,8 @@ export class AdminCourseApprovalService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to list pending courses', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: 0,
|
||||
|
|
@ -113,7 +110,7 @@ export class AdminCourseApprovalService {
|
|||
/**
|
||||
* Get course details for admin review
|
||||
*/
|
||||
static async getCourseDetail(token: string, courseId: number): Promise<GetCourseDetailForAdminResponse> {
|
||||
static async getCourseDetail(userId: number, courseId: number): Promise<GetCourseDetailForAdminResponse> {
|
||||
try {
|
||||
const course = await prisma.course.findUnique({
|
||||
where: { id: courseId },
|
||||
|
|
@ -228,9 +225,8 @@ export class AdminCourseApprovalService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to get course detail', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -245,9 +241,8 @@ export class AdminCourseApprovalService {
|
|||
/**
|
||||
* Approve a course
|
||||
*/
|
||||
static async approveCourse(token: string, courseId: number, comment?: string): Promise<ApproveCourseResponse> {
|
||||
static async approveCourse(userId: number, courseId: number, comment?: string): Promise<ApproveCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
|
||||
const course = await prisma.course.findUnique({ where: { id: courseId } });
|
||||
if (!course) {
|
||||
|
|
@ -264,7 +259,7 @@ export class AdminCourseApprovalService {
|
|||
where: { id: courseId },
|
||||
data: {
|
||||
status: 'APPROVED',
|
||||
approved_by: decoded.id,
|
||||
approved_by: userId,
|
||||
approved_at: new Date()
|
||||
}
|
||||
}),
|
||||
|
|
@ -273,7 +268,7 @@ export class AdminCourseApprovalService {
|
|||
data: {
|
||||
course_id: courseId,
|
||||
submitted_by: course.created_by,
|
||||
reviewed_by: decoded.id,
|
||||
reviewed_by: userId,
|
||||
action: 'APPROVED',
|
||||
previous_status: course.status,
|
||||
new_status: 'APPROVED',
|
||||
|
|
@ -284,7 +279,7 @@ export class AdminCourseApprovalService {
|
|||
|
||||
// Audit log - APPROVE_COURSE
|
||||
await auditService.logSync({
|
||||
userId: decoded.id,
|
||||
userId,
|
||||
action: AuditAction.APPROVE_COURSE,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -299,9 +294,8 @@ export class AdminCourseApprovalService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to approve course', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -317,9 +311,8 @@ export class AdminCourseApprovalService {
|
|||
/**
|
||||
* Reject a course
|
||||
*/
|
||||
static async rejectCourse(token: string, courseId: number, comment: string): Promise<RejectCourseResponse> {
|
||||
static async rejectCourse(userId: number, courseId: number, comment: string): Promise<RejectCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
|
||||
const course = await prisma.course.findUnique({ where: { id: courseId } });
|
||||
if (!course) {
|
||||
|
|
@ -350,7 +343,7 @@ export class AdminCourseApprovalService {
|
|||
data: {
|
||||
course_id: courseId,
|
||||
submitted_by: course.created_by,
|
||||
reviewed_by: decoded.id,
|
||||
reviewed_by: userId,
|
||||
action: 'REJECTED',
|
||||
previous_status: course.status,
|
||||
new_status: 'REJECTED',
|
||||
|
|
@ -361,7 +354,7 @@ export class AdminCourseApprovalService {
|
|||
|
||||
// Audit log - REJECT_COURSE
|
||||
await auditService.logSync({
|
||||
userId: decoded.id,
|
||||
userId,
|
||||
action: AuditAction.REJECT_COURSE,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -376,9 +369,8 @@ export class AdminCourseApprovalService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to reject course', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
|
|||
|
|
@ -59,14 +59,11 @@ import { AuditAction } from '@prisma/client';
|
|||
* ตรวจสอบสิทธิ์เข้าถึง Course (สำหรับทั้ง Instructor และ Student)
|
||||
* Returns: { hasAccess: boolean, role: 'INSTRUCTOR' | 'STUDENT' | null, userId: number }
|
||||
*/
|
||||
async function validateCourseAccess(token: string, course_id: number): Promise<{
|
||||
async function validateCourseAccess(userId: number, course_id: number): Promise<{
|
||||
hasAccess: boolean;
|
||||
role: 'INSTRUCTOR' | 'STUDENT' | null;
|
||||
userId: number;
|
||||
}> {
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const userId = decodedToken.id;
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
|
|
@ -98,9 +95,8 @@ async function validateCourseAccess(token: string, course_id: number): Promise<{
|
|||
export class ChaptersLessonService {
|
||||
async listChapters(request: ChaptersRequest): Promise<ListChaptersResponse> {
|
||||
try {
|
||||
const { token, course_id } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const { userId, course_id } = request;
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
|
|
@ -117,14 +113,13 @@ export class ChaptersLessonService {
|
|||
|
||||
async createChapter(request: CreateChapterInput): Promise<CreateChapterResponse> {
|
||||
try {
|
||||
const { token, course_id, title, description, sort_order } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, title, description, sort_order } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) {
|
||||
throw new ForbiddenError('You are not permitted to create chapter');
|
||||
}
|
||||
|
|
@ -132,7 +127,7 @@ export class ChaptersLessonService {
|
|||
|
||||
// Audit log - CREATE Chapter
|
||||
auditService.log({
|
||||
userId: decodedToken.id,
|
||||
userId: userId,
|
||||
action: AuditAction.CREATE,
|
||||
entityType: 'Chapter',
|
||||
entityId: chapter.id,
|
||||
|
|
@ -142,9 +137,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Chapter created successfully', data: chapter as ChapterData };
|
||||
} catch (error) {
|
||||
logger.error(`Error creating chapter: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Chapter',
|
||||
entityId: 0,
|
||||
|
|
@ -159,14 +153,13 @@ export class ChaptersLessonService {
|
|||
|
||||
async updateChapter(request: UpdateChapterInput): Promise<UpdateChapterResponse> {
|
||||
try {
|
||||
const { token, course_id, chapter_id, title, description, sort_order } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, chapter_id, title, description, sort_order } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) {
|
||||
throw new ForbiddenError('You are not permitted to update chapter');
|
||||
}
|
||||
|
|
@ -174,9 +167,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Chapter updated successfully', data: chapter as ChapterData };
|
||||
} catch (error) {
|
||||
logger.error(`Error updating chapter: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Chapter',
|
||||
entityId: request.chapter_id,
|
||||
|
|
@ -191,14 +183,13 @@ export class ChaptersLessonService {
|
|||
|
||||
async deleteChapter(request: DeleteChapterRequest): Promise<DeleteChapterResponse> {
|
||||
try {
|
||||
const { token, course_id, chapter_id } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, chapter_id } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) {
|
||||
throw new ForbiddenError('You are not permitted to delete chapter');
|
||||
}
|
||||
|
|
@ -206,7 +197,7 @@ export class ChaptersLessonService {
|
|||
|
||||
// Audit log - DELETE Chapter
|
||||
auditService.log({
|
||||
userId: decodedToken.id,
|
||||
userId: userId,
|
||||
action: AuditAction.DELETE,
|
||||
entityType: 'Chapter',
|
||||
entityId: chapter_id,
|
||||
|
|
@ -219,9 +210,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Chapter deleted successfully' };
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting chapter: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Chapter',
|
||||
entityId: request.chapter_id,
|
||||
|
|
@ -236,14 +226,13 @@ export class ChaptersLessonService {
|
|||
|
||||
async reorderChapter(request: ReorderChapterRequest): Promise<ReorderChapterResponse> {
|
||||
try {
|
||||
const { token, course_id, chapter_id, sort_order: newSortOrder } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, chapter_id, sort_order: newSortOrder } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) {
|
||||
throw new ForbiddenError('You are not permitted to reorder chapter');
|
||||
}
|
||||
|
|
@ -313,9 +302,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Chapter reordered successfully', data: chapters as ChapterData[] };
|
||||
} catch (error) {
|
||||
logger.error(`Error reordering chapter: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Chapter',
|
||||
entityId: request.chapter_id,
|
||||
|
|
@ -335,14 +323,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async createLesson(request: CreateLessonInput): Promise<CreateLessonResponse> {
|
||||
try {
|
||||
const { token, course_id, chapter_id, title, content, type, sort_order } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, chapter_id, title, content, type, sort_order } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) {
|
||||
throw new ForbiddenError('You are not permitted to create lesson');
|
||||
}
|
||||
|
|
@ -354,7 +341,6 @@ export class ChaptersLessonService {
|
|||
|
||||
// If QUIZ type, create empty Quiz shell
|
||||
if (type === 'QUIZ') {
|
||||
const userId = decodedToken.id;
|
||||
|
||||
await prisma.quiz.create({
|
||||
data: {
|
||||
|
|
@ -376,7 +362,7 @@ export class ChaptersLessonService {
|
|||
|
||||
// Audit log - CREATE Lesson (QUIZ)
|
||||
auditService.log({
|
||||
userId: decodedToken.id,
|
||||
userId: userId,
|
||||
action: AuditAction.CREATE,
|
||||
entityType: 'Lesson',
|
||||
entityId: lesson.id,
|
||||
|
|
@ -388,7 +374,7 @@ export class ChaptersLessonService {
|
|||
|
||||
// Audit log - CREATE Lesson
|
||||
auditService.log({
|
||||
userId: decodedToken.id,
|
||||
userId: userId,
|
||||
action: AuditAction.CREATE,
|
||||
entityType: 'Lesson',
|
||||
entityId: lesson.id,
|
||||
|
|
@ -398,9 +384,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lesson created successfully', data: lesson as LessonData };
|
||||
} catch (error) {
|
||||
logger.error(`Error creating lesson: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: 0,
|
||||
|
|
@ -419,10 +404,10 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async getLesson(request: GetLessonRequest): Promise<GetLessonResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id } = request;
|
||||
const { userId, course_id, lesson_id } = request;
|
||||
|
||||
// Check access for both instructor and enrolled student
|
||||
const access = await validateCourseAccess(token, course_id);
|
||||
const access = await validateCourseAccess(userId, course_id);
|
||||
if (!access.hasAccess) {
|
||||
throw new ForbiddenError('You do not have access to this course');
|
||||
}
|
||||
|
|
@ -549,9 +534,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lesson fetched successfully', data: lessonData as LessonData };
|
||||
} catch (error) {
|
||||
logger.error(`Error fetching lesson: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
|
|
@ -566,14 +550,13 @@ export class ChaptersLessonService {
|
|||
|
||||
async updateLesson(request: UpdateLessonRequest): Promise<UpdateLessonResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, data } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, data } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) {
|
||||
throw new ForbiddenError('You are not permitted to update lesson');
|
||||
}
|
||||
|
|
@ -581,9 +564,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lesson updated successfully', data: lesson as LessonData };
|
||||
} catch (error) {
|
||||
logger.error(`Error updating lesson: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
|
|
@ -602,14 +584,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async reorderLessons(request: ReorderLessonsRequest): Promise<ReorderLessonsResponse> {
|
||||
try {
|
||||
const { token, course_id, chapter_id, lesson_id, sort_order: newSortOrder } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, chapter_id, lesson_id, sort_order: newSortOrder } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to reorder lessons');
|
||||
|
||||
// Verify chapter exists and belongs to the course
|
||||
|
|
@ -682,9 +663,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lessons reordered successfully', data: lessons as LessonData[] };
|
||||
} catch (error) {
|
||||
logger.error(`Error reordering lessons: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
|
|
@ -704,14 +684,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async deleteLesson(request: DeleteLessonRequest): Promise<DeleteLessonResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to delete this lesson');
|
||||
|
||||
// Fetch lesson with all related data
|
||||
|
|
@ -751,7 +730,7 @@ export class ChaptersLessonService {
|
|||
|
||||
// Audit log - DELETE Lesson
|
||||
auditService.log({
|
||||
userId: decodedToken.id,
|
||||
userId: userId,
|
||||
action: AuditAction.DELETE,
|
||||
entityType: 'Lesson',
|
||||
entityId: lesson_id,
|
||||
|
|
@ -764,9 +743,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lesson deleted successfully' };
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting lesson: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
|
|
@ -789,14 +767,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async uploadVideo(request: UploadVideoInput): Promise<VideoOperationResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, video } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, video } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists and is VIDEO type
|
||||
|
|
@ -833,7 +810,7 @@ export class ChaptersLessonService {
|
|||
|
||||
// Audit log - UPLOAD_FILE (Video)
|
||||
auditService.log({
|
||||
userId: decodedToken.id,
|
||||
userId: userId,
|
||||
action: AuditAction.UPLOAD_FILE,
|
||||
entityType: 'Lesson',
|
||||
entityId: lesson_id,
|
||||
|
|
@ -853,9 +830,8 @@ export class ChaptersLessonService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error uploading video: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
|
|
@ -874,14 +850,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async updateVideo(request: UpdateVideoInput): Promise<VideoOperationResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, video } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, video } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists and is VIDEO type
|
||||
|
|
@ -946,9 +921,8 @@ export class ChaptersLessonService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error updating video: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
|
|
@ -967,14 +941,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async setYouTubeVideo(request: SetYouTubeVideoInput): Promise<YouTubeVideoResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, youtube_video_id, video_title } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, youtube_video_id, video_title } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists and is VIDEO type
|
||||
|
|
@ -1038,9 +1011,8 @@ export class ChaptersLessonService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error setting YouTube video: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
|
|
@ -1059,14 +1031,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async uploadAttachment(request: UploadAttachmentInput): Promise<AttachmentOperationResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, attachment } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, attachment } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists
|
||||
|
|
@ -1101,7 +1072,7 @@ export class ChaptersLessonService {
|
|||
|
||||
// Audit log - UPLOAD_FILE (Attachment)
|
||||
auditService.log({
|
||||
userId: decodedToken.id,
|
||||
userId: userId,
|
||||
action: AuditAction.UPLOAD_FILE,
|
||||
entityType: 'LessonAttachment',
|
||||
entityId: newAttachment.id,
|
||||
|
|
@ -1125,9 +1096,8 @@ export class ChaptersLessonService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error uploading attachment: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'LessonAttachment',
|
||||
entityId: request.lesson_id,
|
||||
|
|
@ -1146,14 +1116,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async deleteAttachment(request: DeleteAttachmentInput): Promise<DeleteAttachmentResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, attachment_id } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, attachment_id } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists
|
||||
|
|
@ -1184,7 +1153,7 @@ export class ChaptersLessonService {
|
|||
|
||||
// Audit log - DELETE_FILE (Attachment)
|
||||
auditService.log({
|
||||
userId: decodedToken.id,
|
||||
userId: userId,
|
||||
action: AuditAction.DELETE_FILE,
|
||||
entityType: 'LessonAttachment',
|
||||
entityId: attachment_id,
|
||||
|
|
@ -1194,9 +1163,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Attachment deleted successfully' };
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting attachment: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'LessonAttachment',
|
||||
entityId: request.attachment_id,
|
||||
|
|
@ -1216,14 +1184,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async addQuestion(request: AddQuestionInput): Promise<AddQuestionResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, question, explanation, question_type, sort_order, choices } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, question, explanation, question_type, sort_order, choices } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists and is QUIZ type
|
||||
|
|
@ -1281,9 +1248,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Question added successfully', data: completeQuestion as QuizQuestionData };
|
||||
} catch (error) {
|
||||
logger.error(`Error adding question: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Question',
|
||||
entityId: 0,
|
||||
|
|
@ -1303,14 +1269,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async updateQuestion(request: UpdateQuestionInput): Promise<UpdateQuestionResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, question_id, question, explanation, question_type, sort_order, choices } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, question_id, question, explanation, question_type, sort_order, choices } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists and is QUIZ type
|
||||
|
|
@ -1367,9 +1332,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Question updated successfully', data: completeQuestion as QuizQuestionData };
|
||||
} catch (error) {
|
||||
logger.error(`Error updating question: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Question',
|
||||
entityId: request.question_id,
|
||||
|
|
@ -1384,14 +1348,13 @@ export class ChaptersLessonService {
|
|||
|
||||
async reorderQuestion(request: ReorderQuestionInput): Promise<ReorderQuestionResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, question_id, sort_order } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, question_id, sort_order } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists and is QUIZ type
|
||||
|
|
@ -1471,9 +1434,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Question reordered successfully', data: questions as QuizQuestionData[] };
|
||||
} catch (error) {
|
||||
logger.error(`Error reordering question: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Question',
|
||||
entityId: request.question_id,
|
||||
|
|
@ -1493,14 +1455,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async deleteQuestion(request: DeleteQuestionInput): Promise<DeleteQuestionResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, question_id } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, question_id } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists and is QUIZ type
|
||||
|
|
@ -1530,9 +1491,8 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Question deleted successfully' };
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting question: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
userId: request.userId || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Question',
|
||||
entityId: request.question_id,
|
||||
|
|
@ -1680,14 +1640,13 @@ export class ChaptersLessonService {
|
|||
*/
|
||||
async updateQuiz(request: UpdateQuizInput): Promise<UpdateQuizResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, title, description, passing_score, time_limit, shuffle_questions, shuffle_choices, show_answers_after_completion, is_skippable, allow_multiple_attempts } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, title, description, passing_score, time_limit, shuffle_questions, shuffle_choices, show_answers_after_completion, is_skippable, allow_multiple_attempts } = request;
|
||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||
|
||||
// Verify lesson exists and is QUIZ type
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
import { prisma } from '../config/database';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { config } from '../config';
|
||||
import { logger } from '../config/logger';
|
||||
import { UnauthorizedError, ValidationError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { ValidationError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
||||
import { uploadFile, deleteFile, getPresignedUrl } from '../config/minio';
|
||||
import {
|
||||
CreateCourseInput,
|
||||
|
|
@ -27,6 +25,7 @@ import {
|
|||
SearchInstructorResponse,
|
||||
GetEnrolledStudentsInput,
|
||||
GetEnrolledStudentsResponse,
|
||||
EnrolledStudentData,
|
||||
GetQuizScoresInput,
|
||||
GetQuizScoresResponse,
|
||||
GetQuizAttemptDetailInput,
|
||||
|
|
@ -38,6 +37,7 @@ import {
|
|||
CloneCourseResponse,
|
||||
setCourseDraft,
|
||||
setCourseDraftResponse,
|
||||
GetAllMyStudentsResponse,
|
||||
} from "../types/CoursesInstructor.types";
|
||||
import { auditService } from './audit.service';
|
||||
import { AuditAction } from '@prisma/client';
|
||||
|
|
@ -121,10 +121,9 @@ export class CoursesInstructorService {
|
|||
|
||||
static async listMyCourses(input: ListMyCoursesInput): Promise<ListMyCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(input.token, config.jwt.secret) as { id: number; type: string };
|
||||
const courseInstructors = await prisma.courseInstructor.findMany({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: input.userId,
|
||||
course: input.status ? { status: input.status } : undefined
|
||||
},
|
||||
include: {
|
||||
|
|
@ -157,9 +156,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to retrieve courses', { error });
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: 0,
|
||||
|
|
@ -174,12 +172,10 @@ export class CoursesInstructorService {
|
|||
|
||||
static async getmyCourse(getmyCourse: getmyCourse): Promise<GetMyCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(getmyCourse.token, config.jwt.secret) as { id: number; type: string };
|
||||
|
||||
// Check if user is instructor of this course
|
||||
const courseInstructor = await prisma.courseInstructor.findFirst({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: getmyCourse.userId,
|
||||
course_id: getmyCourse.course_id
|
||||
},
|
||||
include: {
|
||||
|
|
@ -225,9 +221,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to retrieve course', { error });
|
||||
const decoded = jwt.decode(getmyCourse.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: getmyCourse.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: getmyCourse.course_id,
|
||||
|
|
@ -240,9 +235,9 @@ export class CoursesInstructorService {
|
|||
}
|
||||
}
|
||||
|
||||
static async updateCourse(token: string, courseId: number, courseData: UpdateCourseInput): Promise<createCourseResponse> {
|
||||
static async updateCourse(userId: number, courseId: number, courseData: UpdateCourseInput): Promise<createCourseResponse> {
|
||||
try {
|
||||
await this.validateCourseInstructor(token, courseId);
|
||||
await this.validateCourseInstructor(userId, courseId);
|
||||
|
||||
const course = await prisma.course.update({
|
||||
where: {
|
||||
|
|
@ -258,9 +253,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to update course', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -273,9 +267,9 @@ export class CoursesInstructorService {
|
|||
}
|
||||
}
|
||||
|
||||
static async uploadThumbnail(token: string, courseId: number, file: Express.Multer.File): Promise<{ code: number; message: string; data: { course_id: number; thumbnail_url: string } }> {
|
||||
static async uploadThumbnail(userId: number, courseId: number, file: Express.Multer.File): Promise<{ code: number; message: string; data: { course_id: number; thumbnail_url: string } }> {
|
||||
try {
|
||||
await this.validateCourseInstructor(token, courseId);
|
||||
await this.validateCourseInstructor(userId, courseId);
|
||||
|
||||
// Get current course to check for existing thumbnail
|
||||
const currentCourse = await prisma.course.findUnique({
|
||||
|
|
@ -322,9 +316,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to upload thumbnail', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -337,9 +330,9 @@ export class CoursesInstructorService {
|
|||
}
|
||||
}
|
||||
|
||||
static async deleteCourse(token: string, courseId: number): Promise<createCourseResponse> {
|
||||
static async deleteCourse(userId: number, courseId: number): Promise<createCourseResponse> {
|
||||
try {
|
||||
const courseInstructorId = await this.validateCourseInstructor(token, courseId);
|
||||
const courseInstructorId = await this.validateCourseInstructor(userId, courseId);
|
||||
if (!courseInstructorId.is_primary) {
|
||||
throw new ForbiddenError('You have no permission to delete this course');
|
||||
}
|
||||
|
|
@ -365,9 +358,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to delete course', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -382,11 +374,10 @@ export class CoursesInstructorService {
|
|||
|
||||
static async sendCourseForReview(sendCourseForReview: sendCourseForReview): Promise<submitCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(sendCourseForReview.token, config.jwt.secret) as { id: number; type: string };
|
||||
await prisma.courseApproval.create({
|
||||
data: {
|
||||
course_id: sendCourseForReview.course_id,
|
||||
submitted_by: decoded.id,
|
||||
submitted_by: sendCourseForReview.userId,
|
||||
}
|
||||
});
|
||||
await prisma.course.update({
|
||||
|
|
@ -398,7 +389,7 @@ export class CoursesInstructorService {
|
|||
}
|
||||
});
|
||||
await auditService.logSync({
|
||||
userId: decoded.id,
|
||||
userId: sendCourseForReview.userId,
|
||||
action: AuditAction.UPDATE,
|
||||
entityType: 'Course',
|
||||
entityId: sendCourseForReview.course_id,
|
||||
|
|
@ -412,9 +403,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to send course for review', { error });
|
||||
const decoded = jwt.decode(sendCourseForReview.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: sendCourseForReview.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: sendCourseForReview.course_id,
|
||||
|
|
@ -429,7 +419,7 @@ export class CoursesInstructorService {
|
|||
|
||||
static async setCourseDraft(setCourseDraft: setCourseDraft): Promise<setCourseDraftResponse> {
|
||||
try {
|
||||
await this.validateCourseInstructor(setCourseDraft.token, setCourseDraft.course_id);
|
||||
await this.validateCourseInstructor(setCourseDraft.userId, setCourseDraft.course_id);
|
||||
await prisma.course.update({
|
||||
where: {
|
||||
id: setCourseDraft.course_id,
|
||||
|
|
@ -445,9 +435,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to set course to draft', { error });
|
||||
const decoded = jwt.decode(setCourseDraft.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: setCourseDraft.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: setCourseDraft.course_id,
|
||||
|
|
@ -460,7 +449,7 @@ export class CoursesInstructorService {
|
|||
}
|
||||
}
|
||||
|
||||
static async getCourseApprovals(token: string, courseId: number): Promise<{
|
||||
static async getCourseApprovals(userId: number, courseId: number): Promise<{
|
||||
code: number;
|
||||
message: string;
|
||||
data: any[];
|
||||
|
|
@ -468,7 +457,7 @@ export class CoursesInstructorService {
|
|||
}> {
|
||||
try {
|
||||
// Validate instructor access
|
||||
await this.validateCourseInstructor(token, courseId);
|
||||
await this.validateCourseInstructor(userId, courseId);
|
||||
|
||||
const approvals = await prisma.courseApproval.findMany({
|
||||
where: { course_id: courseId },
|
||||
|
|
@ -491,9 +480,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to retrieve course approvals', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -510,8 +498,6 @@ export class CoursesInstructorService {
|
|||
|
||||
static async searchInstructors(input: SearchInstructorInput): Promise<SearchInstructorResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(input.token, config.jwt.secret) as { id: number };
|
||||
|
||||
// Get existing instructors in the course
|
||||
const existingInstructors = await prisma.courseInstructor.findMany({
|
||||
where: { course_id: input.course_id },
|
||||
|
|
@ -528,7 +514,7 @@ export class CoursesInstructorService {
|
|||
],
|
||||
role: { code: 'INSTRUCTOR' },
|
||||
id: {
|
||||
notIn: [decoded.id, ...existingInstructorIds],
|
||||
notIn: [input.userId, ...existingInstructorIds],
|
||||
},
|
||||
},
|
||||
include: {
|
||||
|
|
@ -563,9 +549,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to search instructors', { error });
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: input.course_id,
|
||||
|
|
@ -581,7 +566,7 @@ export class CoursesInstructorService {
|
|||
static async addInstructorToCourse(addinstructorCourse: addinstructorCourse): Promise<addinstructorCourseResponse> {
|
||||
try {
|
||||
// Validate user is instructor of this course
|
||||
await this.validateCourseInstructor(addinstructorCourse.token, addinstructorCourse.course_id);
|
||||
await this.validateCourseInstructor(addinstructorCourse.userId, addinstructorCourse.course_id);
|
||||
|
||||
// Find user by email or username
|
||||
const user = await prisma.user.findFirst({
|
||||
|
|
@ -619,9 +604,8 @@ export class CoursesInstructorService {
|
|||
}
|
||||
});
|
||||
|
||||
const decoded = jwt.decode(addinstructorCourse.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: addinstructorCourse.userId,
|
||||
action: AuditAction.CREATE,
|
||||
entityType: 'Course',
|
||||
entityId: addinstructorCourse.course_id,
|
||||
|
|
@ -637,9 +621,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to add instructor to course', { error });
|
||||
const decoded = jwt.decode(addinstructorCourse.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: addinstructorCourse.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: addinstructorCourse.course_id,
|
||||
|
|
@ -654,7 +637,6 @@ export class CoursesInstructorService {
|
|||
|
||||
static async removeInstructorFromCourse(removeinstructorCourse: removeinstructorCourse): Promise<removeinstructorCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(removeinstructorCourse.token, config.jwt.secret) as { id: number; type: string };
|
||||
await prisma.courseInstructor.delete({
|
||||
where: {
|
||||
course_id_user_id: {
|
||||
|
|
@ -665,7 +647,7 @@ export class CoursesInstructorService {
|
|||
});
|
||||
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: removeinstructorCourse.userId,
|
||||
action: AuditAction.DELETE,
|
||||
entityType: 'Course',
|
||||
entityId: removeinstructorCourse.course_id,
|
||||
|
|
@ -682,9 +664,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to remove instructor from course', { error });
|
||||
const decoded = jwt.decode(removeinstructorCourse.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: removeinstructorCourse.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: removeinstructorCourse.course_id,
|
||||
|
|
@ -699,7 +680,6 @@ export class CoursesInstructorService {
|
|||
|
||||
static async listInstructorsOfCourse(listinstructorCourse: listinstructorCourse): Promise<listinstructorCourseResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(listinstructorCourse.token, config.jwt.secret) as { id: number; type: string };
|
||||
const courseInstructors = await prisma.courseInstructor.findMany({
|
||||
where: {
|
||||
course_id: listinstructorCourse.course_id,
|
||||
|
|
@ -743,9 +723,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to retrieve instructors of course', { error });
|
||||
const decoded = jwt.decode(listinstructorCourse.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: listinstructorCourse.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: listinstructorCourse.course_id,
|
||||
|
|
@ -760,7 +739,6 @@ export class CoursesInstructorService {
|
|||
|
||||
static async setPrimaryInstructor(setprimaryCourseInstructor: setprimaryCourseInstructor): Promise<setprimaryCourseInstructorResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(setprimaryCourseInstructor.token, config.jwt.secret) as { id: number; type: string };
|
||||
await prisma.courseInstructor.update({
|
||||
where: {
|
||||
course_id_user_id: {
|
||||
|
|
@ -774,7 +752,7 @@ export class CoursesInstructorService {
|
|||
});
|
||||
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: setprimaryCourseInstructor.userId,
|
||||
action: AuditAction.UPDATE,
|
||||
entityType: 'Course',
|
||||
entityId: setprimaryCourseInstructor.course_id,
|
||||
|
|
@ -791,9 +769,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to set primary instructor', { error });
|
||||
const decoded = jwt.decode(setprimaryCourseInstructor.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: setprimaryCourseInstructor.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: setprimaryCourseInstructor.course_id,
|
||||
|
|
@ -806,11 +783,10 @@ export class CoursesInstructorService {
|
|||
}
|
||||
}
|
||||
|
||||
static async validateCourseInstructor(token: string, courseId: number): Promise<{ user_id: number; is_primary: boolean }> {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
||||
static async validateCourseInstructor(userId: number, courseId: number): Promise<{ user_id: number; is_primary: boolean }> {
|
||||
const courseInstructor = await prisma.courseInstructor.findFirst({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id: courseId
|
||||
}
|
||||
});
|
||||
|
|
@ -839,10 +815,10 @@ export class CoursesInstructorService {
|
|||
*/
|
||||
static async getEnrolledStudents(input: GetEnrolledStudentsInput): Promise<GetEnrolledStudentsResponse> {
|
||||
try {
|
||||
const { token, course_id, page = 1, limit = 20, search, status } = input;
|
||||
const { userId, course_id, page = 1, limit = 20, search, status } = input;
|
||||
|
||||
// Validate instructor
|
||||
await this.validateCourseInstructor(token, course_id);
|
||||
await this.validateCourseInstructor(userId, course_id);
|
||||
|
||||
// Build where clause
|
||||
const whereClause: any = { course_id };
|
||||
|
|
@ -917,9 +893,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error getting enrolled students: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: input.course_id,
|
||||
|
|
@ -938,11 +913,10 @@ export class CoursesInstructorService {
|
|||
*/
|
||||
static async getQuizScores(input: GetQuizScoresInput): Promise<GetQuizScoresResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, page = 1, limit = 20, search, is_passed } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, lesson_id, page = 1, limit = 20, search, is_passed } = input;
|
||||
|
||||
// Validate instructor
|
||||
await this.validateCourseInstructor(token, course_id);
|
||||
await this.validateCourseInstructor(userId, course_id);
|
||||
|
||||
// Get lesson and verify it's a QUIZ type
|
||||
const lesson = await prisma.lesson.findUnique({
|
||||
|
|
@ -1095,9 +1069,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error getting quiz scores: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: input.course_id,
|
||||
|
|
@ -1116,10 +1089,10 @@ export class CoursesInstructorService {
|
|||
*/
|
||||
static async getQuizAttemptDetail(input: GetQuizAttemptDetailInput): Promise<GetQuizAttemptDetailResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, student_id } = input;
|
||||
const { userId, course_id, lesson_id, student_id } = input;
|
||||
|
||||
// Validate instructor
|
||||
await this.validateCourseInstructor(token, course_id);
|
||||
await this.validateCourseInstructor(userId, course_id);
|
||||
|
||||
// Get lesson and verify it's a QUIZ type
|
||||
const lesson = await prisma.lesson.findUnique({
|
||||
|
|
@ -1219,9 +1192,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error getting quiz attempt detail: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: input.course_id,
|
||||
|
|
@ -1240,10 +1212,10 @@ export class CoursesInstructorService {
|
|||
*/
|
||||
static async getEnrolledStudentDetail(input: GetEnrolledStudentDetailInput): Promise<GetEnrolledStudentDetailResponse> {
|
||||
try {
|
||||
const { token, course_id, student_id } = input;
|
||||
const { userId, course_id, student_id } = input;
|
||||
|
||||
// Validate instructor
|
||||
await this.validateCourseInstructor(token, course_id);
|
||||
await this.validateCourseInstructor(userId, course_id);
|
||||
|
||||
// Get student info
|
||||
const student = await prisma.user.findUnique({
|
||||
|
|
@ -1367,9 +1339,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error getting enrolled student detail: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: input.course_id,
|
||||
|
|
@ -1386,12 +1357,10 @@ export class CoursesInstructorService {
|
|||
* ดึงประวัติการขออนุมัติคอร์ส
|
||||
* Get course approval history for instructor to see rejection reasons
|
||||
*/
|
||||
static async getCourseApprovalHistory(token: string, courseId: number): Promise<GetCourseApprovalHistoryResponse> {
|
||||
static async getCourseApprovalHistory(userId: number, courseId: number): Promise<GetCourseApprovalHistoryResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
|
||||
// Validate instructor access
|
||||
await this.validateCourseInstructor(token, courseId);
|
||||
await this.validateCourseInstructor(userId, courseId);
|
||||
|
||||
// Get course with approval history
|
||||
const course = await prisma.course.findUnique({
|
||||
|
|
@ -1434,9 +1403,8 @@ export class CoursesInstructorService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error getting course approval history: ${error}`);
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || undefined,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -1454,11 +1422,10 @@ export class CoursesInstructorService {
|
|||
*/
|
||||
static async cloneCourse(input: CloneCourseInput): Promise<CloneCourseResponse> {
|
||||
try {
|
||||
const { token, course_id, title } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, title } = input;
|
||||
|
||||
// Validate instructor
|
||||
const courseInstructor = await this.validateCourseInstructor(token, course_id);
|
||||
const courseInstructor = await this.validateCourseInstructor(userId, course_id);
|
||||
if (!courseInstructor) {
|
||||
throw new ForbiddenError('You are not an instructor of this course');
|
||||
}
|
||||
|
|
@ -1508,7 +1475,7 @@ export class CoursesInstructorService {
|
|||
is_free: originalCourse.is_free,
|
||||
have_certificate: originalCourse.have_certificate,
|
||||
status: 'DRAFT', // Reset status
|
||||
created_by: decoded.id
|
||||
created_by: userId
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -1516,7 +1483,7 @@ export class CoursesInstructorService {
|
|||
await tx.courseInstructor.create({
|
||||
data: {
|
||||
course_id: createdCourse.id,
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
is_primary: true
|
||||
}
|
||||
});
|
||||
|
|
@ -1589,7 +1556,7 @@ export class CoursesInstructorService {
|
|||
shuffle_questions: lesson.quiz.shuffle_questions,
|
||||
shuffle_choices: lesson.quiz.shuffle_choices,
|
||||
show_answers_after_completion: lesson.quiz.show_answers_after_completion,
|
||||
created_by: decoded.id
|
||||
created_by: userId
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -1636,7 +1603,7 @@ export class CoursesInstructorService {
|
|||
});
|
||||
|
||||
await auditService.logSync({
|
||||
userId: decoded.id,
|
||||
userId: input.userId,
|
||||
action: AuditAction.CREATE,
|
||||
entityType: 'Course',
|
||||
entityId: newCourse.id,
|
||||
|
|
@ -1658,9 +1625,8 @@ export class CoursesInstructorService {
|
|||
|
||||
} catch (error) {
|
||||
logger.error(`Error cloning course: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Course',
|
||||
entityId: input.course_id,
|
||||
|
|
@ -1672,4 +1638,45 @@ export class CoursesInstructorService {
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ดึงผู้เรียนทั้งหมดในทุกคอร์สของ instructor
|
||||
* Get all enrolled students across all courses the instructor owns/teaches
|
||||
*/
|
||||
static async getMyAllStudents(userId: number): Promise<GetAllMyStudentsResponse> {
|
||||
try {
|
||||
// หา course IDs ทั้งหมดที่ instructor สอน
|
||||
const instructorCourses = await prisma.courseInstructor.findMany({
|
||||
where: { user_id: userId },
|
||||
select: { course_id: true }
|
||||
});
|
||||
|
||||
const courseIds = instructorCourses.map(ci => ci.course_id);
|
||||
|
||||
if (courseIds.length === 0) {
|
||||
return { code: 200, message: 'Students retrieved successfully', total_students: 0, total_completed: 0 };
|
||||
}
|
||||
|
||||
// unique students ทั้งหมด
|
||||
const uniqueStudents = await prisma.enrollment.groupBy({
|
||||
by: ['user_id'],
|
||||
where: { course_id: { in: courseIds } },
|
||||
});
|
||||
|
||||
// จำนวน enrollment ที่ COMPLETED
|
||||
const totalCompleted = await prisma.enrollment.count({
|
||||
where: { course_id: { in: courseIds }, status: 'COMPLETED' }
|
||||
});
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
message: 'Students retrieved successfully',
|
||||
total_students: uniqueStudents.length,
|
||||
total_completed: totalCompleted,
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error getting all students: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ export class CoursesStudentService {
|
|||
async enrollCourse(input: EnrollCourseInput): Promise<EnrollCourseResponse> {
|
||||
try {
|
||||
const { course_id } = input;
|
||||
const decoded = jwt.verify(input.token, config.jwt.secret) as { id: number; type: string };
|
||||
const userId = input.userId;
|
||||
|
||||
const course = await prisma.course.findUnique({
|
||||
where: { id: course_id },
|
||||
|
|
@ -146,7 +146,7 @@ export class CoursesStudentService {
|
|||
const existingEnrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -159,7 +159,7 @@ export class CoursesStudentService {
|
|||
const enrollment = await prisma.enrollment.create({
|
||||
data: {
|
||||
course_id,
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
status: 'ENROLLED',
|
||||
enrolled_at: new Date(),
|
||||
},
|
||||
|
|
@ -167,11 +167,11 @@ export class CoursesStudentService {
|
|||
|
||||
// Audit log - ENROLL
|
||||
auditService.log({
|
||||
userId: decoded.id,
|
||||
userId: userId,
|
||||
action: AuditAction.ENROLL,
|
||||
entityType: 'Enrollment',
|
||||
entityId: enrollment.id,
|
||||
newValue: { course_id, user_id: decoded.id, status: 'ENROLLED' }
|
||||
newValue: { course_id, user_id: userId, status: 'ENROLLED' }
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
@ -187,9 +187,9 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error enrolling in course: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Enrollment',
|
||||
entityId: 0,
|
||||
|
|
@ -206,13 +206,13 @@ export class CoursesStudentService {
|
|||
|
||||
async GetEnrolledCourses(input: ListEnrolledCoursesInput): Promise<ListEnrolledCoursesResponse> {
|
||||
try {
|
||||
const { token } = input;
|
||||
// destructure input
|
||||
const page = input.page ?? 1;
|
||||
const limit = input.limit ?? 20;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
||||
const userId = input.userId;
|
||||
const enrollments = await prisma.enrollment.findMany({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
},
|
||||
include: {
|
||||
course: {
|
||||
|
|
@ -230,7 +230,7 @@ export class CoursesStudentService {
|
|||
});
|
||||
const total = await prisma.enrollment.count({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -274,9 +274,9 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Enrollment',
|
||||
entityId: 0,
|
||||
|
|
@ -290,8 +290,8 @@ export class CoursesStudentService {
|
|||
}
|
||||
async getCourseLearning(input: GetCourseLearningInput): Promise<GetCourseLearningResponse> {
|
||||
try {
|
||||
const { token, course_id } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
||||
const { course_id } = input;
|
||||
const userId = input.userId;
|
||||
|
||||
// Get course with chapters and lessons (basic info only)
|
||||
const course = await prisma.course.findUnique({
|
||||
|
|
@ -330,7 +330,7 @@ export class CoursesStudentService {
|
|||
const enrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -345,7 +345,7 @@ export class CoursesStudentService {
|
|||
prisma.enrollment.update({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -357,7 +357,7 @@ export class CoursesStudentService {
|
|||
const lessonIds = course.chapters.flatMap(ch => ch.lessons.map(l => l.id));
|
||||
const lessonProgress = await prisma.lessonProgress.findMany({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
lesson_id: { in: lessonIds },
|
||||
},
|
||||
});
|
||||
|
|
@ -453,9 +453,9 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Enrollment',
|
||||
entityId: 0,
|
||||
|
|
@ -470,8 +470,8 @@ export class CoursesStudentService {
|
|||
|
||||
async getlessonContent(input: GetLessonContentInput): Promise<GetLessonContentResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
||||
const { course_id, lesson_id } = input;
|
||||
const userId = input.userId;
|
||||
|
||||
// Import MinIO functions
|
||||
|
||||
|
|
@ -479,7 +479,7 @@ export class CoursesStudentService {
|
|||
const enrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -528,7 +528,7 @@ export class CoursesStudentService {
|
|||
const lessonProgress = await prisma.lessonProgress.findUnique({
|
||||
where: {
|
||||
user_id_lesson_id: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
lesson_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -639,7 +639,7 @@ export class CoursesStudentService {
|
|||
// Get latest quiz attempt for this user
|
||||
latestQuizAttempt = await prisma.quizAttempt.findFirst({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
quiz_id: lesson.quiz.id,
|
||||
},
|
||||
orderBy: {
|
||||
|
|
@ -726,9 +726,9 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Enrollment',
|
||||
entityId: 0,
|
||||
|
|
@ -744,14 +744,14 @@ export class CoursesStudentService {
|
|||
|
||||
async checkAccessLesson(input: CheckLessonAccessInput): Promise<CheckLessonAccessResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
||||
const { course_id, lesson_id } = input;
|
||||
const userId = input.userId;
|
||||
|
||||
// Check enrollment
|
||||
const enrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -845,7 +845,7 @@ export class CoursesStudentService {
|
|||
// Get user's progress for prerequisite lessons
|
||||
const prerequisiteProgress = await prisma.lessonProgress.findMany({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
lesson_id: { in: prerequisiteIds },
|
||||
},
|
||||
});
|
||||
|
|
@ -879,7 +879,7 @@ export class CoursesStudentService {
|
|||
// Check if user passed the quiz
|
||||
const quizAttempt = await prisma.quizAttempt.findFirst({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
quiz_id: prereqLesson.quiz.id,
|
||||
is_passed: true,
|
||||
},
|
||||
|
|
@ -925,9 +925,9 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Enrollment',
|
||||
entityId: 0,
|
||||
|
|
@ -942,8 +942,8 @@ export class CoursesStudentService {
|
|||
|
||||
async getVideoProgress(input: GetVideoProgressInput): Promise<GetVideoProgressResponse> {
|
||||
try {
|
||||
const { token, lesson_id } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
||||
const { lesson_id } = input;
|
||||
const userId = input.userId;
|
||||
|
||||
// Get lesson to find course_id
|
||||
const lesson = await prisma.lesson.findUnique({
|
||||
|
|
@ -966,7 +966,7 @@ export class CoursesStudentService {
|
|||
const enrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -980,7 +980,7 @@ export class CoursesStudentService {
|
|||
const progress = await prisma.lessonProgress.findUnique({
|
||||
where: {
|
||||
user_id_lesson_id: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
lesson_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -1010,9 +1010,9 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Enrollment',
|
||||
entityId: 0,
|
||||
|
|
@ -1027,8 +1027,8 @@ export class CoursesStudentService {
|
|||
|
||||
async saveVideoProgress(input: SaveVideoProgressInput): Promise<SaveVideoProgressResponse> {
|
||||
try {
|
||||
const { token, lesson_id, video_progress_seconds, video_duration_seconds } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
||||
const { lesson_id, video_progress_seconds, video_duration_seconds } = input;
|
||||
const userId = input.userId;
|
||||
|
||||
// Get lesson to find course_id
|
||||
const lesson = await prisma.lesson.findUnique({
|
||||
|
|
@ -1051,7 +1051,7 @@ export class CoursesStudentService {
|
|||
const enrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -1074,12 +1074,12 @@ export class CoursesStudentService {
|
|||
const progress = await prisma.lessonProgress.upsert({
|
||||
where: {
|
||||
user_id_lesson_id: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
lesson_id,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
lesson_id,
|
||||
video_progress_seconds,
|
||||
video_duration_seconds: video_duration_seconds ?? null,
|
||||
|
|
@ -1098,7 +1098,7 @@ export class CoursesStudentService {
|
|||
// If video completed, mark lesson as complete and update enrollment progress
|
||||
let enrollmentProgress: { progress_percentage: number; is_course_completed: boolean } | undefined;
|
||||
if (isCompleted) {
|
||||
const result = await this.markLessonComplete(decoded.id, lesson_id, course_id);
|
||||
const result = await this.markLessonComplete(userId, lesson_id, course_id);
|
||||
enrollmentProgress = result.enrollmentProgress;
|
||||
}
|
||||
|
||||
|
|
@ -1118,9 +1118,9 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Enrollment',
|
||||
entityId: 0,
|
||||
|
|
@ -1135,8 +1135,8 @@ export class CoursesStudentService {
|
|||
|
||||
async completeLesson(input: CompleteLessonInput): Promise<CompleteLessonResponse> {
|
||||
try {
|
||||
const { token, lesson_id } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
||||
const { lesson_id } = input;
|
||||
const userId = input.userId;
|
||||
|
||||
// Get lesson with chapter and course info
|
||||
const lesson = await prisma.lesson.findUnique({
|
||||
|
|
@ -1185,7 +1185,7 @@ export class CoursesStudentService {
|
|||
const enrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -1196,7 +1196,7 @@ export class CoursesStudentService {
|
|||
}
|
||||
|
||||
// Mark lesson as complete and update enrollment progress
|
||||
const { lessonProgress, enrollmentProgress } = await this.markLessonComplete(decoded.id, lesson_id, course_id);
|
||||
const { lessonProgress, enrollmentProgress } = await this.markLessonComplete(userId, lesson_id, course_id);
|
||||
const { progress_percentage: course_progress_percentage, is_course_completed } = enrollmentProgress;
|
||||
|
||||
// Find next lesson
|
||||
|
|
@ -1225,7 +1225,7 @@ export class CoursesStudentService {
|
|||
// Check if certificate already exists
|
||||
const existingCertificate = await prisma.certificate.findFirst({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
});
|
||||
|
|
@ -1233,10 +1233,10 @@ export class CoursesStudentService {
|
|||
if (!existingCertificate) {
|
||||
await prisma.certificate.create({
|
||||
data: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
enrollment_id: enrollment.id,
|
||||
file_path: `certificates/${course_id}/${decoded.id}/${Date.now()}.pdf`,
|
||||
file_path: `certificates/${course_id}/${userId}/${Date.now()}.pdf`,
|
||||
issued_at: new Date(),
|
||||
},
|
||||
});
|
||||
|
|
@ -1261,9 +1261,9 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error completing lesson: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'LessonProgress',
|
||||
entityId: input.lesson_id,
|
||||
|
|
@ -1283,14 +1283,14 @@ export class CoursesStudentService {
|
|||
*/
|
||||
async submitQuiz(input: SubmitQuizInput): Promise<SubmitQuizResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id, answers } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { course_id, lesson_id, answers } = input;
|
||||
const userId = input.userId;
|
||||
|
||||
// Check enrollment
|
||||
const enrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -1331,7 +1331,7 @@ export class CoursesStudentService {
|
|||
// Get previous attempt count
|
||||
const previousAttempts = await prisma.quizAttempt.count({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
quiz_id: quiz.id,
|
||||
},
|
||||
});
|
||||
|
|
@ -1384,7 +1384,7 @@ export class CoursesStudentService {
|
|||
const now = new Date();
|
||||
const quizAttempt = await prisma.quizAttempt.create({
|
||||
data: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
quiz_id: quiz.id,
|
||||
score: earnedScore,
|
||||
total_questions: quiz.questions.length,
|
||||
|
|
@ -1400,7 +1400,7 @@ export class CoursesStudentService {
|
|||
// If passed, mark lesson as complete and update enrollment progress
|
||||
let enrollmentProgress: { progress_percentage: number; is_course_completed: boolean } | undefined;
|
||||
if (isPassed) {
|
||||
const result = await this.markLessonComplete(decoded.id, lesson_id, course_id);
|
||||
const result = await this.markLessonComplete(userId, lesson_id, course_id);
|
||||
enrollmentProgress = result.enrollmentProgress;
|
||||
}
|
||||
|
||||
|
|
@ -1429,9 +1429,9 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error submitting quiz: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'QuizAttempt',
|
||||
entityId: 0,
|
||||
|
|
@ -1452,14 +1452,14 @@ export class CoursesStudentService {
|
|||
*/
|
||||
async getQuizAttempts(input: GetQuizAttemptsInput): Promise<GetQuizAttemptsResponse> {
|
||||
try {
|
||||
const { token, course_id, lesson_id } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { course_id, lesson_id } = input;
|
||||
const userId = input.userId;
|
||||
|
||||
// Check enrollment
|
||||
const enrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -1494,7 +1494,7 @@ export class CoursesStudentService {
|
|||
// Get all quiz attempts for this user
|
||||
const attempts = await prisma.quizAttempt.findMany({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
quiz_id: lesson.quiz.id,
|
||||
},
|
||||
orderBy: { attempt_number: 'desc' },
|
||||
|
|
@ -1539,22 +1539,20 @@ export class CoursesStudentService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
if (decoded?.id) {
|
||||
await auditService.logSync({
|
||||
userId: decoded.id,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'QuizAttempt',
|
||||
entityId: 0,
|
||||
metadata: {
|
||||
operation: 'get_quiz_attempts',
|
||||
course_id: input.course_id,
|
||||
lesson_id: input.lesson_id,
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
}
|
||||
// userId from middleware
|
||||
await auditService.logSync({
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'QuizAttempt',
|
||||
entityId: 0,
|
||||
metadata: {
|
||||
operation: 'get_quiz_attempts',
|
||||
course_id: input.course_id,
|
||||
lesson_id: input.lesson_id,
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import { prisma } from '../config/database';
|
||||
import { config } from '../config';
|
||||
import { logger } from '../config/logger';
|
||||
import { NotFoundError, ValidationError } from '../middleware/errorHandler';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { getPresignedUrl } from '../config/minio';
|
||||
import {
|
||||
ListApprovedCoursesResponse,
|
||||
|
|
@ -20,7 +18,7 @@ export class RecommendedCoursesService {
|
|||
* List all approved courses (for admin to manage recommendations)
|
||||
*/
|
||||
static async listApprovedCourses(
|
||||
token: string,
|
||||
userId: number,
|
||||
filters?: { search?: string; categoryId?: number }
|
||||
): Promise<ListApprovedCoursesResponse> {
|
||||
try {
|
||||
|
|
@ -108,19 +106,16 @@ export class RecommendedCoursesService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to list approved courses', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
if (decoded?.id) {
|
||||
await auditService.logSync({
|
||||
userId: decoded.id,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'RecommendedCourses',
|
||||
entityId: 0,
|
||||
metadata: {
|
||||
operation: 'list_approved_courses',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
}
|
||||
await auditService.logSync({
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'RecommendedCourses',
|
||||
entityId: 0,
|
||||
metadata: {
|
||||
operation: 'list_approved_courses',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -128,7 +123,7 @@ export class RecommendedCoursesService {
|
|||
/**
|
||||
* Get course by ID (for admin to view details)
|
||||
*/
|
||||
static async getCourseById(token: string, courseId: number): Promise<GetCourseByIdResponse> {
|
||||
static async getCourseById(userId: number, courseId: number): Promise<GetCourseByIdResponse> {
|
||||
try {
|
||||
const course = await prisma.course.findUnique({
|
||||
where: { id: courseId },
|
||||
|
|
@ -213,19 +208,16 @@ export class RecommendedCoursesService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to get course by ID', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
if (decoded?.id) {
|
||||
await auditService.logSync({
|
||||
userId: decoded.id,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'RecommendedCourses',
|
||||
entityId: 0,
|
||||
metadata: {
|
||||
operation: 'get_course_by_id',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
}
|
||||
await auditService.logSync({
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'RecommendedCourses',
|
||||
entityId: 0,
|
||||
metadata: {
|
||||
operation: 'get_course_by_id',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -234,12 +226,11 @@ export class RecommendedCoursesService {
|
|||
* Toggle course recommendation status
|
||||
*/
|
||||
static async toggleRecommended(
|
||||
token: string,
|
||||
userId: number,
|
||||
courseId: number,
|
||||
isRecommended: boolean
|
||||
): Promise<ToggleRecommendedResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
|
||||
const course = await prisma.course.findUnique({ where: { id: courseId } });
|
||||
if (!course) {
|
||||
|
|
@ -257,7 +248,7 @@ export class RecommendedCoursesService {
|
|||
|
||||
// Audit log
|
||||
await auditService.logSync({
|
||||
userId: decoded.id,
|
||||
userId,
|
||||
action: AuditAction.UPDATE,
|
||||
entityType: 'Course',
|
||||
entityId: courseId,
|
||||
|
|
@ -276,9 +267,8 @@ export class RecommendedCoursesService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to toggle recommended status', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'RecommendedCourses',
|
||||
entityId: courseId,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import { prisma } from '../config/database';
|
||||
import { config } from '../config';
|
||||
import { logger } from '../config/logger';
|
||||
import { UnauthorizedError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
||||
import {
|
||||
ListAnnouncementResponse,
|
||||
CreateAnnouncementInput,
|
||||
|
|
@ -31,27 +29,26 @@ export class AnnouncementsService {
|
|||
*/
|
||||
async listAnnouncement(input: ListAnnouncementInput): Promise<ListAnnouncementResponse> {
|
||||
try {
|
||||
const { token, course_id, page = 1, limit = 10 } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
||||
const { userId, course_id, page = 1, limit = 10 } = input;
|
||||
|
||||
// Check user access - instructor, admin, or enrolled student
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: decoded.id },
|
||||
where: { id: userId },
|
||||
include: { role: true },
|
||||
});
|
||||
if (!user) throw new UnauthorizedError('Invalid token');
|
||||
if (!user) throw new ForbiddenError('User not found');
|
||||
|
||||
// Admin can access all courses
|
||||
const isAdmin = user.role.code === 'ADMIN';
|
||||
|
||||
// Check if instructor of this course
|
||||
const isInstructor = await prisma.courseInstructor.findFirst({
|
||||
where: { course_id, user_id: decoded.id },
|
||||
where: { course_id, user_id: userId },
|
||||
});
|
||||
|
||||
// Check if enrolled student
|
||||
const isEnrolled = await prisma.enrollment.findFirst({
|
||||
where: { course_id, user_id: decoded.id },
|
||||
where: { course_id, user_id: userId },
|
||||
});
|
||||
|
||||
if (!isAdmin && !isInstructor && !isEnrolled) throw new ForbiddenError('You do not have access to this course announcements');
|
||||
|
|
@ -61,7 +58,7 @@ export class AnnouncementsService {
|
|||
// Students only see PUBLISHED announcements with published_at <= now
|
||||
const now = new Date();
|
||||
const whereClause: any = { course_id };
|
||||
|
||||
|
||||
if (!(isAdmin || isInstructor)) {
|
||||
// Students: only show PUBLISHED and published_at <= now
|
||||
whereClause.status = 'PUBLISHED';
|
||||
|
|
@ -130,9 +127,8 @@ export class AnnouncementsService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error listing announcements: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Announcement',
|
||||
entityId: 0,
|
||||
|
|
@ -150,11 +146,10 @@ export class AnnouncementsService {
|
|||
*/
|
||||
async createAnnouncement(input: CreateAnnouncementInput): Promise<CreateAnnouncementResponse> {
|
||||
try {
|
||||
const { token, course_id, title, content, status, is_pinned, published_at, files } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, title, content, status, is_pinned, published_at, files } = input;
|
||||
|
||||
// Validate instructor access
|
||||
await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
|
||||
// Determine published_at: use provided value or default to now if status is PUBLISHED
|
||||
let finalPublishedAt: Date | null = null;
|
||||
|
|
@ -171,7 +166,7 @@ export class AnnouncementsService {
|
|||
status: status as any,
|
||||
is_pinned,
|
||||
published_at: finalPublishedAt,
|
||||
created_by: decoded.id,
|
||||
created_by: userId,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -236,9 +231,8 @@ export class AnnouncementsService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error creating announcement: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Announcement',
|
||||
entityId: 0,
|
||||
|
|
@ -256,11 +250,10 @@ export class AnnouncementsService {
|
|||
*/
|
||||
async updateAnnouncement(input: UpdateAnnouncementInput): Promise<UpdateAnnouncementResponse> {
|
||||
try {
|
||||
const { token, course_id, announcement_id, title, content, status, is_pinned, published_at } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, announcement_id, title, content, status, is_pinned, published_at } = input;
|
||||
|
||||
// Validate instructor access
|
||||
await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
|
||||
// Check announcement exists and belongs to course
|
||||
const existing = await prisma.announcement.findFirst({
|
||||
|
|
@ -289,7 +282,7 @@ export class AnnouncementsService {
|
|||
status: status as any,
|
||||
is_pinned,
|
||||
published_at: finalPublishedAt,
|
||||
updated_by: decoded.id,
|
||||
updated_by: userId,
|
||||
},
|
||||
include: {
|
||||
attachments: true,
|
||||
|
|
@ -320,9 +313,8 @@ export class AnnouncementsService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error updating announcement: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Announcement',
|
||||
entityId: 0,
|
||||
|
|
@ -340,11 +332,10 @@ export class AnnouncementsService {
|
|||
*/
|
||||
async deleteAnnouncement(input: DeleteAnnouncementInput): Promise<DeleteAnnouncementResponse> {
|
||||
try {
|
||||
const { token, course_id, announcement_id } = input;
|
||||
jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, announcement_id } = input;
|
||||
|
||||
// Validate instructor access
|
||||
await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
|
||||
// Check announcement exists and belongs to course
|
||||
const existing = await prisma.announcement.findFirst({
|
||||
|
|
@ -376,9 +367,8 @@ export class AnnouncementsService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting announcement: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Announcement',
|
||||
entityId: 0,
|
||||
|
|
@ -396,11 +386,10 @@ export class AnnouncementsService {
|
|||
*/
|
||||
async uploadAttachment(input: UploadAnnouncementAttachmentInput): Promise<UploadAnnouncementAttachmentResponse> {
|
||||
try {
|
||||
const { token, course_id, announcement_id, file } = input;
|
||||
jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, announcement_id, file } = input;
|
||||
|
||||
// Validate instructor access
|
||||
await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
|
||||
// Check announcement exists and belongs to course
|
||||
const existing = await prisma.announcement.findFirst({
|
||||
|
|
@ -451,9 +440,8 @@ export class AnnouncementsService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error uploading attachment: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Announcement',
|
||||
entityId: 0,
|
||||
|
|
@ -471,11 +459,10 @@ export class AnnouncementsService {
|
|||
*/
|
||||
async deleteAttachment(input: DeleteAnnouncementAttachmentInput): Promise<DeleteAnnouncementAttachmentResponse> {
|
||||
try {
|
||||
const { token, course_id, announcement_id, attachment_id } = input;
|
||||
jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id, announcement_id, attachment_id } = input;
|
||||
|
||||
// Validate instructor access
|
||||
await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
||||
await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||
|
||||
// Check attachment exists and belongs to announcement in this course
|
||||
const attachment = await prisma.announcementAttachment.findFirst({
|
||||
|
|
@ -508,9 +495,8 @@ export class AnnouncementsService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting attachment: ${error}`);
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Announcement',
|
||||
entityId: 0,
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ export class AuthService {
|
|||
data: {
|
||||
token,
|
||||
refreshToken,
|
||||
user: await this.formatUserResponse(user)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
import { prisma } from '../config/database';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { config } from '../config';
|
||||
import { logger } from '../config/logger';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { createCategory, createCategoryResponse, deleteCategoryResponse, updateCategory, updateCategoryResponse, ListCategoriesResponse, Category } from '../types/categories.type';
|
||||
import { UnauthorizedError, ValidationError, ForbiddenError } from '../middleware/errorHandler';
|
||||
import { auditService } from './audit.service';
|
||||
import { AuditAction } from '@prisma/client';
|
||||
|
||||
|
|
@ -26,14 +23,13 @@ export class CategoryService {
|
|||
}
|
||||
}
|
||||
|
||||
async createCategory(token: string, category: createCategory): Promise<createCategoryResponse> {
|
||||
async createCategory(userId: number, category: createCategory): Promise<createCategoryResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
||||
const newCategory = await prisma.category.create({
|
||||
data: category
|
||||
});
|
||||
auditService.log({
|
||||
userId: decoded.id,
|
||||
userId,
|
||||
action: AuditAction.CREATE,
|
||||
entityType: 'Category',
|
||||
entityId: newCategory.id,
|
||||
|
|
@ -47,13 +43,13 @@ export class CategoryService {
|
|||
name: newCategory.name as { th: string; en: string },
|
||||
slug: newCategory.slug,
|
||||
description: newCategory.description as { th: string; en: string },
|
||||
created_by: decoded.id,
|
||||
created_by: userId,
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to create category', { error });
|
||||
await auditService.logSync({
|
||||
userId: 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Category',
|
||||
entityId: 0,
|
||||
|
|
@ -66,15 +62,14 @@ export class CategoryService {
|
|||
}
|
||||
}
|
||||
|
||||
async updateCategory(token: string, id: number, category: updateCategory): Promise<updateCategoryResponse> {
|
||||
async updateCategory(userId: number, id: number, category: updateCategory): Promise<updateCategoryResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
||||
const updatedCategory = await prisma.category.update({
|
||||
where: { id },
|
||||
data: category
|
||||
});
|
||||
auditService.log({
|
||||
userId: decoded.id,
|
||||
userId,
|
||||
action: AuditAction.UPDATE,
|
||||
entityType: 'Category',
|
||||
entityId: id,
|
||||
|
|
@ -88,13 +83,13 @@ export class CategoryService {
|
|||
name: updatedCategory.name as { th: string; en: string },
|
||||
slug: updatedCategory.slug,
|
||||
description: updatedCategory.description as { th: string; en: string },
|
||||
updated_by: decoded.id,
|
||||
updated_by: userId,
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to update category', { error });
|
||||
await auditService.logSync({
|
||||
userId: 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Category',
|
||||
entityId: 0,
|
||||
|
|
@ -107,14 +102,13 @@ export class CategoryService {
|
|||
}
|
||||
}
|
||||
|
||||
async deleteCategory(token: string, id: number): Promise<deleteCategoryResponse> {
|
||||
async deleteCategory(userId: number, id: number): Promise<deleteCategoryResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
||||
const deletedCategory = await prisma.category.delete({
|
||||
where: { id }
|
||||
});
|
||||
auditService.log({
|
||||
userId: decoded.id,
|
||||
userId,
|
||||
action: AuditAction.DELETE,
|
||||
entityType: 'Category',
|
||||
entityId: id,
|
||||
|
|
@ -127,7 +121,7 @@ export class CategoryService {
|
|||
} catch (error) {
|
||||
logger.error('Failed to delete category', { error });
|
||||
await auditService.logSync({
|
||||
userId: 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Category',
|
||||
entityId: 0,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import { prisma } from '../config/database';
|
||||
import { config } from '../config';
|
||||
import { logger } from '../config/logger';
|
||||
import { NotFoundError, ForbiddenError, ValidationError } from '../middleware/errorHandler';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { PDFDocument, rgb } from 'pdf-lib';
|
||||
import fontkit from '@pdf-lib/fontkit';
|
||||
import * as fs from 'fs';
|
||||
|
|
@ -29,14 +27,13 @@ export class CertificateService {
|
|||
*/
|
||||
async generateCertificate(input: GenerateCertificateInput): Promise<GenerateCertificateResponse> {
|
||||
try {
|
||||
const { token, course_id } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id } = input;
|
||||
|
||||
// Check enrollment and completion
|
||||
const enrollment = await prisma.enrollment.findUnique({
|
||||
where: {
|
||||
unique_enrollment: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
},
|
||||
|
|
@ -65,7 +62,7 @@ export class CertificateService {
|
|||
// Check if certificate already exists
|
||||
const existingCertificate = await prisma.certificate.findFirst({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
});
|
||||
|
|
@ -103,13 +100,13 @@ export class CertificateService {
|
|||
|
||||
// Upload to MinIO
|
||||
const timestamp = Date.now();
|
||||
const filePath = `certificates/${course_id}/${decoded.id}/${timestamp}.pdf`;
|
||||
const filePath = `certificates/${course_id}/${userId}/${timestamp}.pdf`;
|
||||
await uploadFile(filePath, Buffer.from(pdfBytes), 'application/pdf');
|
||||
|
||||
// Save to database
|
||||
const certificate = await prisma.certificate.create({
|
||||
data: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
enrollment_id: enrollment.id,
|
||||
file_path: filePath,
|
||||
|
|
@ -118,7 +115,7 @@ export class CertificateService {
|
|||
});
|
||||
|
||||
auditService.log({
|
||||
userId: decoded.id,
|
||||
userId,
|
||||
action: AuditAction.CREATE,
|
||||
entityType: 'Certificate',
|
||||
entityId: certificate.id,
|
||||
|
|
@ -139,9 +136,8 @@ export class CertificateService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to generate certificate', { error });
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Certificate',
|
||||
entityId: 0,
|
||||
|
|
@ -160,12 +156,11 @@ export class CertificateService {
|
|||
*/
|
||||
async getCertificate(input: GetCertificateInput): Promise<GetCertificateResponse> {
|
||||
try {
|
||||
const { token, course_id } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId, course_id } = input;
|
||||
|
||||
const certificate = await prisma.certificate.findFirst({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
course_id,
|
||||
},
|
||||
include: {
|
||||
|
|
@ -202,9 +197,8 @@ export class CertificateService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to get certificate', { error });
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Certificate',
|
||||
entityId: 0,
|
||||
|
|
@ -223,12 +217,11 @@ export class CertificateService {
|
|||
*/
|
||||
async listMyCertificates(input: ListMyCertificatesInput): Promise<ListMyCertificatesResponse> {
|
||||
try {
|
||||
const { token } = input;
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const { userId } = input;
|
||||
|
||||
const certificates = await prisma.certificate.findMany({
|
||||
where: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
},
|
||||
include: {
|
||||
enrollment: {
|
||||
|
|
@ -267,9 +260,8 @@ export class CertificateService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error('Failed to list certificates', { error });
|
||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id,
|
||||
userId: input.userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Certificate',
|
||||
entityId: 0,
|
||||
|
|
|
|||
|
|
@ -24,15 +24,10 @@ import { auditService } from './audit.service';
|
|||
import { AuditAction } from '@prisma/client';
|
||||
|
||||
export class UserService {
|
||||
async getUserProfile(token: string): Promise<UserResponse> {
|
||||
async getUserProfile(userId: number): Promise<UserResponse> {
|
||||
try {
|
||||
// Decode JWT token to get user ID
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: decoded.id
|
||||
},
|
||||
where: { id: userId },
|
||||
include: {
|
||||
profile: true,
|
||||
role: true
|
||||
|
|
@ -68,14 +63,6 @@ export class UserService {
|
|||
} : undefined
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof jwt.JsonWebTokenError) {
|
||||
logger.error('Invalid JWT token:', error);
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
if (error instanceof jwt.TokenExpiredError) {
|
||||
logger.error('JWT token expired:', error);
|
||||
throw new UnauthorizedError('Token expired');
|
||||
}
|
||||
logger.error('Error fetching user profile:', error);
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -84,12 +71,9 @@ export class UserService {
|
|||
/**
|
||||
* Change user password
|
||||
*/
|
||||
async changePassword(token: string, oldPassword: string, newPassword: string): Promise<ChangePasswordResponse> {
|
||||
async changePassword(userId: number, oldPassword: string, newPassword: string): Promise<ChangePasswordResponse> {
|
||||
try {
|
||||
// Decode JWT token to get user ID
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decoded.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('User not found');
|
||||
|
||||
// Check if account is deactivated
|
||||
|
|
@ -127,21 +111,12 @@ export class UserService {
|
|||
message: 'Password changed successfully'
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof jwt.JsonWebTokenError) {
|
||||
logger.error('Invalid JWT token:', error);
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
if (error instanceof jwt.TokenExpiredError) {
|
||||
logger.error('JWT token expired:', error);
|
||||
throw new UnauthorizedError('Token expired');
|
||||
}
|
||||
logger.error('Failed to change password', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'User',
|
||||
entityId: decoded?.id || 0,
|
||||
entityId: userId,
|
||||
metadata: {
|
||||
operation: 'change_password',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
|
|
@ -154,12 +129,9 @@ export class UserService {
|
|||
/**
|
||||
* Update user profile
|
||||
*/
|
||||
async updateProfile(token: string, profile: ProfileUpdate): Promise<ProfileUpdateResponse> {
|
||||
async updateProfile(userId: number, profile: ProfileUpdate): Promise<ProfileUpdateResponse> {
|
||||
try {
|
||||
// Decode JWT token to get user ID
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: decoded.id } });
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new UnauthorizedError('User not found');
|
||||
|
||||
// Check if account is deactivated
|
||||
|
|
@ -189,21 +161,12 @@ export class UserService {
|
|||
}
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof jwt.JsonWebTokenError) {
|
||||
logger.error('Invalid JWT token:', error);
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
if (error instanceof jwt.TokenExpiredError) {
|
||||
logger.error('JWT token expired:', error);
|
||||
throw new UnauthorizedError('Token expired');
|
||||
}
|
||||
logger.error('Failed to update profile', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId,
|
||||
action: AuditAction.UPDATE,
|
||||
entityType: 'UserProfile',
|
||||
entityId: decoded?.id || 0,
|
||||
entityId: userId,
|
||||
metadata: {
|
||||
operation: 'update_profile',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
|
|
@ -213,9 +176,8 @@ export class UserService {
|
|||
}
|
||||
}
|
||||
|
||||
async getRoles(token: string): Promise<rolesResponse> {
|
||||
async getRoles(): Promise<rolesResponse> {
|
||||
try {
|
||||
jwt.verify(token, config.jwt.secret);
|
||||
const roles = await prisma.role.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
|
|
@ -224,14 +186,6 @@ export class UserService {
|
|||
});
|
||||
return { roles };
|
||||
} catch (error) {
|
||||
if (error instanceof jwt.TokenExpiredError) {
|
||||
logger.error('JWT token expired:', error);
|
||||
throw new UnauthorizedError('Token expired');
|
||||
}
|
||||
if (error instanceof jwt.JsonWebTokenError) {
|
||||
logger.error('Invalid JWT token:', error);
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
logger.error('Failed to get roles', { error });
|
||||
throw error;
|
||||
}
|
||||
|
|
@ -240,13 +194,11 @@ export class UserService {
|
|||
/**
|
||||
* Upload avatar picture to MinIO
|
||||
*/
|
||||
async uploadAvatarPicture(token: string, file: Express.Multer.File): Promise<updateAvatarResponse> {
|
||||
async uploadAvatarPicture(userId: number, file: Express.Multer.File): Promise<updateAvatarResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
|
||||
// Check if user exists
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: decoded.id },
|
||||
where: { id: userId },
|
||||
include: { profile: true }
|
||||
});
|
||||
|
||||
|
|
@ -265,7 +217,7 @@ export class UserService {
|
|||
const fileName = file.originalname || 'avatar';
|
||||
const extension = fileName.split('.').pop() || 'jpg';
|
||||
const safeFilename = `${timestamp}-${uniqueId}.${extension}`;
|
||||
const filePath = `avatars/${decoded.id}/${safeFilename}`;
|
||||
const filePath = `avatars/${userId}/${safeFilename}`;
|
||||
|
||||
// Delete old avatar if exists
|
||||
if (user.profile?.avatar_url) {
|
||||
|
|
@ -285,13 +237,13 @@ export class UserService {
|
|||
// Update or create profile - store only file path
|
||||
if (user.profile) {
|
||||
await prisma.userProfile.update({
|
||||
where: { user_id: decoded.id },
|
||||
where: { user_id: userId },
|
||||
data: { avatar_url: filePath }
|
||||
});
|
||||
} else {
|
||||
await prisma.userProfile.create({
|
||||
data: {
|
||||
user_id: decoded.id,
|
||||
user_id: userId,
|
||||
avatar_url: filePath,
|
||||
first_name: '',
|
||||
last_name: ''
|
||||
|
|
@ -301,10 +253,10 @@ export class UserService {
|
|||
|
||||
// Audit log - UPLOAD_AVATAR
|
||||
await auditService.logSync({
|
||||
userId: decoded.id,
|
||||
userId,
|
||||
action: AuditAction.UPLOAD_FILE,
|
||||
entityType: 'User',
|
||||
entityId: decoded.id,
|
||||
entityId: userId,
|
||||
metadata: {
|
||||
operation: 'upload_avatar',
|
||||
filePath
|
||||
|
|
@ -318,26 +270,17 @@ export class UserService {
|
|||
code: 200,
|
||||
message: 'Avatar uploaded successfully',
|
||||
data: {
|
||||
id: decoded.id,
|
||||
id: userId,
|
||||
avatar_url: presignedUrl
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof jwt.JsonWebTokenError) {
|
||||
logger.error('Invalid JWT token:', error);
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
if (error instanceof jwt.TokenExpiredError) {
|
||||
logger.error('JWT token expired:', error);
|
||||
throw new UnauthorizedError('Token expired');
|
||||
}
|
||||
logger.error('Failed to upload avatar', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId,
|
||||
action: AuditAction.UPLOAD_FILE,
|
||||
entityType: 'UserProfile',
|
||||
entityId: decoded?.id || 0,
|
||||
entityId: userId,
|
||||
metadata: {
|
||||
operation: 'upload_avatar',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
|
|
@ -390,12 +333,10 @@ export class UserService {
|
|||
/**
|
||||
* Send verification email to user
|
||||
*/
|
||||
async sendVerifyEmail(token: string): Promise<SendVerifyEmailResponse> {
|
||||
async sendVerifyEmail(userId: number): Promise<SendVerifyEmailResponse> {
|
||||
try {
|
||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; email: string; roleCode: string };
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: decoded.id },
|
||||
where: { id: userId },
|
||||
include: { role: true }
|
||||
});
|
||||
|
||||
|
|
@ -453,15 +394,12 @@ export class UserService {
|
|||
message: 'Verification email sent successfully'
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof jwt.JsonWebTokenError) throw new UnauthorizedError('Invalid token');
|
||||
if (error instanceof jwt.TokenExpiredError) throw new UnauthorizedError('Token expired');
|
||||
logger.error('Failed to send verification email', { error });
|
||||
const decoded = jwt.decode(token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decoded?.id || 0,
|
||||
userId,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'UserProfile',
|
||||
entityId: decoded?.id || 0,
|
||||
entityId: userId,
|
||||
metadata: {
|
||||
operation: 'send_verification_email',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
|
|
|
|||
|
|
@ -98,18 +98,18 @@ export interface ChapterData {
|
|||
// ============================================
|
||||
|
||||
export interface ChaptersRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
export interface GetChapterRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
}
|
||||
|
||||
export interface CreateChapterInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
title: MultiLanguageText;
|
||||
description?: MultiLanguageText;
|
||||
|
|
@ -118,13 +118,13 @@ export interface CreateChapterInput {
|
|||
}
|
||||
|
||||
export interface CreateChapterRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
data: CreateChapterInput;
|
||||
}
|
||||
|
||||
export interface UpdateChapterInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
title?: MultiLanguageText;
|
||||
|
|
@ -134,20 +134,20 @@ export interface UpdateChapterInput {
|
|||
}
|
||||
|
||||
export interface UpdateChapterRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
data: UpdateChapterInput;
|
||||
}
|
||||
|
||||
export interface DeleteChapterRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
}
|
||||
|
||||
export interface ReorderChapterRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
sort_order: number;
|
||||
|
|
@ -199,7 +199,7 @@ export interface ReorderChapterResponse {
|
|||
// ============================================
|
||||
|
||||
export interface GetLessonRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
lesson_id: number;
|
||||
|
|
@ -216,7 +216,7 @@ export interface UploadedFileInfo {
|
|||
}
|
||||
|
||||
export interface CreateLessonInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
title: MultiLanguageText;
|
||||
|
|
@ -293,7 +293,7 @@ export interface QuizChoiceData {
|
|||
}
|
||||
|
||||
export interface CreateLessonRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
data: CreateLessonInput;
|
||||
|
|
@ -311,7 +311,7 @@ export interface UpdateLessonInput {
|
|||
}
|
||||
|
||||
export interface UpdateLessonRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
lesson_id: number;
|
||||
|
|
@ -319,14 +319,14 @@ export interface UpdateLessonRequest {
|
|||
}
|
||||
|
||||
export interface DeleteLessonRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
lesson_id: number;
|
||||
}
|
||||
|
||||
export interface ReorderLessonsRequest {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
chapter_id: number;
|
||||
lesson_id: number;
|
||||
|
|
@ -365,7 +365,7 @@ export interface UpdateLessonResponse {
|
|||
* Input for uploading video to a lesson
|
||||
*/
|
||||
export interface UploadVideoInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
video: UploadedFileInfo;
|
||||
|
|
@ -375,7 +375,7 @@ export interface UploadVideoInput {
|
|||
* Input for updating (replacing) video in a lesson
|
||||
*/
|
||||
export interface UpdateVideoInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
video: UploadedFileInfo;
|
||||
|
|
@ -385,7 +385,7 @@ export interface UpdateVideoInput {
|
|||
* Input for setting YouTube video to a lesson
|
||||
*/
|
||||
export interface SetYouTubeVideoInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
youtube_video_id: string;
|
||||
|
|
@ -411,7 +411,7 @@ export interface YouTubeVideoResponse {
|
|||
* Input for uploading a single attachment to a lesson
|
||||
*/
|
||||
export interface UploadAttachmentInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
attachment: UploadedFileInfo;
|
||||
|
|
@ -421,7 +421,7 @@ export interface UploadAttachmentInput {
|
|||
* Input for deleting an attachment from a lesson
|
||||
*/
|
||||
export interface DeleteAttachmentInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
attachment_id: number;
|
||||
|
|
@ -490,7 +490,7 @@ export interface LessonWithDetailsResponse {
|
|||
* Input for adding quiz to an existing QUIZ lesson
|
||||
*/
|
||||
export interface AddQuizToLessonInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
quiz_data: {
|
||||
|
|
@ -509,7 +509,7 @@ export interface AddQuizToLessonInput {
|
|||
* Input for adding a single question to a quiz lesson
|
||||
*/
|
||||
export interface AddQuestionInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
question: MultiLanguageText;
|
||||
|
|
@ -532,7 +532,7 @@ export interface AddQuestionResponse {
|
|||
* Input for updating a question
|
||||
*/
|
||||
export interface UpdateQuestionInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
question_id: number;
|
||||
|
|
@ -556,14 +556,14 @@ export interface UpdateQuestionResponse {
|
|||
* Input for deleting a question
|
||||
*/
|
||||
export interface DeleteQuestionInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
question_id: number;
|
||||
}
|
||||
|
||||
export interface ReorderQuestionInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
question_id: number;
|
||||
|
|
@ -588,7 +588,7 @@ export interface DeleteQuestionResponse {
|
|||
* Input for updating quiz settings
|
||||
*/
|
||||
export interface UpdateQuizInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
title?: MultiLanguageText;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export interface createCourseResponse {
|
|||
}
|
||||
|
||||
export interface ListMyCoursesInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
status?: 'DRAFT' | 'PENDING' | 'APPROVED' | 'REJECTED' | 'ARCHIVED';
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ export interface GetMyCourseResponse {
|
|||
}
|
||||
|
||||
export interface getmyCourse {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
|
|
@ -94,13 +94,13 @@ export interface listCourseinstructorResponse {
|
|||
}
|
||||
|
||||
export interface addinstructorCourse {
|
||||
token: string;
|
||||
userId: number;
|
||||
email_or_username: string;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
export interface SearchInstructorInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
query: string;
|
||||
course_id: number;
|
||||
}
|
||||
|
|
@ -145,12 +145,12 @@ export interface listinstructorCourseResponse {
|
|||
}
|
||||
|
||||
export interface listinstructorCourse {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
export interface removeinstructorCourse {
|
||||
token: string;
|
||||
userId: number;
|
||||
user_id: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ export interface removeinstructorCourseResponse {
|
|||
}
|
||||
|
||||
export interface setprimaryCourseInstructor {
|
||||
token: string;
|
||||
userId: number;
|
||||
user_id: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
|
@ -172,12 +172,12 @@ export interface setprimaryCourseInstructorResponse {
|
|||
}
|
||||
|
||||
export interface sendCourseForReview {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
export interface setCourseDraft {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +220,7 @@ export interface GetCourseApprovalsResponse {
|
|||
// ============================================
|
||||
|
||||
export interface GetEnrolledStudentsInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
|
|
@ -254,7 +254,7 @@ export interface GetEnrolledStudentsResponse {
|
|||
// ============================================
|
||||
|
||||
export interface GetQuizScoresInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
page?: number;
|
||||
|
|
@ -305,7 +305,7 @@ export interface GetQuizScoresResponse {
|
|||
// ============================================
|
||||
|
||||
export interface GetQuizAttemptDetailInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
student_id: number;
|
||||
|
|
@ -353,7 +353,7 @@ export interface GetQuizAttemptDetailResponse {
|
|||
// ============================================
|
||||
|
||||
export interface GetEnrolledStudentDetailInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
student_id: number;
|
||||
}
|
||||
|
|
@ -435,7 +435,7 @@ export interface GetCourseApprovalHistoryResponse {
|
|||
}
|
||||
|
||||
export interface CloneCourseInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
title: MultiLanguageText;
|
||||
}
|
||||
|
|
@ -448,3 +448,14 @@ export interface CloneCourseResponse {
|
|||
title: MultiLanguageText;
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Get All Students across all instructor courses
|
||||
// ============================================
|
||||
|
||||
export interface GetAllMyStudentsResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
total_students: number;
|
||||
total_completed: number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export type MultiLangText = MultiLanguageText;
|
|||
// ============================================
|
||||
|
||||
export interface EnrollCourseInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ export interface EnrollCourseResponse {
|
|||
}
|
||||
|
||||
export interface ListEnrolledCoursesInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
status?: EnrollmentStatus;
|
||||
|
|
@ -64,7 +64,7 @@ export interface ListEnrolledCoursesResponse {
|
|||
// ============================================
|
||||
|
||||
export interface GetCourseLearningInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ export interface GetCourseLearningResponse {
|
|||
// ============================================
|
||||
|
||||
export interface GetLessonContentInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
}
|
||||
|
|
@ -204,7 +204,7 @@ export interface GetLessonContentResponse {
|
|||
// ============================================
|
||||
|
||||
export interface CheckLessonAccessInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
}
|
||||
|
|
@ -236,7 +236,7 @@ export interface CheckLessonAccessResponse {
|
|||
// ============================================
|
||||
|
||||
export interface SaveVideoProgressInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
lesson_id: number;
|
||||
video_progress_seconds: number;
|
||||
video_duration_seconds?: number;
|
||||
|
|
@ -258,7 +258,7 @@ export interface SaveVideoProgressResponse {
|
|||
}
|
||||
|
||||
export interface GetVideoProgressInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
lesson_id: number;
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ export interface GetVideoProgressResponse {
|
|||
// ============================================
|
||||
|
||||
export interface MarkLessonCompleteInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
}
|
||||
|
|
@ -314,7 +314,7 @@ export interface EnrollCourseBody {
|
|||
}
|
||||
|
||||
export interface CompleteLessonInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
lesson_id: number;
|
||||
}
|
||||
|
||||
|
|
@ -342,7 +342,7 @@ export interface QuizAnswerInput {
|
|||
}
|
||||
|
||||
export interface SubmitQuizInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
answers: QuizAnswerInput[];
|
||||
|
|
@ -384,7 +384,7 @@ export interface SubmitQuizResponse {
|
|||
// ============================================
|
||||
|
||||
export interface GetQuizAttemptsInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
lesson_id: number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ export interface AnnouncementAttachment {
|
|||
updated_at: Date;
|
||||
}
|
||||
|
||||
export interface ListAnnouncementResponse{
|
||||
export interface ListAnnouncementResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
data: Announcement[];
|
||||
|
|
@ -31,15 +31,15 @@ export interface ListAnnouncementResponse{
|
|||
limit: number;
|
||||
}
|
||||
|
||||
export interface ListAnnouncementInput{
|
||||
token: string;
|
||||
export interface ListAnnouncementInput {
|
||||
userId: number;
|
||||
course_id: number;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export interface CreateAnnouncementInput{
|
||||
token: string;
|
||||
export interface CreateAnnouncementInput {
|
||||
userId: number;
|
||||
course_id: number;
|
||||
title: MultiLanguageText;
|
||||
content: MultiLanguageText;
|
||||
|
|
@ -49,39 +49,39 @@ export interface CreateAnnouncementInput{
|
|||
files?: Express.Multer.File[];
|
||||
}
|
||||
|
||||
export interface UploadAnnouncementAttachmentInput{
|
||||
token: string;
|
||||
export interface UploadAnnouncementAttachmentInput {
|
||||
userId: number;
|
||||
course_id: number;
|
||||
announcement_id: number;
|
||||
file: File;
|
||||
}
|
||||
|
||||
export interface UploadAnnouncementAttachmentResponse{
|
||||
export interface UploadAnnouncementAttachmentResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
data: AnnouncementAttachment;
|
||||
}
|
||||
|
||||
export interface DeleteAnnouncementAttachmentInput{
|
||||
token: string;
|
||||
export interface DeleteAnnouncementAttachmentInput {
|
||||
userId: number;
|
||||
course_id: number;
|
||||
announcement_id: number;
|
||||
attachment_id: number;
|
||||
}
|
||||
|
||||
export interface DeleteAnnouncementAttachmentResponse{
|
||||
export interface DeleteAnnouncementAttachmentResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface CreateAnnouncementResponse{
|
||||
export interface CreateAnnouncementResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
data: Announcement;
|
||||
}
|
||||
|
||||
export interface UpdateAnnouncementInput{
|
||||
token: string;
|
||||
export interface UpdateAnnouncementInput {
|
||||
userId: number;
|
||||
course_id: number;
|
||||
announcement_id: number;
|
||||
title: MultiLanguageText;
|
||||
|
|
@ -92,19 +92,19 @@ export interface UpdateAnnouncementInput{
|
|||
attachments?: AnnouncementAttachment[];
|
||||
}
|
||||
|
||||
export interface UpdateAnnouncementResponse{
|
||||
export interface UpdateAnnouncementResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
data: Announcement;
|
||||
}
|
||||
|
||||
export interface DeleteAnnouncementInput{
|
||||
token: string;
|
||||
export interface DeleteAnnouncementInput {
|
||||
userId: number;
|
||||
course_id: number;
|
||||
announcement_id: number;
|
||||
}
|
||||
|
||||
export interface DeleteAnnouncementResponse{
|
||||
export interface DeleteAnnouncementResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ export interface LoginResponse {
|
|||
data: {
|
||||
token: string;
|
||||
refreshToken: string;
|
||||
user: UserResponse;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
// ============================================
|
||||
|
||||
export interface GenerateCertificateInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ export interface GenerateCertificateResponse {
|
|||
}
|
||||
|
||||
export interface GetCertificateInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
course_id: number;
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ export interface GetCertificateResponse {
|
|||
}
|
||||
|
||||
export interface ListMyCertificatesInput {
|
||||
token: string;
|
||||
userId: number;
|
||||
}
|
||||
|
||||
export interface ListMyCertificatesResponse {
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ export const UpdateLessonValidator = Joi.object({
|
|||
'number.min': 'Duration must be at least 0'
|
||||
}),
|
||||
sort_order: Joi.number().integer().min(0).optional(),
|
||||
prerequisite_lesson_ids: Joi.array().items(Joi.number().integer().positive()).optional(),
|
||||
prerequisite_lesson_ids: Joi.array().items(Joi.number().integer().positive()).allow(null).optional(),
|
||||
is_published: Joi.boolean().optional()
|
||||
});
|
||||
|
||||
|
|
|
|||
14
Backend/tests/tsconfig.json
Normal file
14
Backend/tests/tsconfig.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"extends": "../tsconfig.test.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "..",
|
||||
"types": [
|
||||
"node",
|
||||
"jest"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"../src/**/*",
|
||||
"./**/*"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
import {
|
||||
ApproveCourseValidator,
|
||||
RejectCourseValidator,
|
||||
} from '@/validators/AdminCourseApproval.validator';
|
||||
|
||||
describe('ApproveCourseValidator', () => {
|
||||
it('should pass with no body (comment optional)', () => {
|
||||
const { error } = ApproveCourseValidator.validate({});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with optional comment', () => {
|
||||
const { error } = ApproveCourseValidator.validate({
|
||||
comment: 'Looks great!',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail when comment exceeds 1000 characters', () => {
|
||||
const { error } = ApproveCourseValidator.validate({
|
||||
comment: 'a'.repeat(1001),
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/must not exceed 1000/i);
|
||||
});
|
||||
|
||||
it('should pass with comment exactly 1000 characters', () => {
|
||||
const { error } = ApproveCourseValidator.validate({
|
||||
comment: 'a'.repeat(1000),
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('RejectCourseValidator', () => {
|
||||
it('should pass with valid rejection comment', () => {
|
||||
const { error } = RejectCourseValidator.validate({
|
||||
comment: 'The content is incomplete and needs more details.',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without comment', () => {
|
||||
const { error } = RejectCourseValidator.validate({});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Comment is required when rejecting/i);
|
||||
});
|
||||
|
||||
it('should fail when comment is too short (< 10 chars)', () => {
|
||||
const { error } = RejectCourseValidator.validate({ comment: 'Too short' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/at least 10 characters/i);
|
||||
});
|
||||
|
||||
it('should pass with exactly 10 characters', () => {
|
||||
const { error } = RejectCourseValidator.validate({ comment: '1234567890' });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail when comment exceeds 1000 characters', () => {
|
||||
const { error } = RejectCourseValidator.validate({
|
||||
comment: 'a'.repeat(1001),
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/must not exceed 1000/i);
|
||||
});
|
||||
});
|
||||
263
Backend/tests/unit/validators/ChaptersLesson.validator.test.ts
Normal file
263
Backend/tests/unit/validators/ChaptersLesson.validator.test.ts
Normal file
|
|
@ -0,0 +1,263 @@
|
|||
import {
|
||||
CreateChapterValidator,
|
||||
UpdateChapterValidator,
|
||||
ReorderChapterValidator,
|
||||
CreateLessonValidator,
|
||||
UpdateLessonValidator,
|
||||
ReorderLessonsValidator,
|
||||
AddQuestionValidator,
|
||||
UpdateQuizValidator,
|
||||
} from '@/validators/ChaptersLesson.validator';
|
||||
|
||||
|
||||
// ============================================================
|
||||
// Chapter Validators
|
||||
// ============================================================
|
||||
|
||||
describe('CreateChapterValidator', () => {
|
||||
it('should pass with valid data', () => {
|
||||
const { error } = CreateChapterValidator.validate({
|
||||
title: { th: 'บทที่ 1', en: 'Chapter 1' },
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with optional fields', () => {
|
||||
const { error } = CreateChapterValidator.validate({
|
||||
title: { th: 'บทที่ 1', en: 'Chapter 1' },
|
||||
description: { th: 'คำอธิบาย', en: 'Description' },
|
||||
sort_order: 0,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail if title is missing', () => {
|
||||
const { error } = CreateChapterValidator.validate({});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if title.th is missing', () => {
|
||||
const { error } = CreateChapterValidator.validate({
|
||||
title: { en: 'Chapter 1' },
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if title.en is missing', () => {
|
||||
const { error } = CreateChapterValidator.validate({
|
||||
title: { th: 'บทที่ 1' },
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('UpdateChapterValidator', () => {
|
||||
it('should pass with empty object (all fields optional)', () => {
|
||||
const { error } = UpdateChapterValidator.validate({});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with partial fields', () => {
|
||||
const { error } = UpdateChapterValidator.validate({
|
||||
is_published: true,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ReorderChapterValidator', () => {
|
||||
it('should pass with valid sort_order', () => {
|
||||
const { error } = ReorderChapterValidator.validate({ sort_order: 0 });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without sort_order', () => {
|
||||
const { error } = ReorderChapterValidator.validate({});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Sort order is required/i);
|
||||
});
|
||||
|
||||
it('should fail with negative sort_order', () => {
|
||||
const { error } = ReorderChapterValidator.validate({ sort_order: -1 });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// Lesson Validators
|
||||
// ============================================================
|
||||
|
||||
describe('CreateLessonValidator', () => {
|
||||
it('should pass with VIDEO type', () => {
|
||||
const { error } = CreateLessonValidator.validate({
|
||||
title: { th: 'บทเรียน 1', en: 'Lesson 1' },
|
||||
type: 'VIDEO',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with QUIZ type', () => {
|
||||
const { error } = CreateLessonValidator.validate({
|
||||
title: { th: 'แบบทดสอบ', en: 'Quiz' },
|
||||
type: 'QUIZ',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail with invalid type', () => {
|
||||
const { error } = CreateLessonValidator.validate({
|
||||
title: { th: 'บทเรียน', en: 'Lesson' },
|
||||
type: 'DOCUMENT',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail without title', () => {
|
||||
const { error } = CreateLessonValidator.validate({ type: 'VIDEO' });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail without type', () => {
|
||||
const { error } = CreateLessonValidator.validate({
|
||||
title: { th: 'บทเรียน', en: 'Lesson' },
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('UpdateLessonValidator — prerequisite_lesson_ids', () => {
|
||||
it('should pass with valid array of ids', () => {
|
||||
const { error } = UpdateLessonValidator.validate({
|
||||
prerequisite_lesson_ids: [1, 2, 3],
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with null (clear prerequisites)', () => {
|
||||
const { error } = UpdateLessonValidator.validate({
|
||||
prerequisite_lesson_ids: null,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with empty array (clear prerequisites)', () => {
|
||||
const { error } = UpdateLessonValidator.validate({
|
||||
prerequisite_lesson_ids: [],
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass without the field (no change)', () => {
|
||||
const { error } = UpdateLessonValidator.validate({});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail with non-integer ids', () => {
|
||||
const { error } = UpdateLessonValidator.validate({
|
||||
prerequisite_lesson_ids: [1.5],
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail with negative ids', () => {
|
||||
const { error } = UpdateLessonValidator.validate({
|
||||
prerequisite_lesson_ids: [-1],
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail with string ids', () => {
|
||||
const { error } = UpdateLessonValidator.validate({
|
||||
prerequisite_lesson_ids: ['abc'],
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ReorderLessonsValidator', () => {
|
||||
it('should pass with valid data', () => {
|
||||
const { error } = ReorderLessonsValidator.validate({
|
||||
lesson_id: 1,
|
||||
sort_order: 0,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without lesson_id', () => {
|
||||
const { error } = ReorderLessonsValidator.validate({ sort_order: 0 });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail without sort_order', () => {
|
||||
const { error } = ReorderLessonsValidator.validate({ lesson_id: 1 });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// Quiz Validators
|
||||
// ============================================================
|
||||
|
||||
describe('AddQuestionValidator', () => {
|
||||
it('should pass with MULTIPLE_CHOICE type + choices', () => {
|
||||
const { error } = AddQuestionValidator.validate({
|
||||
question: { th: 'ข้อที่ 1 คืออะไร?', en: 'What is question 1?' },
|
||||
question_type: 'MULTIPLE_CHOICE',
|
||||
choices: [
|
||||
{ text: { th: 'ก', en: 'A' }, is_correct: true },
|
||||
{ text: { th: 'ข', en: 'B' }, is_correct: false },
|
||||
],
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with TRUE_FALSE type without choices', () => {
|
||||
const { error } = AddQuestionValidator.validate({
|
||||
question: { th: 'ถูกหรือผิด?', en: 'True or False?' },
|
||||
question_type: 'TRUE_FALSE',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail with invalid question_type', () => {
|
||||
const { error } = AddQuestionValidator.validate({
|
||||
question: { th: 'คำถาม', en: 'Question' },
|
||||
question_type: 'ESSAY',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail without question', () => {
|
||||
const { error } = AddQuestionValidator.validate({
|
||||
question_type: 'TRUE_FALSE',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('UpdateQuizValidator', () => {
|
||||
it('should pass with empty object (all optional)', () => {
|
||||
const { error } = UpdateQuizValidator.validate({});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with valid passing_score', () => {
|
||||
const { error } = UpdateQuizValidator.validate({ passing_score: 70 });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail with passing_score > 100', () => {
|
||||
const { error } = UpdateQuizValidator.validate({ passing_score: 101 });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail with passing_score < 0', () => {
|
||||
const { error } = UpdateQuizValidator.validate({ passing_score: -1 });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should pass with time_limit 0 (no limit)', () => {
|
||||
const { error } = UpdateQuizValidator.validate({ time_limit: 0 });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
import {
|
||||
CreateCourseValidator,
|
||||
UpdateCourseValidator,
|
||||
CloneCourseValidator,
|
||||
addInstructorCourseValidator,
|
||||
} from '@/validators/CoursesInstructor.validator';
|
||||
|
||||
// ============================================================
|
||||
// addInstructorCourseValidator
|
||||
// ============================================================
|
||||
|
||||
describe('addInstructorCourseValidator', () => {
|
||||
it('should pass with valid user_id and course_id', () => {
|
||||
const { error } = addInstructorCourseValidator.validate({
|
||||
user_id: 1,
|
||||
course_id: 2,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without user_id', () => {
|
||||
const { error } = addInstructorCourseValidator.validate({ course_id: 2 });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail without course_id', () => {
|
||||
const { error } = addInstructorCourseValidator.validate({ user_id: 1 });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// CreateCourseValidator
|
||||
// ============================================================
|
||||
|
||||
describe('CreateCourseValidator', () => {
|
||||
const validPayload = {
|
||||
category_id: 1,
|
||||
title: { th: 'คอร์สทดสอบ', en: 'Test Course' },
|
||||
slug: 'test-course',
|
||||
description: { th: 'คำอธิบาย', en: 'Description' },
|
||||
price: 500,
|
||||
is_free: false,
|
||||
have_certificate: true,
|
||||
};
|
||||
|
||||
it('should pass with all required fields', () => {
|
||||
const { error } = CreateCourseValidator.validate(validPayload);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail if title.th is missing', () => {
|
||||
const { error } = CreateCourseValidator.validate({
|
||||
...validPayload,
|
||||
title: { en: 'Test Course' },
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if slug is missing', () => {
|
||||
const { error } = CreateCourseValidator.validate({
|
||||
...validPayload,
|
||||
slug: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if price is missing', () => {
|
||||
const { error } = CreateCourseValidator.validate({
|
||||
...validPayload,
|
||||
price: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if is_free is missing', () => {
|
||||
const { error } = CreateCourseValidator.validate({
|
||||
...validPayload,
|
||||
is_free: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should allow price = 0 (free course)', () => {
|
||||
const { error } = CreateCourseValidator.validate({
|
||||
...validPayload,
|
||||
price: 0,
|
||||
is_free: true,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// UpdateCourseValidator
|
||||
// ============================================================
|
||||
|
||||
describe('UpdateCourseValidator', () => {
|
||||
it('should pass with empty object (all optional)', () => {
|
||||
const { error } = UpdateCourseValidator.validate({});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with partial update', () => {
|
||||
const { error } = UpdateCourseValidator.validate({ price: 999 });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with title partial update (th only)', () => {
|
||||
const { error } = UpdateCourseValidator.validate({
|
||||
title: { th: 'ชื่อใหม่' },
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// CloneCourseValidator
|
||||
// ============================================================
|
||||
|
||||
describe('CloneCourseValidator', () => {
|
||||
it('should pass with valid title', () => {
|
||||
const { error } = CloneCourseValidator.validate({
|
||||
title: { th: 'คอร์ส Copy', en: 'Course Copy' },
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without title.th', () => {
|
||||
const { error } = CloneCourseValidator.validate({
|
||||
title: { en: 'Course Copy' },
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Thai title is required/i);
|
||||
});
|
||||
|
||||
it('should fail without title.en', () => {
|
||||
const { error } = CloneCourseValidator.validate({
|
||||
title: { th: 'คอร์ส Copy' },
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/English title is required/i);
|
||||
});
|
||||
|
||||
it('should fail without title entirely', () => {
|
||||
const { error } = CloneCourseValidator.validate({});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Title is required/i);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
import {
|
||||
SaveVideoProgressValidator,
|
||||
SubmitQuizValidator,
|
||||
} from '@/validators/CoursesStudent.validator';
|
||||
|
||||
describe('SaveVideoProgressValidator', () => {
|
||||
it('should pass with required field only', () => {
|
||||
const { error } = SaveVideoProgressValidator.validate({
|
||||
video_progress_seconds: 60,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with all fields', () => {
|
||||
const { error } = SaveVideoProgressValidator.validate({
|
||||
video_progress_seconds: 120,
|
||||
video_duration_seconds: 600,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with progress = 0 (start of video)', () => {
|
||||
const { error } = SaveVideoProgressValidator.validate({
|
||||
video_progress_seconds: 0,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without video_progress_seconds', () => {
|
||||
const { error } = SaveVideoProgressValidator.validate({});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Video progress seconds is required/i);
|
||||
});
|
||||
|
||||
it('should fail with negative progress', () => {
|
||||
const { error } = SaveVideoProgressValidator.validate({
|
||||
video_progress_seconds: -1,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/at least 0/i);
|
||||
});
|
||||
|
||||
it('should fail with negative video duration', () => {
|
||||
const { error } = SaveVideoProgressValidator.validate({
|
||||
video_progress_seconds: 10,
|
||||
video_duration_seconds: -1,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('SubmitQuizValidator', () => {
|
||||
const validAnswer = { question_id: 1, choice_id: 2 };
|
||||
|
||||
it('should pass with valid answers', () => {
|
||||
const { error } = SubmitQuizValidator.validate({
|
||||
answers: [validAnswer, { question_id: 2, choice_id: 5 }],
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without answers', () => {
|
||||
const { error } = SubmitQuizValidator.validate({});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Answers are required/i);
|
||||
});
|
||||
|
||||
it('should fail with empty answers array', () => {
|
||||
const { error } = SubmitQuizValidator.validate({ answers: [] });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/At least one answer/i);
|
||||
});
|
||||
|
||||
it('should fail if question_id is missing in an answer', () => {
|
||||
const { error } = SubmitQuizValidator.validate({
|
||||
answers: [{ choice_id: 2 }],
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Question ID is required/i);
|
||||
});
|
||||
|
||||
it('should fail if choice_id is missing in an answer', () => {
|
||||
const { error } = SubmitQuizValidator.validate({
|
||||
answers: [{ question_id: 1 }],
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Choice ID is required/i);
|
||||
});
|
||||
|
||||
it('should fail if question_id is not a positive integer', () => {
|
||||
const { error } = SubmitQuizValidator.validate({
|
||||
answers: [{ question_id: -1, choice_id: 1 }],
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
45
Backend/tests/unit/validators/Lessons.validator.test.ts
Normal file
45
Backend/tests/unit/validators/Lessons.validator.test.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { SetYouTubeVideoValidator } from '@/validators/Lessons.validator';
|
||||
|
||||
describe('SetYouTubeVideoValidator', () => {
|
||||
it('should pass with valid youtube_video_id and video_title', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
youtube_video_id: 'dQw4w9WgXcQ',
|
||||
video_title: 'Introduction to TypeScript',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without youtube_video_id', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
video_title: 'Intro to TS',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/YouTube video ID is required/i);
|
||||
});
|
||||
|
||||
it('should fail with empty youtube_video_id string', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
youtube_video_id: '',
|
||||
video_title: 'Intro to TS',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/cannot be empty/i);
|
||||
});
|
||||
|
||||
it('should fail without video_title', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
youtube_video_id: 'dQw4w9WgXcQ',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Video title is required/i);
|
||||
});
|
||||
|
||||
it('should fail with empty video_title string', () => {
|
||||
const { error } = SetYouTubeVideoValidator.validate({
|
||||
youtube_video_id: 'dQw4w9WgXcQ',
|
||||
video_title: '',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/cannot be empty/i);
|
||||
});
|
||||
});
|
||||
115
Backend/tests/unit/validators/announcements.validator.test.ts
Normal file
115
Backend/tests/unit/validators/announcements.validator.test.ts
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import {
|
||||
CreateAnnouncementValidator,
|
||||
UpdateAnnouncementValidator,
|
||||
} from '@/validators/announcements.validator';
|
||||
|
||||
describe('CreateAnnouncementValidator', () => {
|
||||
const validPayload = {
|
||||
title: { th: 'ประกาศใหม่', en: 'New Announcement' },
|
||||
content: { th: 'เนื้อหา', en: 'Content' },
|
||||
status: 'DRAFT',
|
||||
is_pinned: false,
|
||||
};
|
||||
|
||||
it('should pass with all required fields', () => {
|
||||
const { error } = CreateAnnouncementValidator.validate(validPayload);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with optional published_at as ISO date', () => {
|
||||
const { error } = CreateAnnouncementValidator.validate({
|
||||
...validPayload,
|
||||
published_at: '2026-03-01T00:00:00.000Z',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail with invalid published_at format', () => {
|
||||
const { error } = CreateAnnouncementValidator.validate({
|
||||
...validPayload,
|
||||
published_at: '01-03-2026',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/ISO date/i);
|
||||
});
|
||||
|
||||
it('should fail with invalid status', () => {
|
||||
const { error } = CreateAnnouncementValidator.validate({
|
||||
...validPayload,
|
||||
status: 'HIDDEN',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/DRAFT, PUBLISHED, ARCHIVED/i);
|
||||
});
|
||||
|
||||
it('should pass with PUBLISHED status', () => {
|
||||
const { error } = CreateAnnouncementValidator.validate({
|
||||
...validPayload,
|
||||
status: 'PUBLISHED',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with ARCHIVED status', () => {
|
||||
const { error } = CreateAnnouncementValidator.validate({
|
||||
...validPayload,
|
||||
status: 'ARCHIVED',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without title', () => {
|
||||
const { error } = CreateAnnouncementValidator.validate({
|
||||
...validPayload,
|
||||
title: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Title is required/i);
|
||||
});
|
||||
|
||||
it('should fail without content', () => {
|
||||
const { error } = CreateAnnouncementValidator.validate({
|
||||
...validPayload,
|
||||
content: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Content is required/i);
|
||||
});
|
||||
|
||||
it('should fail without is_pinned', () => {
|
||||
const { error } = CreateAnnouncementValidator.validate({
|
||||
...validPayload,
|
||||
is_pinned: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/is_pinned is required/i);
|
||||
});
|
||||
});
|
||||
|
||||
describe('UpdateAnnouncementValidator', () => {
|
||||
it('should pass with empty object (all optional)', () => {
|
||||
const { error } = UpdateAnnouncementValidator.validate({});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with partial update', () => {
|
||||
const { error } = UpdateAnnouncementValidator.validate({
|
||||
status: 'PUBLISHED',
|
||||
is_pinned: true,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail with invalid status', () => {
|
||||
const { error } = UpdateAnnouncementValidator.validate({ status: 'DELETED' });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail with invalid published_at format', () => {
|
||||
const { error } = UpdateAnnouncementValidator.validate({
|
||||
published_at: 'not-a-date',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/ISO date/i);
|
||||
});
|
||||
});
|
||||
246
Backend/tests/unit/validators/auth.validator.test.ts
Normal file
246
Backend/tests/unit/validators/auth.validator.test.ts
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
import {
|
||||
loginSchema,
|
||||
registerSchema,
|
||||
refreshTokenSchema,
|
||||
resetPasswordSchema,
|
||||
changePasswordSchema,
|
||||
resetRequestSchema,
|
||||
} from '@/validators/auth.validator';
|
||||
|
||||
// ============================================================
|
||||
// loginSchema
|
||||
// ============================================================
|
||||
|
||||
describe('loginSchema', () => {
|
||||
it('should pass with valid email and password', () => {
|
||||
const { error } = loginSchema.validate({
|
||||
email: 'user@example.com',
|
||||
password: 'password123',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail with invalid email format', () => {
|
||||
const { error } = loginSchema.validate({
|
||||
email: 'not-an-email',
|
||||
password: 'password123',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/valid email/i);
|
||||
});
|
||||
|
||||
it('should fail without email', () => {
|
||||
const { error } = loginSchema.validate({ password: 'password123' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Email is required/i);
|
||||
});
|
||||
|
||||
it('should fail without password', () => {
|
||||
const { error } = loginSchema.validate({ email: 'user@example.com' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Password is required/i);
|
||||
});
|
||||
|
||||
it('should fail with password shorter than 6 characters', () => {
|
||||
const { error } = loginSchema.validate({
|
||||
email: 'user@example.com',
|
||||
password: '12345',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/at least 6 characters/i);
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// registerSchema
|
||||
// ============================================================
|
||||
|
||||
describe('registerSchema', () => {
|
||||
const validPayload = {
|
||||
username: 'john_doe',
|
||||
email: 'john@example.com',
|
||||
password: 'securepass',
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
phone: '0812345678',
|
||||
};
|
||||
|
||||
it('should pass with all required fields', () => {
|
||||
const { error } = registerSchema.validate(validPayload);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with optional prefix', () => {
|
||||
const { error } = registerSchema.validate({
|
||||
...validPayload,
|
||||
prefix: { th: 'นาย', en: 'Mr.' },
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail if username has invalid characters', () => {
|
||||
const { error } = registerSchema.validate({
|
||||
...validPayload,
|
||||
username: 'john doe!',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/letters, numbers, and underscores/i);
|
||||
});
|
||||
|
||||
it('should fail if username is too short (< 3 chars)', () => {
|
||||
const { error } = registerSchema.validate({
|
||||
...validPayload,
|
||||
username: 'ab',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/at least 3 characters/i);
|
||||
});
|
||||
|
||||
it('should fail if username is too long (> 50 chars)', () => {
|
||||
const { error } = registerSchema.validate({
|
||||
...validPayload,
|
||||
username: 'a'.repeat(51),
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/not exceed 50 characters/i);
|
||||
});
|
||||
|
||||
it('should fail with invalid email', () => {
|
||||
const { error } = registerSchema.validate({
|
||||
...validPayload,
|
||||
email: 'bad-email',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if phone is too short (< 10 chars)', () => {
|
||||
const { error } = registerSchema.validate({
|
||||
...validPayload,
|
||||
phone: '081234',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail without first_name', () => {
|
||||
const { error } = registerSchema.validate({
|
||||
...validPayload,
|
||||
first_name: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/First name is required/i);
|
||||
});
|
||||
|
||||
it('should fail without last_name', () => {
|
||||
const { error } = registerSchema.validate({
|
||||
...validPayload,
|
||||
last_name: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Last name is required/i);
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// refreshTokenSchema
|
||||
// ============================================================
|
||||
|
||||
describe('refreshTokenSchema', () => {
|
||||
it('should pass with a valid refreshToken', () => {
|
||||
const { error } = refreshTokenSchema.validate({
|
||||
refreshToken: 'some-refresh-token-string',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without refreshToken', () => {
|
||||
const { error } = refreshTokenSchema.validate({});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Refresh token is required/i);
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// resetPasswordSchema
|
||||
// ============================================================
|
||||
|
||||
describe('resetPasswordSchema', () => {
|
||||
it('should pass with valid token and password', () => {
|
||||
const { error } = resetPasswordSchema.validate({
|
||||
token: 'reset-token-abc',
|
||||
password: 'newpassword',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without token', () => {
|
||||
const { error } = resetPasswordSchema.validate({ password: 'newpassword' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Reset token is required/i);
|
||||
});
|
||||
|
||||
it('should fail with password too short', () => {
|
||||
const { error } = resetPasswordSchema.validate({
|
||||
token: 'abc',
|
||||
password: '12345',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/at least 6 characters/i);
|
||||
});
|
||||
|
||||
it('should fail with password too long (> 100 chars)', () => {
|
||||
const { error } = resetPasswordSchema.validate({
|
||||
token: 'abc',
|
||||
password: 'a'.repeat(101),
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// changePasswordSchema (auth)
|
||||
// ============================================================
|
||||
|
||||
describe('changePasswordSchema (auth.validator)', () => {
|
||||
it('should pass with valid old and new passwords', () => {
|
||||
const { error } = changePasswordSchema.validate({
|
||||
oldPassword: 'oldpass123',
|
||||
newPassword: 'newpass456',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without oldPassword', () => {
|
||||
const { error } = changePasswordSchema.validate({ newPassword: 'newpass456' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Password is required/i);
|
||||
});
|
||||
|
||||
it('should fail without newPassword', () => {
|
||||
const { error } = changePasswordSchema.validate({ oldPassword: 'oldpass123' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Password is required/i);
|
||||
});
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// resetRequestSchema
|
||||
// ============================================================
|
||||
|
||||
describe('resetRequestSchema', () => {
|
||||
it('should pass with valid email', () => {
|
||||
const { error } = resetRequestSchema.validate({ email: 'user@example.com' });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without email', () => {
|
||||
const { error } = resetRequestSchema.validate({});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Email is required/i);
|
||||
});
|
||||
|
||||
it('should fail with invalid email', () => {
|
||||
const { error } = resetRequestSchema.validate({ email: 'not-email' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/valid email/i);
|
||||
});
|
||||
});
|
||||
121
Backend/tests/unit/validators/categories.validator.test.ts
Normal file
121
Backend/tests/unit/validators/categories.validator.test.ts
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import {
|
||||
CreateCategoryValidator,
|
||||
UpdateCategoryValidator,
|
||||
} from '@/validators/categories.validator';
|
||||
|
||||
describe('CreateCategoryValidator', () => {
|
||||
const validPayload = {
|
||||
name: { th: 'การพัฒนาเว็บ', en: 'Web Development' },
|
||||
slug: 'web-development',
|
||||
description: { th: 'หมวดหมู่การพัฒนาเว็บ', en: 'Web development category' },
|
||||
};
|
||||
|
||||
it('should pass with all required fields', () => {
|
||||
const { error } = CreateCategoryValidator.validate(validPayload);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with optional created_by', () => {
|
||||
const { error } = CreateCategoryValidator.validate({
|
||||
...validPayload,
|
||||
created_by: 1,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without name', () => {
|
||||
const { error } = CreateCategoryValidator.validate({
|
||||
...validPayload,
|
||||
name: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Name is required/i);
|
||||
});
|
||||
|
||||
it('should fail without name.th', () => {
|
||||
const { error } = CreateCategoryValidator.validate({
|
||||
...validPayload,
|
||||
name: { en: 'Web Development' },
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Thai name is required/i);
|
||||
});
|
||||
|
||||
it('should fail without slug', () => {
|
||||
const { error } = CreateCategoryValidator.validate({
|
||||
...validPayload,
|
||||
slug: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Slug is required/i);
|
||||
});
|
||||
|
||||
it('should fail with invalid slug format (uppercase)', () => {
|
||||
const { error } = CreateCategoryValidator.validate({
|
||||
...validPayload,
|
||||
slug: 'Web-Development',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/lowercase with hyphens/i);
|
||||
});
|
||||
|
||||
it('should fail with invalid slug format (spaces)', () => {
|
||||
const { error } = CreateCategoryValidator.validate({
|
||||
...validPayload,
|
||||
slug: 'web development',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should pass with valid slug formats', () => {
|
||||
const slugs = ['web', 'web-dev', 'web-development-101'];
|
||||
for (const slug of slugs) {
|
||||
const { error } = CreateCategoryValidator.validate({
|
||||
...validPayload,
|
||||
slug,
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
}
|
||||
});
|
||||
|
||||
it('should fail without description', () => {
|
||||
const { error } = CreateCategoryValidator.validate({
|
||||
...validPayload,
|
||||
description: undefined,
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Description is required/i);
|
||||
});
|
||||
});
|
||||
|
||||
describe('UpdateCategoryValidator', () => {
|
||||
it('should pass with only required id', () => {
|
||||
const { error } = UpdateCategoryValidator.validate({ id: 1 });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with all optional fields', () => {
|
||||
const { error } = UpdateCategoryValidator.validate({
|
||||
id: 1,
|
||||
name: { th: 'ใหม่', en: 'New' },
|
||||
slug: 'new-category',
|
||||
description: { th: 'คำอธิบาย', en: 'Description' },
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without id', () => {
|
||||
const { error } = UpdateCategoryValidator.validate({ name: { th: 'ใหม่', en: 'New' } });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Category ID is required/i);
|
||||
});
|
||||
|
||||
it('should fail with invalid slug format', () => {
|
||||
const { error } = UpdateCategoryValidator.validate({
|
||||
id: 1,
|
||||
slug: 'Invalid Slug!',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/lowercase with hyphens/i);
|
||||
});
|
||||
});
|
||||
100
Backend/tests/unit/validators/user.validator.test.ts
Normal file
100
Backend/tests/unit/validators/user.validator.test.ts
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import {
|
||||
profileUpdateSchema,
|
||||
changePasswordSchema,
|
||||
} from '@/validators/user.validator';
|
||||
|
||||
describe('profileUpdateSchema', () => {
|
||||
it('should pass with empty object (all optional)', () => {
|
||||
const { error } = profileUpdateSchema.validate({});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with all fields', () => {
|
||||
const { error } = profileUpdateSchema.validate({
|
||||
prefix: { th: 'นาย', en: 'Mr.' },
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
phone: '0812345678',
|
||||
avatar_url: 'https://example.com/avatar.jpg',
|
||||
birth_date: new Date('1990-01-01'),
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should pass with partial update (first_name only)', () => {
|
||||
const { error } = profileUpdateSchema.validate({ first_name: 'Jane' });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail if first_name is empty string', () => {
|
||||
const { error } = profileUpdateSchema.validate({ first_name: '' });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if first_name exceeds 100 characters', () => {
|
||||
const { error } = profileUpdateSchema.validate({ first_name: 'a'.repeat(101) });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if phone is too short (< 10 chars)', () => {
|
||||
const { error } = profileUpdateSchema.validate({ phone: '081234' });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if phone exceeds 15 characters', () => {
|
||||
const { error } = profileUpdateSchema.validate({ phone: '1'.repeat(16) });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should pass with valid birth_date', () => {
|
||||
const { error } = profileUpdateSchema.validate({ birth_date: new Date('2000-06-15') });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('changePasswordSchema (user.validator)', () => {
|
||||
it('should pass with valid old and new passwords', () => {
|
||||
const { error } = changePasswordSchema.validate({
|
||||
oldPassword: 'oldpass123',
|
||||
newPassword: 'newpass456',
|
||||
});
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without oldPassword', () => {
|
||||
const { error } = changePasswordSchema.validate({ newPassword: 'newpass456' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Old password is required/i);
|
||||
});
|
||||
|
||||
it('should fail without newPassword', () => {
|
||||
const { error } = changePasswordSchema.validate({ oldPassword: 'oldpass123' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/New password is required/i);
|
||||
});
|
||||
|
||||
it('should fail if oldPassword is shorter than 6 chars', () => {
|
||||
const { error } = changePasswordSchema.validate({
|
||||
oldPassword: '12345',
|
||||
newPassword: 'newpass456',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/at least 6 characters/i);
|
||||
});
|
||||
|
||||
it('should fail if newPassword is shorter than 6 chars', () => {
|
||||
const { error } = changePasswordSchema.validate({
|
||||
oldPassword: 'oldpass123',
|
||||
newPassword: '123',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail if oldPassword exceeds 100 characters', () => {
|
||||
const { error } = changePasswordSchema.validate({
|
||||
oldPassword: 'a'.repeat(101),
|
||||
newPassword: 'newpass456',
|
||||
});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
import {
|
||||
getUserByIdValidator,
|
||||
updateUserRoleValidator,
|
||||
} from '@/validators/usermanagement.validator';
|
||||
|
||||
describe('getUserByIdValidator', () => {
|
||||
it('should pass with valid id', () => {
|
||||
const { error } = getUserByIdValidator.validate({ id: 1 });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without id', () => {
|
||||
const { error } = getUserByIdValidator.validate({});
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail with non-numeric id', () => {
|
||||
const { error } = getUserByIdValidator.validate({ id: 'abc' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/ID must be a number/i);
|
||||
});
|
||||
|
||||
it('should pass with id = 0', () => {
|
||||
// Joi number() allows 0 by default unless positive() is specified
|
||||
const { error } = getUserByIdValidator.validate({ id: 0 });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateUserRoleValidator', () => {
|
||||
it('should pass with valid id and role_id', () => {
|
||||
const { error } = updateUserRoleValidator.validate({ id: 1, role_id: 2 });
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should fail without id', () => {
|
||||
const { error } = updateUserRoleValidator.validate({ role_id: 2 });
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should fail without role_id', () => {
|
||||
const { error } = updateUserRoleValidator.validate({ id: 1 });
|
||||
expect(error).toBeDefined();
|
||||
// Joi uses field name in message when custom messages don't match
|
||||
expect(error?.details[0].message).toContain('role_id');
|
||||
});
|
||||
|
||||
it('should fail with non-numeric role_id', () => {
|
||||
const { error } = updateUserRoleValidator.validate({ id: 1, role_id: 'admin' });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/Role ID must be a number/i);
|
||||
});
|
||||
|
||||
it('should fail with non-numeric id', () => {
|
||||
const { error } = updateUserRoleValidator.validate({ id: 'abc', role_id: 1 });
|
||||
expect(error).toBeDefined();
|
||||
expect(error?.details[0].message).toMatch(/ID must be a number/i);
|
||||
});
|
||||
});
|
||||
20
Backend/tsconfig.test.json
Normal file
20
Backend/tsconfig.test.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
"types": [
|
||||
"node",
|
||||
"jest"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"tests/**/*"
|
||||
]
|
||||
}
|
||||
1
Frontend-Learner/.nuxtrc
Normal file
1
Frontend-Learner/.nuxtrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
setups.@nuxt/test-utils="4.0.0"
|
||||
|
|
@ -7,8 +7,8 @@ WORKDIR /app
|
|||
# คัดลอกไฟล์จัดการ dependencies
|
||||
COPY package*.json ./
|
||||
|
||||
# ติดตั้ง dependencies (ใช้ npm ci เพื่อความแม่นยำของเวอร์ชัน)
|
||||
RUN npm ci
|
||||
# ติดตั้ง dependencies
|
||||
RUN npm install
|
||||
|
||||
# คัดลอกไฟล์ทั้งหมดในโปรเจกต์
|
||||
COPY . .
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ onMounted(() => {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<!-- แสดง Loader ระหว่างเปลี่ยนหน้า หรือโหลดข้อมูล -->
|
||||
<GlobalLoader />
|
||||
<!-- แสดงแถบโหลดด้านบนจอ (Progress Bar) แทนการโหลดเต็มหน้าจอ -->
|
||||
<NuxtLoadingIndicator color="#2563EB" :height="4" />
|
||||
|
||||
<!-- NuxtLayout: แสดง Layout ที่กำหนดในแต่ละเพจ (default: layouts/default.vue) -->
|
||||
<NuxtLayout>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file AnnouncementModal.vue
|
||||
* @description Modal component to display course announcements
|
||||
* @description คอมโพเนนต์ Modal สำหรับแสดงประกาศของคอร์สเรียน (Modal component to display course announcements)
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
|
|
@ -15,7 +15,7 @@ const emit = defineEmits<{
|
|||
|
||||
const { locale, t } = useI18n()
|
||||
|
||||
// Helper for localization
|
||||
// ตัวช่วยจัดการข้อความหลายภาษา (Helper for localization)
|
||||
const getLocalizedText = (text: any) => {
|
||||
if (!text) return ''
|
||||
if (typeof text === 'string') return text
|
||||
|
|
@ -49,7 +49,7 @@ const getLocalizedText = (text: any) => {
|
|||
class="p-5 rounded-2xl bg-white dark:bg-slate-800 shadow-sm border border-gray-200 dark:border-white/5 transition-all hover:shadow-md relative overflow-hidden group"
|
||||
:class="{'ring-2 ring-orange-200 dark:ring-orange-900/40 !bg-orange-50/50 dark:!bg-orange-900/20': ann.is_pinned}"
|
||||
>
|
||||
<!-- Pinned Banner -->
|
||||
<!-- ป้ายกำกับสำหรับข้อความที่ปักหมุดไว้ (Pinned Banner) -->
|
||||
<div v-if="ann.is_pinned" class="absolute top-0 right-0 p-3">
|
||||
<q-icon name="push_pin" color="orange" size="18px" class="transform rotate-45" />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file CurriculumSidebar.vue
|
||||
* @description Sidebar Component for displaying course curriculum (Chapters & Lessons)
|
||||
* Handles lesson navigation, locked status display, and unread announcement badge.
|
||||
* @description คอมโพเนนต์แถบเมนูด้านข้างสำหรับแสดงหลักสูตรของคอร์สเรียน (บทเรียน & ตอนต่างๆ)
|
||||
* จัดการการนำทางไปยังบทเรียน, แสดงสถานะการล็อค, และแจ้งเตือนประกาศที่ยังไม่ได้อ่าน
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean; // Sidebar open state (v-model)
|
||||
modelValue: boolean; // สถานะการเปิด/ปิดของ Sidebar (Sidebar open state - v-model)
|
||||
courseData: any;
|
||||
currentLessonId?: number;
|
||||
isLoading: boolean;
|
||||
|
|
@ -21,10 +21,10 @@ const emit = defineEmits<{
|
|||
|
||||
const { locale } = useI18n()
|
||||
|
||||
// State for expansion items
|
||||
// สถานะของส่วนที่ขยายได้ (State for expansion items)
|
||||
const chapterOpenState = ref<Record<string, boolean>>({})
|
||||
|
||||
// Helper for localization
|
||||
// ตัวช่วยจัดการข้อความหลายภาษา (Helper for localization)
|
||||
const getLocalizedText = (text: any) => {
|
||||
if (!text) return ''
|
||||
if (typeof text === 'string') return text
|
||||
|
|
@ -34,13 +34,13 @@ const getLocalizedText = (text: any) => {
|
|||
return text[currentLocale] || text.th || text.en || ''
|
||||
}
|
||||
|
||||
// Helper: Check if lesson is completed
|
||||
// ตัวช่วยตรวจสอบว่าบทเรียนเรียนจบหรือยัง (Helper: Check if lesson is completed)
|
||||
const isLessonCompleted = (lesson: any) => {
|
||||
return lesson.is_completed === true || lesson.progress?.is_completed === true
|
||||
}
|
||||
|
||||
// Reactive Chapter Completion Status
|
||||
// Computes a map of chapterId -> boolean (true if all lessons are completed)
|
||||
// ตรวจสอบสถานะการสำเร็จของบท (Reactive Chapter Completion Status)
|
||||
// คำนวณเป็น Map ของ chapterId -> boolean (true ถ้าทุกบทเรียนย่อยเรียนจบแล้ว)
|
||||
const chapterCompletionStatus = computed(() => {
|
||||
const status: Record<string, boolean> = {}
|
||||
if (!props.courseData || !props.courseData.chapters) return status
|
||||
|
|
@ -55,7 +55,7 @@ const chapterCompletionStatus = computed(() => {
|
|||
return status
|
||||
})
|
||||
|
||||
// Local Progress Calculation
|
||||
// คำนวณความคืบหน้าแบบ Local (Local Progress Calculation)
|
||||
const progressPercentage = computed(() => {
|
||||
if (!props.courseData || !props.courseData.chapters) return 0
|
||||
let total = 0
|
||||
|
|
@ -69,7 +69,7 @@ const progressPercentage = computed(() => {
|
|||
return total > 0 ? Math.round((completed / total) * 100) : 0
|
||||
})
|
||||
|
||||
// Auto-expand chapter containing current lesson
|
||||
// ขยายบทเรียนปัจจุบันอัตโนมัติ (Auto-expand chapter containing current lesson)
|
||||
watch(() => props.currentLessonId, (newId) => {
|
||||
if (newId && props.courseData?.chapters) {
|
||||
props.courseData.chapters.forEach((chapter: any) => {
|
||||
|
|
@ -81,7 +81,7 @@ watch(() => props.currentLessonId, (newId) => {
|
|||
}
|
||||
}, { immediate: true })
|
||||
|
||||
// Initialize all chapters as open by default on load
|
||||
// ตั้งค่าเริ่มต้นให้ทุกบทเรียนเปิดอยู่เมื่อโหลด (Initialize all chapters as open by default on load)
|
||||
watch(() => props.courseData, (newData) => {
|
||||
if (newData?.chapters) {
|
||||
newData.chapters.forEach((chapter: any) => {
|
||||
|
|
@ -104,10 +104,10 @@ watch(() => props.courseData, (newData) => {
|
|||
:breakpoint="1024"
|
||||
class="bg-slate-50 dark:!bg-slate-900 shadow-xl"
|
||||
>
|
||||
<!-- Main Container: Enforce Column Layout and Full Width -->
|
||||
<!-- คอนเทนเนอร์หลักบังคับใช้ความกว้างเต็มที่ (Main Container: Enforce Column Layout and Full Width) -->
|
||||
<div v-if="courseData" class="flex flex-col w-full h-full overflow-hidden text-slate-900 dark:!text-white relative bg-slate-50 dark:!bg-slate-900">
|
||||
|
||||
<!-- 1. Header Section (Fixed at Top) -->
|
||||
<!-- 1. ส่วนหัว ด้านบนคงที่ (Header Section - Fixed at Top) -->
|
||||
<div class="flex-none p-5 border-b border-slate-200 dark:border-white/10 bg-white dark:!bg-slate-900 z-10 w-full">
|
||||
<h2 class="text-sm font-bold mb-4 line-clamp-2 leading-snug block w-full text-slate-900 dark:!text-white">{{ getLocalizedText(courseData.course.title) }}</h2>
|
||||
|
||||
|
|
@ -123,11 +123,11 @@ watch(() => props.courseData, (newData) => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 2. Curriculum List (Scrollable Area) -->
|
||||
<!-- 2. รายการหลักสูตร พื้นที่เลื่อนได้ (Curriculum List - Scrollable Area) -->
|
||||
<div class="flex-1 overflow-y-auto bg-slate-50 dark:!bg-slate-900 w-full p-4 space-y-3">
|
||||
<q-list class="block w-full">
|
||||
<div v-for="(chapter, idx) in courseData.chapters" :key="chapter.id" class="block w-full mb-3">
|
||||
<!-- Chapter Accordion -->
|
||||
<!-- กล่องข้อมูลของบท (Chapter Accordion) -->
|
||||
<q-expansion-item
|
||||
v-model="chapterOpenState[chapter.id]"
|
||||
class="bg-white dark:!bg-slate-800 rounded-xl overflow-hidden shadow-sm border border-slate-200 dark:border-slate-700 w-full"
|
||||
|
|
@ -137,7 +137,7 @@ watch(() => props.courseData, (newData) => {
|
|||
<template v-slot:header>
|
||||
<div class="flex items-center w-full py-3 text-slate-900 dark:!text-white">
|
||||
<div class="mr-3 flex-shrink-0">
|
||||
<!-- Chapter Indicator (Check or Number) -->
|
||||
<!-- ตัวบ่งชี้บทเรียน เครื่องหมายถูกหรือตัวเลข (Chapter Indicator - Check or Number) -->
|
||||
<div class="w-7 h-7 rounded-full border-2 flex items-center justify-center transition-colors font-bold"
|
||||
:class="chapterCompletionStatus[chapter.id]
|
||||
? 'border-green-500 text-green-500 bg-green-50 dark:!bg-green-500/10'
|
||||
|
|
@ -146,7 +146,7 @@ watch(() => props.courseData, (newData) => {
|
|||
<span v-else class="text-[10px]">{{ Number(idx) + 1 }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Explicitly handle text overflow -->
|
||||
<!-- จัดการตัวอักษรที่ล้นเกินอย่างชัดเจน (Explicitly handle text overflow) -->
|
||||
<div class="flex-1 min-w-0 pr-2 overflow-hidden">
|
||||
<div class="font-bold text-sm leading-tight mb-0.5 truncate block w-full">{{ getLocalizedText(chapter.title) }}</div>
|
||||
<div class="text-[10px] text-slate-500 dark:!text-slate-400 font-normal truncate block w-full">
|
||||
|
|
@ -156,7 +156,7 @@ watch(() => props.courseData, (newData) => {
|
|||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Lessons List -->
|
||||
<!-- รายการบทเรียนย่อย (Lessons List) -->
|
||||
<div class="bg-slate-50 dark:!bg-slate-800/50 border-t border-slate-100 dark:border-slate-700 w-full">
|
||||
<div
|
||||
v-for="(lesson, lIdx) in chapter.lessons"
|
||||
|
|
@ -167,27 +167,27 @@ watch(() => props.courseData, (newData) => {
|
|||
: 'border-transparent'"
|
||||
@click="!lesson.is_locked && emit('select-lesson', lesson.id)"
|
||||
>
|
||||
<!-- Lesson Status Icon -->
|
||||
<!-- ไอคอนสถานะของบทเรียน (Lesson Status Icon) -->
|
||||
<div class="mr-3 flex-shrink-0">
|
||||
<!-- Completed (Takes Precedence) -->
|
||||
<!-- เรียนจบแล้ว (สำคัญที่สุด) (Completed - Takes Precedence) -->
|
||||
<q-icon v-if="isLessonCompleted(lesson)"
|
||||
name="check_circle"
|
||||
class="text-green-500"
|
||||
size="20px"
|
||||
/>
|
||||
<!-- Active/Playing (If not completed) -->
|
||||
<!-- กำลังเรียนอยู่ (Active/Playing - If not completed) -->
|
||||
<q-icon v-else-if="currentLessonId === lesson.id"
|
||||
name="play_circle_filled"
|
||||
class="text-blue-600 dark:!text-blue-400 animate-pulse"
|
||||
size="20px"
|
||||
/>
|
||||
<!-- Locked -->
|
||||
<!-- ถูกล็อคอยู่ (Locked) -->
|
||||
<q-icon v-else-if="lesson.is_locked"
|
||||
name="lock"
|
||||
class="text-slate-400 dark:!text-slate-500 opacity-70"
|
||||
size="18px"
|
||||
/>
|
||||
<!-- Not Started -->
|
||||
<!-- ยังไม่ได้เริ่ม (Not Started) -->
|
||||
<div v-else class="w-[18px] h-[18px] rounded-full border-2 border-slate-300 dark:border-slate-600"></div>
|
||||
</div>
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ watch(() => props.courseData, (newData) => {
|
|||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Custom scrollbar for better aesthetics */
|
||||
/* สครอลบาร์ปรับแต่งเพื่อความสวยงาม (Custom scrollbar for better aesthetics) */
|
||||
::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file VideoPlayer.vue
|
||||
* @description Video Player Component with custom controls provided by design
|
||||
* @description คอมโพเนนต์เครื่องเล่นวิดีโอพร้อมด้วยตัวควบคุมแบบกำหนดเองตามการออกแบบ (Video Player Component with custom controls provided by design)
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
|
|
@ -22,7 +22,7 @@ const videoProgress = ref(0);
|
|||
const currentTime = ref(0);
|
||||
const duration = ref(0);
|
||||
|
||||
// Media Prefs
|
||||
// การตั้งค่าเกี่ยวกับสื่อ (Media Prefs)
|
||||
const { volume, muted: isMuted, setVolume, setMuted, applyTo } = useMediaPrefs();
|
||||
|
||||
const volumeIcon = computed(() => {
|
||||
|
|
@ -40,7 +40,7 @@ const formatTime = (time: number) => {
|
|||
const currentTimeDisplay = computed(() => formatTime(currentTime.value));
|
||||
const durationDisplay = computed(() => formatTime(duration.value || 0));
|
||||
|
||||
// YouTube Helper Logic
|
||||
// ตรรกะตัวช่วยสำหรับ YouTube (YouTube Helper Logic)
|
||||
const isYoutube = computed(() => {
|
||||
const s = props.src.toLowerCase();
|
||||
return s.includes('youtube.com') || s.includes('youtu.be');
|
||||
|
|
@ -50,7 +50,7 @@ const youtubeEmbedUrl = computed(() => {
|
|||
if (!isYoutube.value) return '';
|
||||
let videoId = '';
|
||||
|
||||
// Extract Video ID
|
||||
// ดึงรหัสวิดีโอ (Extract Video ID)
|
||||
if (props.src.includes('youtu.be')) {
|
||||
videoId = props.src.split('youtu.be/')[1]?.split('?')[0];
|
||||
} else {
|
||||
|
|
@ -58,18 +58,18 @@ const youtubeEmbedUrl = computed(() => {
|
|||
videoId = urlParams.get('v') || '';
|
||||
}
|
||||
|
||||
// Return Embed URL with enablejsapi=1
|
||||
// คืนค่า URL สำหรับฝังพร้อมเปิดใช้งาน jsapi (Return Embed URL with enablejsapi=1)
|
||||
return `https://www.youtube.com/embed/${videoId}?enablejsapi=1&rel=0`;
|
||||
});
|
||||
|
||||
// YouTube API Tracking
|
||||
// การติดตามผ่าน YouTube API (YouTube API Tracking)
|
||||
let ytPlayer: any = null;
|
||||
let ytInterval: any = null;
|
||||
|
||||
const initYoutubeAPI = () => {
|
||||
if (!isYoutube.value || typeof window === 'undefined') return;
|
||||
|
||||
// Load API Script if not exists
|
||||
// โหลดสคริปต์ API หากยังไม่มี (Load API Script if not exists)
|
||||
if (!(window as any).YT) {
|
||||
const tag = document.createElement('script');
|
||||
tag.src = "https://www.youtube.com/iframe_api";
|
||||
|
|
@ -83,7 +83,7 @@ const initYoutubeAPI = () => {
|
|||
'onReady': (event: any) => {
|
||||
duration.value = event.target.getDuration();
|
||||
|
||||
// Resume Logic for YouTube
|
||||
// ตรรกะการเล่นต่อสำหรับ YouTube (Resume Logic for YouTube)
|
||||
if (props.initialSeekTime && props.initialSeekTime > 0) {
|
||||
event.target.seekTo(props.initialSeekTime, true);
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ const startYTTracking = () => {
|
|||
currentTime.value = ytPlayer.getCurrentTime();
|
||||
emit('timeupdate', currentTime.value, duration.value);
|
||||
}
|
||||
}, 1000); // Check every second
|
||||
}, 1000); // ตรวจสอบทุกๆ วินาที (Check every second)
|
||||
};
|
||||
|
||||
const stopYTTracking = () => {
|
||||
|
|
@ -145,7 +145,7 @@ onUnmounted(() => {
|
|||
destroyYoutubePlayer();
|
||||
});
|
||||
|
||||
// Watch for src change to re-init
|
||||
// เฝ้าดูการเปลี่ยนแปลงของ src เพื่อเริ่มต้นใหม่ (Watch for src change to re-init)
|
||||
watch(() => props.src, (newSrc, oldSrc) => {
|
||||
if (newSrc !== oldSrc) {
|
||||
destroyYoutubePlayer();
|
||||
|
|
@ -174,8 +174,8 @@ const togglePlay = () => {
|
|||
playPromise.then(() => {
|
||||
isPlaying.value = true;
|
||||
}).catch(error => {
|
||||
// Auto-play was prevented or play was interrupted
|
||||
// We can safely ignore this error
|
||||
// การเล่นอัตโนมัติถูกป้องกันหรือถูกขัดจังหวะ (Auto-play was prevented or play was interrupted)
|
||||
// สามารถละเว้นข้อผิดพลาดนี้ได้อย่างปลอดภัย (We can safely ignore this error)
|
||||
console.log("Video play request handled:", error.name);
|
||||
});
|
||||
}
|
||||
|
|
@ -223,14 +223,14 @@ const handleVolumeChange = (val: any) => {
|
|||
setVolume(newVol);
|
||||
};
|
||||
|
||||
// Expose video ref for parent to control if needed
|
||||
// เปิดเผย video ref ให้คอมโพเนนต์แม่ควบคุมถ้าจำเป็น (Expose video ref for parent to control if needed)
|
||||
defineExpose({
|
||||
videoRef,
|
||||
pause: () => videoRef.value?.pause(),
|
||||
currentTime: () => videoRef.value?.currentTime || 0
|
||||
});
|
||||
|
||||
// Watch for volume/mute changes to apply to video element
|
||||
// เฝ้าดูการเปลี่ยนแปลงระดับเสียง/ปิดเสียง เพื่อนำไปใช้กับองค์ประกอบวิดีโอ (Watch for volume/mute changes to apply to video element)
|
||||
watch([volume, isMuted], () => {
|
||||
if (videoRef.value) applyTo(videoRef.value);
|
||||
});
|
||||
|
|
@ -238,7 +238,7 @@ watch([volume, isMuted], () => {
|
|||
|
||||
<template>
|
||||
<div class="bg-black rounded-xl overflow-hidden shadow-2xl mb-6 aspect-video relative group ring-1 ring-white/10">
|
||||
<!-- 1. YouTube Player -->
|
||||
<!-- 1. เครื่องเล่น YouTube (YouTube Player) -->
|
||||
<iframe
|
||||
v-if="isYoutube"
|
||||
id="youtube-iframe"
|
||||
|
|
@ -249,7 +249,7 @@ watch([volume, isMuted], () => {
|
|||
allowfullscreen
|
||||
></iframe>
|
||||
|
||||
<!-- 2. Standard HTML5 Video Player -->
|
||||
<!-- 2. เครื่องเล่นวิดีโอ HTML5 มาตรฐาน (Standard HTML5 Video Player) -->
|
||||
<div v-else class="w-full h-full relative group/video cursor-pointer">
|
||||
<video
|
||||
ref="videoRef"
|
||||
|
|
@ -262,9 +262,9 @@ watch([volume, isMuted], () => {
|
|||
@ended="handleEnded"
|
||||
/>
|
||||
|
||||
<!-- Custom Controls Overlay (Only for HTML5 Video) -->
|
||||
<!-- เลเยอร์ควบคุมแบบกำหนดเอง (Overlay) เฉพาะสำหรับวิดีโอ HTML5 เท่านั้น (Custom Controls Overlay (Only for HTML5 Video)) -->
|
||||
<div class="absolute bottom-0 left-0 right-0 p-6 bg-gradient-to-t from-black/90 via-black/40 to-transparent transition-opacity opacity-0 group-hover/video:opacity-100 flex flex-col gap-3">
|
||||
<!-- Progress Bar -->
|
||||
<!-- แถบแสดงความคืบหน้า (Progress Bar) -->
|
||||
<div class="relative flex-grow h-1.5 bg-white/20 rounded-full cursor-pointer group/progress overflow-hidden" @click="seek">
|
||||
<div class="absolute top-0 left-0 h-full bg-blue-500 rounded-full group-hover/progress:bg-blue-400 transition-all shadow-[0_0_12px_rgba(59,130,246,0.6)]" :style="{ width: videoProgress + '%' }"></div>
|
||||
</div>
|
||||
|
|
@ -275,7 +275,7 @@ watch([volume, isMuted], () => {
|
|||
|
||||
<div class="flex-grow"></div>
|
||||
|
||||
<!-- Volume Control -->
|
||||
<!-- ตัวควบคุมระดับเสียง (Volume Control) -->
|
||||
<div class="flex items-center gap-2 group/volume relative">
|
||||
<q-btn flat round dense :icon="volumeIcon" @click.stop="handleToggleMute" color="white" class="hover:scale-110 transition-transform" />
|
||||
<div class="w-0 group-hover/volume:w-24 overflow-hidden transition-all duration-300 flex items-center bg-black/60 backdrop-blur-md rounded-full px-2">
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file FormInput.vue
|
||||
* @description Reusable input component with label, error handling, and support for disabled/required states.
|
||||
* Now supports password visibility toggle.
|
||||
* @description คอมโพเนนต์ช่องกรอกข้อมูล (Input) แบบนำกลับมาใช้ใหม่ได้ พร้อมรองรับข้อความป้ายกำกับ, จัดการข้อผิดพลาด และสถานะปิดใช้งาน/บังคับกรอก
|
||||
* รองรับการสลับซ่อน/แสดงรหัสผ่าน
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
|
|
@ -16,19 +16,19 @@ const props = defineProps<{
|
|||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** Update v-model value */
|
||||
/** อัปเดตค่า v-model (Update v-model value) */
|
||||
'update:modelValue': [value: string]
|
||||
}>()
|
||||
|
||||
// Password visibility state
|
||||
// สถานะการซ่อน/แสดงรหัสผ่าน (Password visibility state)
|
||||
const showPassword = ref(false)
|
||||
|
||||
// Toggle function
|
||||
// ฟังก์ชันสำหรับสลับสถานะ (Toggle function)
|
||||
const togglePassword = () => {
|
||||
showPassword.value = !showPassword.value
|
||||
}
|
||||
|
||||
// Compute input type based on visibility state
|
||||
// คำนวณประเภทของช่องกรอกข้อมูล بناءً pada state (Compute input type based on visibility state)
|
||||
const inputType = computed(() => {
|
||||
if (props.type === 'password') {
|
||||
return showPassword.value ? 'text' : 'password'
|
||||
|
|
@ -59,7 +59,7 @@ const updateValue = (event: Event) => {
|
|||
@input="updateValue"
|
||||
>
|
||||
|
||||
<!-- Password Toggle Button -->
|
||||
<!-- ปุ่มสลับซ่อน/แสดงรหัสผ่าน (Password Toggle Button) -->
|
||||
<button
|
||||
v-if="type === 'password'"
|
||||
type="button"
|
||||
|
|
@ -67,13 +67,13 @@ const updateValue = (event: Event) => {
|
|||
@click="togglePassword"
|
||||
tabindex="-1"
|
||||
>
|
||||
<!-- Eye Icon (Show) -->
|
||||
<!-- ไอคอนเปิดตา (แสดงรหัสผ่าน) (Eye Icon - Show) -->
|
||||
<svg v-if="!showPassword" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/>
|
||||
<circle cx="12" cy="12" r="3"/>
|
||||
</svg>
|
||||
|
||||
<!-- Eye Off Icon (Hide) -->
|
||||
<!-- ไอคอนปิดตา (ซ่อนรหัสผ่าน) (Eye Off Icon - Hide) -->
|
||||
<svg v-else xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/>
|
||||
<path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/>
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file GlobalLoader.vue
|
||||
* @description Global full-screen loading overlay that triggers during page navigation.
|
||||
* Uses a premium pulsing logo animation.
|
||||
* @description คอมโพเนนต์หน้าจอโหลดแบบเต็มจอ (Global full-screen loading) แสดงผลตอนเปลี่ยนหน้า
|
||||
* พร้มแอนิเมชันโลโก้ขยับได้แบบพรีเมียม
|
||||
*/
|
||||
|
||||
const nuxtApp = useNuxtApp()
|
||||
const isLoading = ref(false)
|
||||
|
||||
// Hook into Nuxt page transitions
|
||||
// ดักจับจังหวะการเปลี่ยนหน้าผ่าย Nuxt hook (Hook into Nuxt page transitions)
|
||||
nuxtApp.hook('page:start', () => {
|
||||
isLoading.value = true
|
||||
})
|
||||
|
||||
nuxtApp.hook('page:finish', () => {
|
||||
// Add a small delay for better UX (prevents flickering on fast loads)
|
||||
// หน่วงเวลาเล็กน้อยเพื่อให้ไหลลื่น ไม่กระพริบเร็วไปหากหน้าโหลดเสร็จไว (Add a small delay for better UX)
|
||||
setTimeout(() => {
|
||||
isLoading.value = false
|
||||
}, 500)
|
||||
|
|
@ -25,14 +25,14 @@ nuxtApp.hook('page:finish', () => {
|
|||
<Transition name="fade">
|
||||
<div v-if="isLoading" class="fixed inset-0 z-[99999] flex flex-col items-center justify-center bg-white dark:bg-[#0f172a] transition-colors duration-300">
|
||||
<div class="relative flex flex-col items-center">
|
||||
<!-- Main Logo Box -->
|
||||
<!-- กล่องโลโก้หลัก (Main Logo Box) -->
|
||||
<div class="w-20 h-20 bg-blue-50 dark:bg-blue-900/20 rounded-2xl flex items-center justify-center mb-6 animate-pulse-soft">
|
||||
<div class="w-12 h-12 bg-blue-600 rounded-xl flex items-center justify-center shadow-lg shadow-blue-600/30 animate-bounce-subtle">
|
||||
<span class="text-2xl font-black text-white">E</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading Text -->
|
||||
<!-- ข้อความระหว่างโหลด (Loading Text) -->
|
||||
<div class="flex flex-col items-center gap-2">
|
||||
<h3 class="text-lg font-bold text-slate-800 dark:text-white tracking-wide">e-Learning</h3>
|
||||
<div class="flex gap-1">
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file LanguageSwitcher.vue
|
||||
* @description Language switcher component using Quasar dropdown.
|
||||
* Allows switching between Thai (th) and English (en) locales.
|
||||
* @description คอมโพเนนต์ตัวสลับภาษาใช้ปุ่ม Dropdown ของ Quasar
|
||||
* ใช้สลับระหว่างภาษาไทย (th) และภาษาอังกฤษ (en)
|
||||
*/
|
||||
|
||||
const { locale, setLocale, locales } = useI18n()
|
||||
|
||||
// Get available locales with their names
|
||||
// ดึงรายการภาษาที่มีอยู่พร้อมชื่อภาษา (Get available locales with their names)
|
||||
const availableLocales = computed(() => {
|
||||
return (locales.value as Array<{ code: string; name: string }>).map((loc) => ({
|
||||
code: loc.code,
|
||||
|
|
@ -15,13 +15,13 @@ const availableLocales = computed(() => {
|
|||
}))
|
||||
})
|
||||
|
||||
// Get flag image path for a locale
|
||||
// ดึงพาธภาพธงชาติสำหรับภาษานั้นๆ (Get flag image path for a locale)
|
||||
const getFlagPath = (code: string) => `/flags/${code}.png`
|
||||
|
||||
// Handle locale change
|
||||
// จัดการเมื่อเปลี่ยนภาษา (Handle locale change)
|
||||
const changeLocale = async (code: string) => {
|
||||
await setLocale(code as 'th' | 'en')
|
||||
// Cookie is automatically handled by @nuxtjs/i18n with detectBrowserLanguage.useCookie
|
||||
// คุกกี้ (Cookie) จะถูกจัดการอัตโนมัติโดย @nuxtjs/i18n จากออปชัน detectBrowserLanguage.useCookie
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ const changeLocale = async (code: string) => {
|
|||
class="language-btn"
|
||||
:aria-label="$t('language.label')"
|
||||
>
|
||||
<!-- Show current locale flag -->
|
||||
<!-- แสดงธงชาติตามภาษาที่ใช้อยู่ (Show current locale flag) -->
|
||||
<img
|
||||
:src="getFlagPath(locale)"
|
||||
:alt="locale.toUpperCase()"
|
||||
|
|
@ -178,7 +178,7 @@ const changeLocale = async (code: string) => {
|
|||
</style>
|
||||
|
||||
<style>
|
||||
/* Global styles for teleported menu */
|
||||
/* สไตล์ Global สำหรับเมนูที่ถูกข้ามไปแสดงผลที่อื่นด้วย Teleport (Global styles for teleported menu) */
|
||||
.language-menu {
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file LoadingSkeleton.vue
|
||||
* @description คอมโพเนนต์ Skeleton สำหรับแสดงโครงร่างหน้าจอระหว่างรอโหลดข้อมูล (Loading Skeleton Component)
|
||||
*/
|
||||
defineProps<{
|
||||
type?: 'text' | 'avatar' | 'card' | 'button'
|
||||
width?: string
|
||||
|
|
@ -9,6 +13,7 @@ defineProps<{
|
|||
|
||||
<template>
|
||||
<div class="skeleton-wrapper">
|
||||
<!-- กรณีเป็นโครงร่างประเภทการ์ด (Card type skeleton) -->
|
||||
<template v-if="type === 'card'">
|
||||
<div v-for="i in (count || 1)" :key="i" class="skeleton-card">
|
||||
<div class="skeleton skeleton-image"/>
|
||||
|
|
@ -20,14 +25,17 @@ defineProps<{
|
|||
</div>
|
||||
</template>
|
||||
|
||||
<!-- กรณีเป็นโครงร่างประเภทรูปโปรไฟล์ (Avatar type skeleton) -->
|
||||
<template v-else-if="type === 'avatar'">
|
||||
<div class="skeleton skeleton-avatar"/>
|
||||
</template>
|
||||
|
||||
<!-- กรณีเป็นโครงร่างประเภทปุ่มกด (Button type skeleton) -->
|
||||
<template v-else-if="type === 'button'">
|
||||
<div class="skeleton skeleton-button" :style="{ width: width || '120px' }"/>
|
||||
</template>
|
||||
|
||||
<!-- กรณีอื่นๆ จะแสดงเป็นบรรทัดข้อความ (Fallback/Text type skeleton) -->
|
||||
<template v-else>
|
||||
<div
|
||||
v-for="i in (count || 1)"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file LoadingSpinner.vue
|
||||
* @description ไอคอนหมุนแสดงการโหลด (Loading Spinner Component) เหมาะสำหรับใช้ตรงจุดเล็กๆ หรือตอนโหลดหน้าเว็บ
|
||||
*/
|
||||
defineProps<{
|
||||
size?: 'sm' | 'md' | 'lg'
|
||||
text?: string
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file CourseCard.vue
|
||||
* @description Standardized Course Card Component.
|
||||
* Usage: <CourseCard :id="1" title="..." ... />
|
||||
* @description คอมโพเนนต์การ์ดแสดงคอร์สเรียนมาตรฐาน (Standardized Course Card Component)
|
||||
* วิธีใช้งาน: <CourseCard :id="1" title="..." ... />
|
||||
*/
|
||||
|
||||
interface CourseCardProps {
|
||||
|
|
@ -20,7 +20,7 @@ interface CourseCardProps {
|
|||
image?: string
|
||||
loading?: boolean
|
||||
|
||||
// Action Flags
|
||||
// ตัวควบคุมการแสดงปุ่มต่างๆ (Action Flags)
|
||||
showViewDetails?: boolean
|
||||
showContinue?: boolean
|
||||
showCertificate?: boolean
|
||||
|
|
@ -59,7 +59,7 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
|||
<template>
|
||||
<div class="group relative flex flex-col bg-white dark:!bg-slate-900 rounded-3xl overflow-hidden border border-slate-200 dark:border-white/5 shadow-sm hover:shadow-xl dark:shadow-none hover:-translate-y-1 transition-all duration-300 h-full">
|
||||
|
||||
<!-- Thumbnail Section -->
|
||||
<!-- ส่วนรูปหน้าปก (Thumbnail Section) -->
|
||||
<div class="relative w-full aspect-video overflow-hidden">
|
||||
<img
|
||||
v-if="image"
|
||||
|
|
@ -71,12 +71,12 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
|||
<q-icon name="image" size="48px" class="text-slate-300 dark:text-slate-600" />
|
||||
</div>
|
||||
|
||||
<!-- Overlays -->
|
||||
<!-- เลเยอร์ฟิลเตอร์ซ้อนทับ (Overlays) -->
|
||||
<div class="absolute inset-0 bg-gradient-to-t from-slate-900/60 to-transparent opacity-0 group-hover:opacity-100 transition-opacity"></div>
|
||||
|
||||
|
||||
|
||||
<!-- Completed Badge -->
|
||||
<!-- ป้ายแสดงสถานะเรียนจบ (Completed Badge) -->
|
||||
<div v-if="completed" class="absolute inset-0 bg-emerald-900/40 backdrop-blur-[2px] flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity duration-300">
|
||||
<span class="bg-emerald-500 text-white w-12 h-12 rounded-full flex items-center justify-center shadow-lg transform scale-75 group-hover:scale-100 transition-transform">
|
||||
<q-icon name="check" size="24px" />
|
||||
|
|
@ -84,9 +84,9 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content Section -->
|
||||
<!-- ส่วนเนื้อหาข้อมูล (Content Section) -->
|
||||
<div class="p-6 flex flex-col flex-grow">
|
||||
<!-- Meta Info (Lessons/Duration) -->
|
||||
<!-- ข้อมูลประกอบย่อย เช่น บทเรียน/ระยะเวลา (Meta Info - Lessons/Duration) -->
|
||||
<div class="flex items-center gap-3 text-xs font-bold text-slate-500 dark:text-slate-400 mb-3 uppercase tracking-wider">
|
||||
<span v-if="lessons" class="flex items-center gap-1">
|
||||
<q-icon name="menu_book" size="14px" /> {{ lessons }} {{ $t('course.lessonsUnit') }}
|
||||
|
|
@ -96,18 +96,18 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
|||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Title -->
|
||||
<!-- ชื่อคอร์ส (Title) -->
|
||||
<h3 class="text-lg font-black text-slate-900 dark:text-white mb-2 line-clamp-2 leading-tight group-hover:text-blue-600 dark:group-hover:text-blue-400 transition-colors">
|
||||
{{ displayTitle }}
|
||||
</h3>
|
||||
|
||||
<!-- Description -->
|
||||
<!-- รายละเอียดเพิ่มเติม (Description) -->
|
||||
<p v-if="displayDescription" class="text-sm text-slate-500 dark:text-slate-400 line-clamp-2 mb-6">
|
||||
{{ displayDescription }}
|
||||
</p>
|
||||
|
||||
<div class="mt-auto pt-4">
|
||||
<!-- Progress Bar -->
|
||||
<!-- หลอดความคืบหน้า (Progress Bar) -->
|
||||
<div v-if="progress !== undefined && !completed && !hideProgress" class="mb-4">
|
||||
<div class="flex justify-between text-[10px] font-bold uppercase mb-1">
|
||||
<span class="text-slate-500 dark:text-slate-400">{{ $t('course.progress') }}</span>
|
||||
|
|
@ -118,9 +118,9 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<!-- ปุ่มปฏิบัติการต่างๆ (Action Buttons) -->
|
||||
<div v-if="!hideActions" class="flex flex-col gap-3">
|
||||
<!-- View Details (Secondary Action) -->
|
||||
<!-- ปุ่มดูรายละเอียด (ปุ่มรอง) (View Details - Secondary Action) -->
|
||||
<q-btn
|
||||
v-if="showViewDetails && !completed && !progress"
|
||||
flat
|
||||
|
|
@ -130,7 +130,7 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
|||
:to="`/course/${id}`"
|
||||
/>
|
||||
|
||||
<!-- Continue Learning (Primary Action) -->
|
||||
<!-- ปุ่มเรียนต่อ/เริ่มเรียน (ปุ่มหลัก) (Continue Learning - Primary Action) -->
|
||||
<q-btn
|
||||
v-if="showContinue || (progress && !completed) || (progress === 0 && !completed)"
|
||||
unelevated
|
||||
|
|
@ -142,7 +142,7 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
|||
</div>
|
||||
|
||||
<div v-if="completed" class="space-y-2">
|
||||
<!-- Study Again -->
|
||||
<!-- ปุ่มเรียนอีกครั้ง (Study Again) -->
|
||||
<q-btn
|
||||
v-if="showStudyAgain"
|
||||
unelevated
|
||||
|
|
@ -152,7 +152,7 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
|||
:to="`/classroom/learning?course_id=${id}`"
|
||||
/>
|
||||
|
||||
<!-- Download Certificate -->
|
||||
<!-- ปุ่มดาวน์โหลดใบรับรอง (Download Certificate) -->
|
||||
<q-btn
|
||||
v-if="showCertificate"
|
||||
unelevated
|
||||
|
|
@ -168,5 +168,5 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
|||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Scoped overrides if needed */
|
||||
/* ใส่โค้ด CSS เพิ่มได้ถ้าต้องการครอบคลุมเฉพาะไฟล์นี้ (Scoped overrides if needed) */
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file CategorySidebar.vue
|
||||
* @description Sidebar for filtering courses by category
|
||||
* @description แถบเมนูด้านข้างสำหรับกรองคอร์สตามหมวดหมู่ (Sidebar for filtering courses by category)
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
|
|
@ -81,13 +81,13 @@ const toggleCategory = (id: number) => {
|
|||
{{ getLocalizedText(cat.name) }}
|
||||
</span>
|
||||
|
||||
<!-- Active Indicator Dot -->
|
||||
<!-- จุดแสดงสถานะเมื่อถูกเลือก (Active Indicator Dot) -->
|
||||
<div v-if="modelValue.includes(cat.id)" class="ml-auto w-1.5 h-1.5 rounded-full bg-blue-600 dark:bg-blue-400 shadow-lg shadow-blue-500/50"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Show More/Less Action -->
|
||||
<!-- ปุ่มแสดงเพิ่มเติม/แสดงน้อยลง (Show More/Less Action) -->
|
||||
<div
|
||||
v-if="categories.length > 5"
|
||||
@click="showAllCategories = !showAllCategories"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file CourseDetailView.vue
|
||||
* @description Quick view of course details including video preview, curriculum, and enroll logic
|
||||
* @description แสดงรายละเอียดคอร์สแบบรวดเร็ว รวมถึงตัวอย่างวิดีโอ, หลักสูตร, และระบบการลงทะเบียน
|
||||
*/
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
|
|
@ -51,9 +51,9 @@ const handleEnroll = () => {
|
|||
if(!props.course) return;
|
||||
enrollmentLoading.value = true;
|
||||
emit('enroll', props.course.id);
|
||||
// Loading state reset depends on parent, but locally we can reset after emit or keep until prop changes
|
||||
// In this pattern, we just emit.
|
||||
setTimeout(() => enrollmentLoading.value = false, 2000); // Safety timeout
|
||||
// สถานะ Loading ถูกจัดการโดยคอมโพเนนต์แม่ แต่ในคอมโพเนนต์นี้เรารีเซ็ตหลังจากส่ง event หรือเก็บไว้จนกว่า prop จะเปลี่ยน
|
||||
// ในรูปแบบนี้ เราแค่ส่ง event ออกไป (just emit)
|
||||
setTimeout(() => enrollmentLoading.value = false, 2000); // ตั้งเวลารีเซ็ตเพื่อความปลอดภัย (Safety timeout)
|
||||
};
|
||||
const instructorData = computed(() => {
|
||||
if (props.course?.instructors && props.course.instructors.length > 0) {
|
||||
|
|
@ -67,10 +67,10 @@ const instructorData = computed(() => {
|
|||
<template>
|
||||
<div class="animate-fade-in-up">
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
||||
<!-- Left: Content Detail -->
|
||||
<!-- ด้านซ้าย: รายละเอียดเนื้อหา (Left: Content Detail) -->
|
||||
<div class="lg:col-span-2 space-y-8">
|
||||
|
||||
<!-- Video Preview Section -->
|
||||
<!-- ส่วนแสดงตัวอย่างวิดีโอ (Video Preview Section) -->
|
||||
<div class="relative aspect-video rounded-3xl overflow-hidden shadow-2xl group cursor-pointer bg-slate-900 border-4 border-white dark:border-slate-800 transition-transform duration-500 hover:scale-[1.01]">
|
||||
<template v-if="course.media?.video_url">
|
||||
<video
|
||||
|
|
@ -81,19 +81,19 @@ const instructorData = computed(() => {
|
|||
<source :src="course.media.video_url" type="video/mp4">
|
||||
{{ $t('course.videoNotSupported') }}
|
||||
</video>
|
||||
<!-- Custom Play Overlay when not playing - simple version is often best -->
|
||||
<!-- ปุ่มเล่นวิดีโอแบบปรับแต่งเองตอนยังไม่เล่น (Custom Play Overlay when not playing) -->
|
||||
</template>
|
||||
<!-- Beautiful Image Showcase if no video -->
|
||||
<!-- แสดงรูปภาพสวยๆ กรณีที่ไม่มีวิดีโอ (Beautiful Image Showcase if no video) -->
|
||||
<template v-else>
|
||||
<div class="w-full h-full flex items-center justify-center relative overflow-hidden bg-slate-950 group">
|
||||
<!-- Blurred background fill -->
|
||||
<!-- รูปพื้นหลังเบลอ (Blurred background fill) -->
|
||||
<img
|
||||
v-if="course.thumbnail_url || course.cover_image"
|
||||
:src="course.thumbnail_url || course.cover_image"
|
||||
class="absolute inset-0 w-full h-full object-cover opacity-40 blur-2xl scale-125"
|
||||
/>
|
||||
|
||||
<!-- Main Sharp Image -->
|
||||
<!-- รูปหลักแบบคมชัด (Main Sharp Image) -->
|
||||
<img
|
||||
v-if="course.thumbnail_url || course.cover_image"
|
||||
:src="course.thumbnail_url || course.cover_image"
|
||||
|
|
@ -107,7 +107,7 @@ const instructorData = computed(() => {
|
|||
</template>
|
||||
</div>
|
||||
|
||||
<!-- Course Title & Description -->
|
||||
<!-- ชื่อคอร์สและรายละเอียด (Course Title & Description) -->
|
||||
<div>
|
||||
<h1 class="text-3xl md:text-4xl font-extrabold text-slate-900 dark:text-white mb-4 leading-tight">
|
||||
{{ getLocalizedText(course.title) }}
|
||||
|
|
@ -118,10 +118,10 @@ const instructorData = computed(() => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Course Detail - Single Page Layout -->
|
||||
<!-- รายละเอียดคอร์ส - รูแแบบหน้าเดียว (Course Detail - Single Page Layout) -->
|
||||
<div class="space-y-10">
|
||||
|
||||
<!-- Instructor Info -->
|
||||
<!-- ข้อมูลผู้สอน (Instructor Info) -->
|
||||
<div class="flex flex-col sm:flex-row gap-6 items-start sm:items-center pb-8 border-b border-slate-200 dark:border-slate-800">
|
||||
<q-avatar size="64px">
|
||||
<img :src="instructorData?.profile?.avatar_url || 'https://cdn.quasar.dev/img/boy-avatar.png'" />
|
||||
|
|
@ -135,7 +135,7 @@ const instructorData = computed(() => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Curriculum / Lesson Details -->
|
||||
<!-- รายละเอียดหลักสูตร / บทเรียน (Curriculum / Lesson Details) -->
|
||||
<div>
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h3 class="text-xl font-bold text-slate-900 dark:text-white">
|
||||
|
|
@ -148,7 +148,7 @@ const instructorData = computed(() => {
|
|||
|
||||
<div class="space-y-4">
|
||||
<div v-for="(chapter, idx) in course.chapters" :key="chapter.id" class="group">
|
||||
<!-- Chapter Header -->
|
||||
<!-- ส่วนหัวของบท (Chapter Header) -->
|
||||
<div class="px-6 py-4 bg-white dark:bg-slate-800 rounded-2xl border border-slate-200 dark:border-white/5 font-black text-slate-800 dark:text-white flex justify-between items-center mb-2 shadow-sm">
|
||||
<span class="flex items-center gap-3">
|
||||
<span class="w-7 h-7 flex items-center justify-center bg-slate-100 dark:bg-white/10 rounded-lg text-xs font-bold font-mono">{{ Number(idx) + 1 }}</span>
|
||||
|
|
@ -157,7 +157,7 @@ const instructorData = computed(() => {
|
|||
<span class="text-[10px] uppercase font-black tracking-widest text-slate-400 opacity-60">{{ chapter.lessons?.length || 0 }} {{ $t('course.lessonsUnit') }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Lessons List -->
|
||||
<!-- รายการบทเรียน (Lessons List) -->
|
||||
<div class="ml-4 pl-4 border-l-2 border-slate-100 dark:border-slate-800 space-y-1 mt-3">
|
||||
<div v-for="lesson in chapter.lessons" :key="lesson.id" class="px-5 py-3 flex items-center gap-3 text-sm text-slate-600 dark:text-slate-400 hover:bg-white dark:hover:bg-white/5 rounded-xl transition-all hover:translate-x-1">
|
||||
<div class="w-8 h-8 rounded-full flex items-center justify-center shrink-0" :class="lesson.type === 'VIDEO' ? 'bg-blue-50 text-blue-600 dark:bg-blue-500/10 dark:text-blue-400' : 'bg-orange-50 text-orange-600 dark:bg-orange-500/10 dark:text-orange-400'">
|
||||
|
|
@ -173,7 +173,7 @@ const instructorData = computed(() => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<!-- กรณีที่ไม่มีข้อมูล (Empty State) -->
|
||||
<div v-if="!course.chapters || course.chapters.length === 0" class="flex flex-col items-center justify-center py-12 text-slate-400 dark:text-slate-500 bg-white/50 dark:bg-slate-900/50 rounded-2xl border-2 border-dashed border-slate-200 dark:border-slate-800">
|
||||
<q-icon name="menu_book" size="40px" class="mb-2 opacity-50" />
|
||||
<p class="text-sm font-medium">{{ $t('course.noContent') }}</p>
|
||||
|
|
@ -185,11 +185,11 @@ const instructorData = computed(() => {
|
|||
|
||||
</div>
|
||||
|
||||
<!-- Right: Enrollment Card -->
|
||||
<!-- ด้านขวา: การ์ดลงทะเบียน (Right: Enrollment Card) -->
|
||||
<div class="lg:col-span-1">
|
||||
<div class="sticky top-24">
|
||||
<div class="bg-white dark:bg-slate-900 rounded-3xl shadow-2xl shadow-blue-500/10 dark:shadow-none p-8 border border-slate-100 dark:border-white/5 relative overflow-hidden group">
|
||||
<!-- Decorative background glow -->
|
||||
<!-- ลูกเล่นแสงพื้นหลังตกแต่ง (Decorative background glow) -->
|
||||
<div class="absolute -top-12 -right-12 w-48 h-48 bg-blue-500/10 rounded-full blur-3xl group-hover:bg-blue-500/20 transition-colors"></div>
|
||||
|
||||
<div class="relative">
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file AppHeader.vue
|
||||
* @description The main header for the EduLearn application dashboard.
|
||||
* @description แถบเมนูด้านบนหลัก (Header) สำหรับหน้าแดชบอร์ด (Dashboard) ของระบบ EduLearn
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
/** Controls visibility of the sidebar toggle button */
|
||||
/** ควบคุมการแสดงผลของปุ่มเปิด/ปิดแถบเมนูด้านข้าง (Sidebar) */
|
||||
showSidebarToggle?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** Emitted when the hamburger menu is clicked */
|
||||
/** ส่งสัญญาณ (Emit) เมื่อผู้ใช้คลิกที่ปุ่มแฮมเบอร์เกอร์เมนู */
|
||||
toggleSidebar: [];
|
||||
}>();
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ const toggleTheme = () => {
|
|||
<template>
|
||||
<q-toolbar class="bg-white dark:!bg-[#020617] text-slate-900 dark:!text-white h-20 border-b border-slate-50 dark:border-slate-800/50 px-6">
|
||||
|
||||
<!-- Left: Hamburger Toggle -->
|
||||
<!-- ด้านซ้าย: ปุ่มย่อขยายแถบเมนูด้านข้าง (Hamburger Toggle) -->
|
||||
<q-btn
|
||||
flat
|
||||
round
|
||||
|
|
@ -43,10 +43,10 @@ const toggleTheme = () => {
|
|||
|
||||
<q-space />
|
||||
|
||||
<!-- Right Section -->
|
||||
<!-- ส่วนการตั้งค่าทางด้านขวา (Right Section) -->
|
||||
<div class="flex items-center gap-2 sm:gap-4 md:gap-6 no-wrap">
|
||||
|
||||
<!-- Theme Toggle -->
|
||||
<!-- ปุ่มสลับธีม (Theme Toggle) -->
|
||||
<q-btn
|
||||
flat
|
||||
round
|
||||
|
|
@ -60,7 +60,7 @@ const toggleTheme = () => {
|
|||
<q-tooltip>{{ isDark ? 'โหมดกลางคืน' : 'โหมดกลางวัน' }}</q-tooltip>
|
||||
</q-btn>
|
||||
|
||||
<!-- Language Switcher (Pill Style) -->
|
||||
<!-- ตัวสลับภาษาแบบแคปซูล (Language Switcher) -->
|
||||
<div
|
||||
@click="toggleLanguage"
|
||||
class="flex items-center bg-slate-50 dark:bg-slate-800/50 border border-slate-100 dark:border-slate-800 rounded-xl p-0.5 sm:p-1 cursor-pointer hover:bg-slate-100 transition-all font-bold text-[11px] sm:text-[13px] select-none"
|
||||
|
|
@ -70,7 +70,7 @@ const toggleTheme = () => {
|
|||
<div :class="locale === 'en' ? 'bg-white dark:bg-slate-700 shadow-sm text-blue-600' : 'text-slate-400'" class="px-2 sm:px-3 py-1 rounded-lg transition-all">EN</div>
|
||||
</div>
|
||||
|
||||
<!-- Divider -->
|
||||
<!-- เส้นคั่น (Divider) -->
|
||||
<div class="hidden sm:block w-[1px] h-8 bg-slate-100 dark:bg-slate-800"></div>
|
||||
|
||||
<!-- ส่วนข้อมูลผู้ใช้งาน (User Profile) -->
|
||||
|
|
@ -102,12 +102,12 @@ const toggleTheme = () => {
|
|||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Ensure toolbar height is consistent */
|
||||
/* บังคับให้ความสูงของ Header เท่ากันเสมอ (Ensure toolbar height is consistent) */
|
||||
:deep(.q-toolbar) {
|
||||
min-height: 80px;
|
||||
}
|
||||
|
||||
/* Hide user name only on small mobile screens */
|
||||
/* ซ่อนชื่อผู้ใช้ไว้เฉพาะบนหน้าจอมือถือขนาดเล็กเท่านั้น (Hide user name only on small mobile screens) */
|
||||
@media (max-width: 600px) {
|
||||
.user-info-text {
|
||||
display: none !important;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ const handleLogout = () => {
|
|||
<template>
|
||||
<div class="flex flex-col h-full bg-white dark:!bg-[#04091a] px-4 py-6 border-r border-slate-100 dark:border-slate-800">
|
||||
|
||||
<!-- Logo Section -->
|
||||
<!-- โลโก้แบรนด์ (Logo Section) -->
|
||||
<div class="flex items-center gap-3 px-2 mb-10 transition-transform active:scale-95 cursor-pointer" @click="navigateTo('/dashboard')">
|
||||
<div class="w-10 h-10 rounded-xl bg-blue-600 flex items-center justify-center shadow-lg shadow-blue-500/20">
|
||||
<q-icon name="school" color="white" size="24px" />
|
||||
|
|
@ -59,7 +59,7 @@ const handleLogout = () => {
|
|||
<span class="text-[22px] font-black tracking-tight text-slate-800 dark:text-white">EduLearn</span>
|
||||
</div>
|
||||
|
||||
<!-- Main Navigation -->
|
||||
<!-- การนำทางหลัก (Main Navigation) -->
|
||||
<div class="space-y-1 mb-8">
|
||||
<NuxtLink
|
||||
v-for="item in menuItems"
|
||||
|
|
@ -71,12 +71,12 @@ const handleLogout = () => {
|
|||
<q-icon :name="item.icon" size="24px" class="transition-colors" />
|
||||
<span class="font-bold text-[15px]">{{ item.label }}</span>
|
||||
|
||||
<!-- Active Indicator -->
|
||||
<!-- ตัวบ่งชี้หน้าปัจจุบัน (Active Indicator) -->
|
||||
<div v-if="route.path === item.to" class="absolute left-0 top-1/2 -translate-y-1/2 w-1.5 h-6 bg-blue-600 rounded-r-full shadow-[2px_0_8px_rgba(37,99,235,0.4)]"></div>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
|
||||
<!-- Account Section -->
|
||||
<!-- หมวดหมู่บัญชี (Account Section) -->
|
||||
<div class="px-4 mb-4">
|
||||
<span class="text-[12px] font-bold text-slate-400 uppercase tracking-widest">{{ $t('sidebar.accountGroup') }}</span>
|
||||
</div>
|
||||
|
|
@ -92,7 +92,7 @@ const handleLogout = () => {
|
|||
<span class="font-bold text-[15px]">{{ item.label }}</span>
|
||||
</NuxtLink>
|
||||
|
||||
<!-- Logout Button -->
|
||||
<!-- ปุ่มออกจากระบบ (Logout Button) -->
|
||||
<button
|
||||
@click="handleLogout"
|
||||
class="w-full flex items-center gap-4 px-4 py-3 rounded-2xl transition-all text-red-500 hover:bg-red-50 dark:hover:bg-red-900/10 font-bold text-[15px] group"
|
||||
|
|
@ -104,7 +104,7 @@ const handleLogout = () => {
|
|||
|
||||
<q-space />
|
||||
|
||||
<!-- Promo Card -->
|
||||
<!-- การ์ดโปรโมชั่น (Promo Card) -->
|
||||
<div class="mt-auto p-5 rounded-[2rem] bg-slate-50 dark:bg-slate-800/50 border border-slate-100 dark:border-slate-800 relative overflow-hidden group">
|
||||
<div class="relative z-10">
|
||||
<h4 class="font-black text-slate-800 dark:text-white text-sm mb-1">{{ $t('sidebar.promoTitle') }}</h4>
|
||||
|
|
@ -118,7 +118,7 @@ const handleLogout = () => {
|
|||
</q-btn>
|
||||
</div>
|
||||
|
||||
<!-- Subtle background decoration -->
|
||||
<!-- การตกแต่งพื้นหลังแบบจางๆ (Subtle background decoration) -->
|
||||
<div class="absolute -right-2 -bottom-2 w-16 h-16 bg-blue-500/5 rounded-full blur-xl"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file LandingFooter.vue
|
||||
* @description Footer component for the landing page - Adjusted to Image 2 (E-Learning Platform Branding)
|
||||
* @description ส่วนท้ายของหน้าแรก (Footer component for the landing page)
|
||||
*/
|
||||
</script>
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
<footer class="bg-white pt-16 pb-8 border-t border-slate-200">
|
||||
<div class="container mx-auto px-6 md:px-12">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-8 mb-12 text-left">
|
||||
<!-- Brand -->
|
||||
<!-- โลโก้และชื่อแบรนด์ (Brand) -->
|
||||
<div class="space-y-6">
|
||||
<NuxtLink to="/" class="flex items-center gap-3 group">
|
||||
<div class="bg-blue-600 text-white font-black rounded-full px-6 w-10 h-10 flex items-center justify-center group-hover:scale-110 transition-transform">
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Links -->
|
||||
<!-- ลิงก์ต่างๆ (Links) -->
|
||||
<div class="lg:pl-8">
|
||||
<h4 class="font-bold text-slate-900 mb-6 text-base tracking-tight">คอร์สเรียน</h4>
|
||||
<ul class="space-y-3 text-sm text-slate-500 flex flex-col gap-2">
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Support -->
|
||||
<!-- การสนับสนุนผู้ใช้ (Support) -->
|
||||
<div>
|
||||
<h4 class="font-bold text-slate-900 mb-6 text-base">ช่วยเหลือ</h4>
|
||||
<ul class="space-y-3 text-sm text-slate-500 flex flex-col gap-2">
|
||||
|
|
@ -50,11 +50,11 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Contact (Bronco Hourse Data) -->
|
||||
<!-- ข้อมูลการติดต่อ (Contact) -->
|
||||
<div class="space-y-6">
|
||||
<h4 class="font-bold text-slate-900 text-base">ติดต่อเรา</h4>
|
||||
<div class="flex flex-col gap-5">
|
||||
<!-- Location -->
|
||||
<!-- สถานที่ตั้ง (Location) -->
|
||||
<div class="flex flex-row items-start gap-4 flex-nowrap">
|
||||
<q-icon name="o_location_on" size="20px" color="slate-800" />
|
||||
<div class="flex flex-col gap-1 min-w-0">
|
||||
|
|
@ -65,18 +65,18 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Phone -->
|
||||
<!-- เบอร์โทรศัพท์ (Phone) -->
|
||||
<div class="flex flex-row items-center gap-4 flex-nowrap">
|
||||
<q-icon name="o_phone" size="18px" color="slate-800" />
|
||||
<a href="tel:052-076-025" class="font-semibold text-slate-800 text-sm hover:text-blue-600 font-semibold text-sm transition-colors truncate">
|
||||
<a href="tel:052-076-025" class="font-semibold text-slate-800 text-sm hover:text-blue-600 transition-colors truncate">
|
||||
052-076-025
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Email -->
|
||||
<!-- อีเมล (Email) -->
|
||||
<div class="flex flex-row items-center gap-4 flex-nowrap">
|
||||
<q-icon name="o_email" size="18px" color="slate-800" />
|
||||
<a href="mailto:info@chamomind.com" class="font-semibold text-slate-800 text-sm hover:text-blue-600 font-semibold text-sm transition-colors truncate">
|
||||
<a href="mailto:info@chamomind.com" class="font-semibold text-slate-800 text-sm hover:text-blue-600 transition-colors truncate">
|
||||
info@chamomind.com
|
||||
</a>
|
||||
</div>
|
||||
|
|
@ -84,7 +84,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bottom Bar (Centered Copyright) -->
|
||||
<!-- แถบด้านล่างสำหรับสงวนลิขสิทธิ์ (Bottom Bar - Centered Copyright) -->
|
||||
<div class="pt-8 border-t border-slate-200 text-center">
|
||||
<p class="text-sm text-slate-400 font-medium tracking-wide">
|
||||
Copyright © CHAMOMIND CO., LTD. 2023
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file LandingHeader.vue
|
||||
* @description The main header for the public landing pages.
|
||||
* Features a transparent background that becomes solid/glass upon scrolling.
|
||||
* Responsive: Collapses into a drawer on mobile (md breakpoint).
|
||||
* @description คอมโพเนนต์แถบเมนูด้านบน (Header Navigation) สำหรับหน้า Landing Page และหน้าเปิดอื่นๆ
|
||||
* รองรับการเปลี่ยนภาษา เปลี่ยนโหมดสว่าง/มืด และเข้าถึงเมนูผู้ใช้ (Profile/Logout)
|
||||
*/
|
||||
const text = ref('');
|
||||
|
||||
// Track scrolling state to adjust header styling
|
||||
// ติดตามสถานะการเลื่อนเมาส์ (scroll) เพื่อปรับรูปแบบของ Header
|
||||
const isScrolled = ref(false)
|
||||
const { isAuthenticated } = useAuth()
|
||||
// Mobile Drawer State
|
||||
// สถานะเมนูสำหรับหน้าจอมือถือ (Mobile Drawer State)
|
||||
// ตัวแปรควบคุมการเปิด/ปิดเมนูบนหน้าจอขนาดเล็ก (Mobile Drawer)
|
||||
const mobileMenuOpen = ref(false)
|
||||
|
||||
const handleScroll = () => {
|
||||
isScrolled.value = window.scrollY > 20
|
||||
}
|
||||
|
||||
// Lock body scroll when mobile menu is open
|
||||
// ปิดการเลื่อนหน้าเว็บ (Lock body scroll) เมื่อเปิดเมนูบนมือถือ
|
||||
watch(mobileMenuOpen, (isOpen) => {
|
||||
if (isOpen) {
|
||||
document.body.style.overflow = 'hidden'
|
||||
|
|
@ -32,21 +31,21 @@ onMounted(() => {
|
|||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('scroll', handleScroll)
|
||||
document.body.style.overflow = '' // Cleanup
|
||||
document.body.style.overflow = '' // คืนค่าเริ่มต้น (Cleanup)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!--
|
||||
Header Container
|
||||
- Transitions between transparent and glass effect based on scroll.
|
||||
คอนเทนเนอร์ของ Header (Header Container)
|
||||
- เปลี่ยนจากสีใส (transparent) เป็นเอฟเฟกต์กระจก (glass effect) เมื่อเลื่อนเมาส์ลง
|
||||
-->
|
||||
<header
|
||||
class="fixed top-0 left-0 right-0 z-[100] transition-all"
|
||||
:class="[isScrolled ? 'h-20 glass-nav shadow-lg' : 'h-20 bg-transparent duration-300 border-b border-b-grey-7 ']"
|
||||
>
|
||||
<div class="container mx-auto px-6 md:px-12 h-full flex items-center justify-between">
|
||||
<!-- Left Section: Logo -->
|
||||
<!-- ด้านซ้าย: โลโก้แบรนด์ (Left Section: Logo) -->
|
||||
<NuxtLink to="/" class="flex items-center gap-3 group">
|
||||
<div class="bg-blue-600 text-white font-black rounded-full px-6 w-10 h-10 flex items-center justify-center group-hover:scale-110 transition-transform">
|
||||
<q-icon name="o_school" size="24px" />
|
||||
|
|
@ -67,7 +66,7 @@ onUnmounted(() => {
|
|||
</div>
|
||||
</NuxtLink>
|
||||
|
||||
<!-- Desktop Navigation (Visible by default, hidden on mobile via CSS 'desktop-nav') -->
|
||||
<!-- การนำทางสำหรับเดสก์ท็อป (แสดงผลเป็นค่าเริ่มต้น, ซ่อนบนมือถือผ่าน CSS 'desktop-nav') -->
|
||||
<!-- <nav class="flex desktop-nav items-center gap-8 text-[16px] font-medium">
|
||||
<NuxtLink
|
||||
to="/browse"
|
||||
|
|
@ -89,10 +88,10 @@ onUnmounted(() => {
|
|||
|
||||
|
||||
|
||||
<!-- Desktop Action Buttons (Visible by default, hidden on mobile via CSS 'desktop-nav') -->
|
||||
<!-- ปุ่มปฏิบัติการสำหรับเดสก์ท็อป (แสดงผลเป็นค่าเริ่มต้น, ซ่อนบนมือถือผ่าน CSS 'desktop-nav') -->
|
||||
<div class="flex desktop-nav items-center gap-4">
|
||||
<template v-if="!isAuthenticated">
|
||||
<!-- Login Button -->
|
||||
<!-- ปุ่มเข้าสู่ระบบ (Login Button) -->
|
||||
<NuxtLink
|
||||
to="/auth/login"
|
||||
class="px-5 py-4 rounded-full text-slate-700 font-semibold text-sm transition-all hover:-translate-y-0.5"
|
||||
|
|
@ -101,7 +100,7 @@ onUnmounted(() => {
|
|||
{{ $t('auth.login') }}
|
||||
</NuxtLink>
|
||||
|
||||
<!-- Register Button -->
|
||||
<!-- ปุ่มสมัครสมาชิก (Register Button) -->
|
||||
<NuxtLink
|
||||
to="/auth/register"
|
||||
class="px-5 py-4 rounded-full bg-blue-600 text-white font-semibold text-sm hover:shadow-blue-600/40 hover:-translate-y-0.5 transition-all"
|
||||
|
|
@ -120,7 +119,7 @@ onUnmounted(() => {
|
|||
</template>
|
||||
</div>
|
||||
|
||||
<!-- Mobile Menu Button (Visible on Mobile) -->
|
||||
<!-- ปุ่มเปิดเมนูบนมือถือ (แสดงผลเฉพาะบน Mobile) -->
|
||||
<button
|
||||
class="md:hidden mobile-toggle ml-auto relative z-[120] w-10 h-10 flex items-center justify-center rounded-full transition-colors"
|
||||
:class="[isScrolled ? 'text-white hover:bg-white/10' : 'text-slate-900 hover:bg-slate-100', mobileMenuOpen ? 'text-slate-900 z-[120]' : '']"
|
||||
|
|
@ -132,7 +131,7 @@ onUnmounted(() => {
|
|||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Mobile Navigation Drawer (Teleported to body to avoid z-index/clipping issues with Header) -->
|
||||
<!-- ลิ้นชักเมนูด้านข้างสำหรับมือถือ (Mobile Navigation Drawer - แยกส่วนไปยัง body เพื่อไม่ให้มีปัญหา z-index หรือถูกบัง) -->
|
||||
<Teleport to="body">
|
||||
<div v-if="mobileMenuOpen">
|
||||
<div
|
||||
|
|
@ -146,7 +145,7 @@ onUnmounted(() => {
|
|||
:class="[mobileMenuOpen ? 'translate-x-0' : 'translate-x-full']"
|
||||
>
|
||||
<div class="p-6 pt-8 flex flex-col gap-6 h-full overflow-y-auto relative">
|
||||
<!-- Close Button -->
|
||||
<!-- ปุ่มปิดเมนู (Close Button) -->
|
||||
<button
|
||||
class="absolute top-6 right-6 w-8 h-8 flex items-center justify-center rounded-full bg-slate-100 text-slate-500 hover:bg-slate-200 transition-colors"
|
||||
@click="mobileMenuOpen = false"
|
||||
|
|
@ -154,7 +153,7 @@ onUnmounted(() => {
|
|||
<q-icon name="close" size="20px" />
|
||||
</button>
|
||||
|
||||
<!-- Mobile Links -->
|
||||
<!-- ลิงก์สำหรับมือถือ (Mobile Links) -->
|
||||
<nav class="flex flex-col gap-2 mt-8">
|
||||
<NuxtLink
|
||||
to="/"
|
||||
|
|
@ -210,14 +209,14 @@ onUnmounted(() => {
|
|||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Glassmorphism Effect for Scrolled Header */
|
||||
/* เอฟเฟกต์ Glassmorphism สำหรับ Header ตอนเลื่อนเมาส์ลง */
|
||||
.glass-nav {
|
||||
background: rgba(15, 23, 42, 0.95); /* Darker background for legibility */
|
||||
background: rgba(15, 23, 42, 0.95); /* พื้นหลังเข้มขึ้นเพื่อให้อ่านตัวหนังสือชัดเจน */
|
||||
backdrop-filter: blur(16px);
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
/* Premium Primary Button Styling */
|
||||
/* สไตล์ปุ่มหลัก (Primary Button) แบบพรีเมียม */
|
||||
.btn-primary-premium {
|
||||
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
|
||||
color: white;
|
||||
|
|
@ -236,7 +235,7 @@ onUnmounted(() => {
|
|||
box-shadow: 0 8px 20px -4px rgba(37, 99, 235, 0.5);
|
||||
}
|
||||
|
||||
/* Secondary Premium Button Styling */
|
||||
/* สไตล์ปุ่มดรอง (Secondary Button) แบบพรีเมียม */
|
||||
.btn-secondary-premium {
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 0.75rem;
|
||||
|
|
@ -260,11 +259,11 @@ onUnmounted(() => {
|
|||
}
|
||||
|
||||
/*
|
||||
Force Visibility Logic to bypass potential Tailwind Build issues
|
||||
Ensures Desktop and Mobile parts are strictly separated
|
||||
โลจิกบังคับการแสดงผล เพื่อแก้ปัญหาการคอมไฟล์ของ Tailwind
|
||||
ยืนยันว่าส่วน Desktop และ Mobile เลย์เอาต์แยกจากกันอย่างชัดเจน
|
||||
*/
|
||||
.desktop-nav {
|
||||
display: flex; /* Default to visible */
|
||||
display: flex; /* แสดงผลเป็นค่าเริ่มต้น */
|
||||
}
|
||||
|
||||
@media (max-width: 767.98px) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ const handleNavigate = (path: string) => {
|
|||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Optional shadow for better separation */
|
||||
/* เงาด้านบนแบบบางๆ เพื่อแบ่งส่วนล่างให้ชัดเจนขึ้น (Optional shadow for better separation) */
|
||||
.shadow-up-1 {
|
||||
box-shadow: 0 -1px 3px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file PasswordChangeForm.vue
|
||||
* @description From for changing user password
|
||||
* @description ฟอร์มสำหรับเปลี่ยนรหัสผ่านของผู้ใช้ (From for changing user password)
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
|
|
@ -130,7 +130,12 @@ const showConfirmPassword = ref(false);
|
|||
|
||||
<style scoped>
|
||||
.card-premium {
|
||||
@apply bg-white dark:bg-[#1e293b] border-slate-200 dark:border-white/5;
|
||||
background-color: white;
|
||||
border-color: #e2e8f0;
|
||||
}
|
||||
:global(.dark) .card-premium {
|
||||
background-color: #1e293b;
|
||||
border-color: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 1.5rem;
|
||||
border-width: 1px;
|
||||
box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file ProfileEditForm.vue
|
||||
* @description From for editing user personal information
|
||||
* @description ฟอร์มสำหรับแก้ไขข้อมูลส่วนตัวของผู้ใช้ (Form for editing user personal information)
|
||||
*/
|
||||
|
||||
const props = defineProps<{
|
||||
|
|
@ -93,14 +93,14 @@ const onPhoneKeydown = (e: KeyboardEvent) => {
|
|||
<div class="absolute inset-0 bg-black/40 rounded-2xl flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<q-icon name="camera_alt" class="text-white text-xl" />
|
||||
</div>
|
||||
<!-- Hidden Input -->
|
||||
<!-- ช่องเลือกไฟล์ที่ถูกซ่อนไว้ (Hidden Input) -->
|
||||
<input ref="fileInput" type="file" class="hidden" accept="image/*" @change="handleFileUpload" >
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="font-bold text-slate-900 dark:text-white mb-1">{{ $t('profile.yourAvatar') }}</div>
|
||||
|
||||
<!-- Buttons Row -->
|
||||
<!-- แถวปุ่มกด (Buttons Row) -->
|
||||
<div class="flex items-center gap-3">
|
||||
<template v-if="modelValue.photoURL">
|
||||
<q-btn
|
||||
|
|
@ -124,7 +124,7 @@ const onPhoneKeydown = (e: KeyboardEvent) => {
|
|||
</template>
|
||||
</div>
|
||||
|
||||
<!-- Add Limit Text -->
|
||||
<!-- ข้อความจำกัดขนาดไฟล์ (Add Limit Text) -->
|
||||
<div class="mt-1 text-xs text-slate-500 dark:text-slate-400">
|
||||
{{ $t('profile.uploadLimit') }}
|
||||
</div>
|
||||
|
|
@ -248,7 +248,12 @@ const onPhoneKeydown = (e: KeyboardEvent) => {
|
|||
|
||||
<style scoped>
|
||||
.card-premium {
|
||||
@apply bg-white dark:bg-[#1e293b] border-slate-200 dark:border-white/5;
|
||||
background-color: white;
|
||||
border-color: #e2e8f0;
|
||||
}
|
||||
:global(.dark) .card-premium {
|
||||
background-color: #1e293b;
|
||||
border-color: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 1.5rem;
|
||||
border-width: 1px;
|
||||
box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file UserAvatar.vue
|
||||
* @description คอมโพเนนต์แสดงรูปโปรไฟล์ผู้ใช้ หากไม่มีรูปจะแสดงตัวอักษรย่อของชื่อ
|
||||
*/
|
||||
const props = defineProps<{
|
||||
size?: number | string
|
||||
photoURL?: string
|
||||
|
|
@ -19,7 +23,7 @@ const avatarSize = computed(() => {
|
|||
const initials = computed(() => {
|
||||
const getFirstChar = (name?: string) => {
|
||||
if (!name) return ''
|
||||
// For Thai names, if the first char is a leading vowel (เ แ โ ใ ไ), skip it to get the consonant
|
||||
// สำหรับชื่อภาษาไทย ถ้าตัวอักษรแรกเป็นสระนำหน้า (เ แ โ ใ ไ) ให้ข้ามไปเอาพยัญชนะ
|
||||
const leadingVowels = ['เ', 'แ', 'โ', 'ใ', 'ไ']
|
||||
if (leadingVowels.includes(name.charAt(0)) && name.length > 1) {
|
||||
return name.charAt(1)
|
||||
|
|
@ -36,7 +40,7 @@ const handleImageError = () => {
|
|||
imageError.value = true
|
||||
}
|
||||
|
||||
// Watch for photoURL changes to reset error state
|
||||
// รีเซ็ตสถานะข้อผิดพลาดเมื่อรูปโปรไฟล์เปลี่ยน (Watch for photoURL changes to reset error state)
|
||||
watch(() => props.photoURL, () => {
|
||||
imageError.value = false
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file UserMenu.vue
|
||||
* @description User profile dropdown menu component using Quasar.
|
||||
* @description คอมโพเนนต์เมนู Dropdown ของโปรไฟล์ผู้ใช้ ใช้ Quasar
|
||||
*/
|
||||
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
|
|
@ -12,7 +12,7 @@ const { currentUser, logout } = useAuth()
|
|||
const { t } = useI18n()
|
||||
const $q = useQuasar()
|
||||
|
||||
// Use centralized theme management
|
||||
// จัดการการเปลี่ยนธีมแบบรวมศูนย์ (Use centralized theme management)
|
||||
const { isDark, set } = useThemeMode()
|
||||
|
||||
const isHydrated = ref(false)
|
||||
|
|
@ -21,7 +21,7 @@ onMounted(() => {
|
|||
isHydrated.value = true
|
||||
})
|
||||
|
||||
// User Initials
|
||||
// ตัวอักษรย่อของผู้ใช้ (User Initials)
|
||||
const userInitials = computed(() => {
|
||||
if (!currentUser.value) return ''
|
||||
const f = currentUser.value.firstName?.charAt(0).toUpperCase() || 'U'
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export const useAuth = () => {
|
|||
// ฟังก์ชันเข้าสู่ระบบ (Login)
|
||||
const login = async (credentials: { email: string; password: string }) => {
|
||||
try {
|
||||
// API returns { code: 200, message: "...", data: { token, user, ... } }
|
||||
// API returns { code: 200, message: "...", data: { token, refreshToken } }
|
||||
const response = await $fetch<any>(`${API_BASE_URL}/auth/login`, {
|
||||
method: 'POST',
|
||||
body: credentials
|
||||
|
|
@ -49,16 +49,35 @@ export const useAuth = () => {
|
|||
if (response && response.data) {
|
||||
const data = response.data
|
||||
|
||||
// Validation: Ensure user and role exist, then check for Role 'STUDENT'
|
||||
if (!data.user || !data.user.role || data.user.role.code !== 'STUDENT') {
|
||||
return { success: false, error: 'Email ไม่ถูกต้อง' }
|
||||
}
|
||||
|
||||
// บันทึก Token ก่อน เพื่อใช้เรียก /user/me
|
||||
token.value = data.token
|
||||
refreshToken.value = data.refreshToken // บันทึก Refresh Token
|
||||
|
||||
// API ส่งข้อมูล profile มาใน user object
|
||||
user.value = data.user
|
||||
refreshToken.value = data.refreshToken
|
||||
|
||||
// ดึงข้อมูลผู้ใช้จาก /user/me (เพราะ API login ไม่ส่ง user กลับมาแล้ว)
|
||||
try {
|
||||
const userData = await $fetch<any>(`${API_BASE_URL}/user/me`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${data.token}`
|
||||
}
|
||||
})
|
||||
|
||||
// Validation: ตรวจสอบ Role ต้องเป็น STUDENT เท่านั้น
|
||||
if (!userData || !userData.role || userData.role.code !== 'STUDENT') {
|
||||
// ถ้า Role ไม่ใช่ STUDENT ให้ล้าง Token ออก
|
||||
token.value = null
|
||||
refreshToken.value = null
|
||||
return { success: false, error: 'Email ไม่ถูกต้อง' }
|
||||
}
|
||||
|
||||
// เก็บข้อมูล User ลง Cookie
|
||||
user.value = userData
|
||||
} catch (profileErr) {
|
||||
// ดึงข้อมูลผู้ใช้ไม่สำเร็จ ให้ล้าง Token ออก
|
||||
console.error('Failed to fetch user profile after login:', profileErr)
|
||||
token.value = null
|
||||
refreshToken.value = null
|
||||
return { success: false, error: 'ไม่สามารถดึงข้อมูลผู้ใช้ได้' }
|
||||
}
|
||||
|
||||
return { success: true }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
// Interface สำหรับข้อมูลหมวดหมู่ (Category)
|
||||
/**
|
||||
* @interface Category
|
||||
* @description โครงสร้างข้อมูลหมวดหมู่ (Category)
|
||||
*/
|
||||
export interface Category {
|
||||
id: number
|
||||
name: {
|
||||
name: { // ชื่อหมวดหมู่รองรับ 2 ภาษา
|
||||
th: string
|
||||
en: string
|
||||
[key: string]: string
|
||||
}
|
||||
slug: string
|
||||
description: {
|
||||
slug: string // Slug สำหรับใช้งานบน URL
|
||||
description: { // รายละเอียดหมวดหมู่
|
||||
th: string
|
||||
en: string
|
||||
[key: string]: string
|
||||
}
|
||||
icon: string
|
||||
icon: string // ไอคอนของหมวดหมู่อ้างอิงจาก Material Icons
|
||||
sort_order: number
|
||||
is_active: boolean
|
||||
created_at: string
|
||||
|
|
@ -20,7 +23,7 @@ export interface Category {
|
|||
}
|
||||
|
||||
export interface CategoryData {
|
||||
total: number
|
||||
total: number // จำนวนหมวดหมู่ทั้งหมด
|
||||
categories: Category[]
|
||||
}
|
||||
|
||||
|
|
@ -30,18 +33,24 @@ interface CategoryResponse {
|
|||
data: CategoryData
|
||||
}
|
||||
|
||||
// Composable สำหรับจัดการข้อมูลหมวดหมู่
|
||||
/**
|
||||
* @composable useCategory
|
||||
* @description จัดการข้อมูลหมวดหมู่ (Categories) การดึงข้อมูล และการจัดการ Cache (เก็บข้อมูลจำลองชั่วคราว)
|
||||
*/
|
||||
export const useCategory = () => {
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBase as string
|
||||
const { token } = useAuth()
|
||||
|
||||
// ใช้ useState เพื่อเก็บ Cached Data ระดับ Global (แชร์กันทุก Component)
|
||||
// เก็บ Cache การดึงข้อมูลหมวดหมู่ในระดับ Global (ใช้ข้าม Component ได้โดยไม่ต้องโหลดใหม่)
|
||||
const categoriesState = useState<Category[]>('categories_cache', () => [])
|
||||
const isLoaded = useState<boolean>('categories_loaded', () => false)
|
||||
|
||||
// ฟังก์ชันดึงข้อมูลหมวดหมู่ทั้งหมด
|
||||
// Endpoint: GET /categories
|
||||
/**
|
||||
* @function fetchCategories
|
||||
* @description ดึงรายการหมวดหมู่ทั้งหมดจาก API (GET /categories)
|
||||
* หากมีแคชอยู่แล้วจะดึงจาก State ทันที แต่อาจบังคับให้โหลดใหม่ (forceRefresh) ได้
|
||||
*/
|
||||
const fetchCategories = async (forceRefresh = false) => {
|
||||
// ถ้ามีข้อมูลอยู่แล้วและไม่สั่งบังคับโหลดใหม่ ให้ใช้ข้อมูลเดิมทันที
|
||||
if (isLoaded.value && !forceRefresh && categoriesState.value.length > 0) {
|
||||
|
|
@ -62,7 +71,7 @@ export const useCategory = () => {
|
|||
|
||||
const categories = response.data?.categories || []
|
||||
|
||||
// เก็บข้อมูลลง State
|
||||
// บันทึกรายการหมวดหมู่ลง State Cache
|
||||
categoriesState.value = categories
|
||||
isLoaded.value = true
|
||||
|
||||
|
|
@ -74,9 +83,9 @@ export const useCategory = () => {
|
|||
} catch (err: any) {
|
||||
console.error('Fetch categories failed:', err)
|
||||
|
||||
// Retry logic for 429 Too Many Requests
|
||||
// กรณีเกิด Error 429 ระบบจะทำการหน่วงเวลา (1.5 วิ) และลองโหลดข้อมูลใหม่อีก 1 ครั้ง (Retry)
|
||||
if (err.statusCode === 429 || err.status === 429) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1500)); // Wait 1.5s
|
||||
await new Promise(resolve => setTimeout(resolve, 1500)); // หน่วงเวลา 1.5 วินาที
|
||||
try {
|
||||
const retryRes = await $fetch<CategoryResponse>(`${API_BASE_URL}/categories`, {
|
||||
method: 'GET',
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
/**
|
||||
* @interface ValidationRule
|
||||
* @description กฎการตรวจสอบความถูกต้องของฟิลด์ (เช่น บังคับกรอก, เช็คความยาว, ตรวจอีเมล)
|
||||
*/
|
||||
export interface ValidationRule {
|
||||
required?: boolean
|
||||
minLength?: number
|
||||
|
|
@ -8,10 +12,18 @@ export interface ValidationRule {
|
|||
custom?: (value: string) => string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface FieldErrors
|
||||
* @description รูปแบบการเก็บข้อผิดพลาด (Key ของฟิลด์ คู่กับข้อความแจ้งเตือน)
|
||||
*/
|
||||
export interface FieldErrors {
|
||||
[key: string]: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @composable useFormValidation
|
||||
* @description ใช้สำหรับตรวจสอบความถูกต้อง (Validate) ของข้อมูลในแบบฟอร์ม
|
||||
*/
|
||||
export function useFormValidation() {
|
||||
const errors = ref<FieldErrors>({})
|
||||
|
||||
|
|
@ -52,6 +64,7 @@ export function useFormValidation() {
|
|||
return null
|
||||
}
|
||||
|
||||
// ฟังก์ชันหลักที่เอาแบบฟอร์ม (formData) มาตรวจกับเช็คลิสต์ทั้งหมด (validationRules)
|
||||
const validate = (
|
||||
formData: Record<string, string>,
|
||||
validationRules: Record<string, { rules: ValidationRule; label: string; messages?: Record<string, string> }>
|
||||
|
|
@ -67,14 +80,18 @@ export function useFormValidation() {
|
|||
}
|
||||
}
|
||||
|
||||
// บันทึกข้อผิดพลาดที่พบทั้งหมดลงใน State
|
||||
errors.value = newErrors
|
||||
// คืนค่าบอกว่า "ฟอร์มนี้ผ่านทั้งหมดไหม" (true คือผ่านหมด)
|
||||
return isValid
|
||||
}
|
||||
|
||||
// ฟังก์ชันลบข้อผิดพลาดทิ้งทั้งหมด (สำหรับตอนเริ่มกรอกใหม่)
|
||||
const clearErrors = () => {
|
||||
errors.value = {}
|
||||
}
|
||||
|
||||
// ฟังก์ชันลบข้อผิดพลาดเฉพาะฟิลด์ที่กำหนด
|
||||
const clearFieldError = (field: string) => {
|
||||
if (errors.value[field]) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
|
|
|
|||
|
|
@ -1,22 +1,27 @@
|
|||
/**
|
||||
* @composable useMediaPrefs
|
||||
* @description จัดการตั้งค่าระดับเสียงและสถานะปิดเสียง (Mute) ของวิดีโอ/สื่อ
|
||||
* โดยจะเก็บค่าแยกตามบัญชีผู้ใช้งาน และสั่งประยุกต์ใช้กับ <video> ให้อัตโนมัติ
|
||||
*/
|
||||
export const useMediaPrefs = () => {
|
||||
// 1. Global State
|
||||
// ใช้ useState เพื่อแชร์ค่าเดียวกันทั่วทั้ง App (เช่น เปลี่ยนหน้าแล้วเสียงยังเท่าเดิม)
|
||||
// 1. สถานะส่วนกลาง (Global State)
|
||||
// ใช้ useState เพื่อแชร์ค่าเดียวกันทั่วหน้าเว็บ (เช่น เปลี่ยนหน้าแล้วระดับเสียงยังคงที่)
|
||||
const volume = useState<number>('media_prefs_volume', () => 1)
|
||||
const muted = useState<boolean>('media_prefs_muted', () => false)
|
||||
|
||||
const { user } = useAuth()
|
||||
|
||||
// 2. Storage Key Helper (User Specific)
|
||||
// 2. ฟังก์ชันช่วยสร้าง Key สำหรับ Storage (เก็บแยกตาม User)
|
||||
const getStorageKey = () => {
|
||||
const userId = user.value?.id || 'guest'
|
||||
return `media:prefs:v1:${userId}`
|
||||
}
|
||||
|
||||
// 3. Save Logic (Throttled)
|
||||
// 3. ระบบบันทึกการตั้งค่าลงเบราว์เซอร์ (Throttled เพื่อไม่ให้บันทึกถี่เกินไป)
|
||||
let saveTimeout: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
const save = () => {
|
||||
if (import.meta.server) return
|
||||
if (import.meta.server) return // เลี่ยงไม่ได้ต้องทำงานบนฝั่ง Client เท่านั้น
|
||||
|
||||
if (saveTimeout) clearTimeout(saveTimeout)
|
||||
saveTimeout = setTimeout(() => {
|
||||
|
|
@ -29,12 +34,12 @@ export const useMediaPrefs = () => {
|
|||
}
|
||||
localStorage.setItem(key, JSON.stringify(data))
|
||||
} catch (e) {
|
||||
console.error('Failed to save media prefs', e)
|
||||
console.error('ไม่สามารถบันทึกการตั้งค่าสื่อได้', e)
|
||||
}
|
||||
}, 500) // Throttle 500ms
|
||||
}, 500) // หน่วงเวลา 500ms
|
||||
}
|
||||
|
||||
// 4. Load Logic
|
||||
// 4. ระบบโหลดการตั้งค่าเก่าขึ้นมา (Load Logic)
|
||||
const load = () => {
|
||||
if (import.meta.server) return
|
||||
|
||||
|
|
@ -51,20 +56,20 @@ export const useMediaPrefs = () => {
|
|||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load media prefs', e)
|
||||
console.error('ไม่สามารถโหลดการตั้งค่าสื่อได้', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Setters (With Logic)
|
||||
// 5. ฟังก์ชันสำหรับอัปเดตและสั่งบันทึกการตั้งค่า (Setters)
|
||||
const setVolume = (val: number) => {
|
||||
const clamped = Math.max(0, Math.min(1, val))
|
||||
volume.value = clamped
|
||||
|
||||
// Auto unmute if volume increased from 0
|
||||
// ยกเลิกปิดเสียงอัตโนมัติ ถ้าระดับเสียงเพิ่มขึ้นจาก 0
|
||||
if (clamped > 0 && muted.value) {
|
||||
muted.value = false
|
||||
}
|
||||
// Auto mute if volume set to 0
|
||||
// ปิดเสียงอัตโนมัติ ถ้าระดับเสียงกลายเป็น 0
|
||||
if (clamped === 0 && !muted.value) {
|
||||
muted.value = true
|
||||
}
|
||||
|
|
@ -75,7 +80,7 @@ export const useMediaPrefs = () => {
|
|||
const setMuted = (val: boolean) => {
|
||||
muted.value = val
|
||||
|
||||
// Logic: Unmuting should restore volume if it was 0
|
||||
// หากผู้ใช้กดยกเลิกการปิดเสียงขณะที่ระดับเสียงเคยเป็น 0 ควรตั้งค่าเริ่มต้นให้เป็น 1
|
||||
if (!val && volume.value === 0) {
|
||||
volume.value = 1
|
||||
}
|
||||
|
|
@ -83,15 +88,15 @@ export const useMediaPrefs = () => {
|
|||
save()
|
||||
}
|
||||
|
||||
// 6. Apply & Bind to Element (The Magic)
|
||||
// 6. ฟังก์ชันจับคู่ใช้กับการเล่นสื่อ (ตย. <video ref="videoEl"> -> applyTo(videoEl.value))
|
||||
const applyTo = (el: HTMLMediaElement | null | undefined) => {
|
||||
if (!el) return () => {}
|
||||
|
||||
// Initial Apply
|
||||
// ใส่ค่าตั้งต้นให้กับออบเจ็กต์สื่อ
|
||||
el.volume = volume.value
|
||||
el.muted = muted.value
|
||||
|
||||
// A. Watch State -> Update Element
|
||||
// A. สังเกตการเปลี่ยนแปลงจาก State -> เพื่อส่งไปอัปเดต Element สื่อ
|
||||
const stopVolWatch = watch(volume, (v) => {
|
||||
if (Math.abs(el.volume - v) > 0.01) el.volume = v
|
||||
})
|
||||
|
|
@ -99,9 +104,9 @@ export const useMediaPrefs = () => {
|
|||
if (el.muted !== m) el.muted = m
|
||||
})
|
||||
|
||||
// B. Listen Element -> Update State (e.g. Native Controls)
|
||||
// B. สังเกตการเปลี่ยนแปลงจาก Element (เช่น ผู้ใช้กดปุ่มเร่งเสียงในวิดีโอตรงๆ) -> เพื่อเอาค่ามาอัปเดต State
|
||||
const onVolumeChange = () => {
|
||||
// Update state only if diff allows (prevent loop)
|
||||
// อัปเดตเฉพาะเมื่อมีความแตกต่างเพื่อหลีกเลี่ยง Loop อนันต์
|
||||
if (Math.abs(el.volume - volume.value) > 0.01) {
|
||||
volume.value = el.volume
|
||||
save()
|
||||
|
|
@ -113,7 +118,7 @@ export const useMediaPrefs = () => {
|
|||
}
|
||||
el.addEventListener('volumechange', onVolumeChange)
|
||||
|
||||
// Cleanup function
|
||||
// ฟังก์ชันล้างค่าเพื่อเลิกติดตาม (Cleanup แบบส่งกลับ (Return))
|
||||
return () => {
|
||||
stopVolWatch()
|
||||
stopMutedWatch()
|
||||
|
|
@ -121,11 +126,11 @@ export const useMediaPrefs = () => {
|
|||
}
|
||||
}
|
||||
|
||||
// 7. Lifecycle & Sync
|
||||
// 7. จังหวะวงจรชีวิตตอนโหลดเสร็จและระบบ Sync
|
||||
if (import.meta.client) {
|
||||
onMounted(() => {
|
||||
load()
|
||||
// Cross-tab sync
|
||||
// ระบบ Sync กับแท็บหรือหน้าต่างเดียวกันหากถูกเปิดไว้
|
||||
window.addEventListener('storage', (e) => {
|
||||
if (e.key === getStorageKey()) {
|
||||
load()
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
/**
|
||||
* @file useNavItems.ts
|
||||
* @description Single Source of Truth for navigation items used across the app (Sidebar, Mobile Nav, User Menu).
|
||||
* @description ศูนย์รวมจัดการเมนูนำทาง (Navigation Items) เพื่อให้ใช้ข้อมูลชุดเดียวกันทั้งเว็บ
|
||||
* (เช่น เมนูด้านข้าง, เมนูบนมือถือ, และเมนูโปรไฟล์ผู้ใช้)
|
||||
*/
|
||||
|
||||
export interface NavItem {
|
||||
to: string
|
||||
labelKey: string
|
||||
icon: string
|
||||
showOn: ('sidebar' | 'mobile' | 'userMenu')[]
|
||||
roles?: string[]
|
||||
to: string // ลิงก์ปลายทาง
|
||||
labelKey: string // คีย์ภาษาสำหรับ i18n
|
||||
icon: string // ไอคอนจาก Material Icons
|
||||
showOn: ('sidebar' | 'mobile' | 'userMenu')[] // กำหนดให้โชว์ที่ส่วนไหนบ้าง
|
||||
roles?: string[] // กำหนดสิทธิ์ผู้ใช้ที่จะเห็น (ถ้ามี)
|
||||
}
|
||||
|
||||
export const useNavItems = () => {
|
||||
// เมนูทั้งหมดในระบบ กำหนดไว้ที่เดียว
|
||||
const allNavItems: NavItem[] = [
|
||||
{
|
||||
to: '/dashboard',
|
||||
|
|
@ -63,6 +65,7 @@ export const useNavItems = () => {
|
|||
}
|
||||
]
|
||||
|
||||
// คัดกรองเมนูที่จะเอาไปแสดงแต่ละตำแหน่ง
|
||||
const sidebarItems = computed(() => allNavItems.filter(item => item.showOn.includes('sidebar')))
|
||||
const mobileItems = computed(() => allNavItems.filter(item => item.showOn.includes('mobile')))
|
||||
const userMenuItems = computed(() => allNavItems.filter(item => item.showOn.includes('userMenu')))
|
||||
|
|
|
|||
|
|
@ -19,95 +19,107 @@ export interface AnswerState {
|
|||
|
||||
/**
|
||||
* @composable useQuizRunner
|
||||
* @description Manages the state and logic for running a quiz activity.
|
||||
* @description จัดการ State (สถานะ) และ Logic สำหรับการทำแบบทดสอบ (Quiz)
|
||||
* ครอบคลุมการแสดงคำถาม, บันทึกคำตอบ, และตรวจสอบการข้ามคำถาม
|
||||
*/
|
||||
export const useQuizRunner = () => {
|
||||
// State
|
||||
const questions = useState<QuizQuestion[]>('quiz-questions', () => []);
|
||||
const answers = useState<Record<number, AnswerState>>('quiz-answers', () => ({}));
|
||||
const currentQuestionIndex = useState<number>('quiz-current-index', () => 0);
|
||||
const loading = useState<boolean>('quiz-loading', () => false);
|
||||
const lastError = useState<string | null>('quiz-error', () => null);
|
||||
// ================= State (สถานะเก็บค่าต่างๆ ของข้อสอบ) =================
|
||||
const questions = useState<QuizQuestion[]>('quiz-questions', () => []); // เก็บรายการคำถามทั้งหมด
|
||||
const answers = useState<Record<number, AnswerState>>('quiz-answers', () => ({})); // เก็บคำตอบที่ผู้ใช้ตอบ แยกตาม ID คำถาม
|
||||
const currentQuestionIndex = useState<number>('quiz-current-index', () => 0); // ลำดับคำถามที่กำลังทำอยู่ปัจจุบัน (เริ่มที่ 0)
|
||||
const loading = useState<boolean>('quiz-loading', () => false); // สถานะตอนกำลังกดเซฟหรือโหลดข้อมูล
|
||||
const lastError = useState<string | null>('quiz-error', () => null); // เก็บข้อความแจ้งเตือนข้อผิดพลาดล่าสุด
|
||||
|
||||
// Getters
|
||||
const currentQuestion = computed(() => questions.value[currentQuestionIndex.value]);
|
||||
// ================= Getters (ดึงค่าที่ถูกประมวลผลแล้ว) =================
|
||||
const currentQuestion = computed(() => questions.value[currentQuestionIndex.value]); // ดึงคำถามข้อปัจจุบัน
|
||||
|
||||
const currentAnswer = computed(() => {
|
||||
const currentAnswer = computed(() => { // ดึงคำตอบในข้อปัจจุบัน
|
||||
if (!currentQuestion.value) return null;
|
||||
return answers.value[currentQuestion.value.id];
|
||||
});
|
||||
|
||||
const totalQuestions = computed(() => questions.value.length);
|
||||
const isLastQuestion = computed(() => currentQuestionIndex.value === questions.value.length - 1);
|
||||
const isFirstQuestion = computed(() => currentQuestionIndex.value === 0);
|
||||
const totalQuestions = computed(() => questions.value.length); // จำนวนคำถามทั้งหมดในแบบทดสอบ
|
||||
const isLastQuestion = computed(() => currentQuestionIndex.value === questions.value.length - 1); // เช็คว่าใช่คำถามข้อสุดท้ายหรือไม่
|
||||
const isFirstQuestion = computed(() => currentQuestionIndex.value === 0); // เช็คว่าใช่คำถามข้อแรกหรือไม่
|
||||
|
||||
// Actions
|
||||
// ================= Actions (ฟังก์ชันหลักสำหรับการทำงาน) =================
|
||||
|
||||
// ฟังก์ชันเริ่มต้นสร้าง/โหลดข้อสอบ (กำหนดโครงสร้างพื้นฐาน)
|
||||
function initQuiz(quizData: any) {
|
||||
if (!quizData || !quizData.questions) return;
|
||||
|
||||
questions.value = quizData.questions;
|
||||
currentQuestionIndex.value = 0;
|
||||
currentQuestionIndex.value = 0; // รีเซ็ตไปที่ข้อ 1 ใหม่
|
||||
answers.value = {};
|
||||
lastError.value = null;
|
||||
|
||||
// เตรียมโครงสร้างคำตอบรองรับทุกข้อ
|
||||
questions.value.forEach(q => {
|
||||
answers.value[q.id] = {
|
||||
questionId: q.id,
|
||||
value: null,
|
||||
is_saved: false,
|
||||
status: 'not_started',
|
||||
touched: false,
|
||||
is_saved: false, // บันทึกและส่ง API เรียบร้อยหรือยัง
|
||||
status: 'not_started', // สถานะเริ่มต้นของคำถาม
|
||||
touched: false, // ผู้ใช้เคยเปิดเข้ามาดูข้อนีัหรือยัง
|
||||
};
|
||||
});
|
||||
|
||||
// เริ่มต้นบันทึกเวลา/เข้าสู่ข้อที่ 1 ทันทีเมื่ออธิบายเสร็จ
|
||||
if (questions.value.length > 0) {
|
||||
enterQuestion(questions.value[0].id);
|
||||
}
|
||||
}
|
||||
|
||||
// ฟังก์ชันสลับสถานะเมื่อกดเข้ามาที่คำถามนั้นๆ
|
||||
function enterQuestion(qId: number) {
|
||||
const ans = answers.value[qId];
|
||||
if (ans) {
|
||||
ans.touched = true;
|
||||
if (ans.status === 'not_started' || ans.status === 'skipped') {
|
||||
ans.status = 'in_progress';
|
||||
ans.status = 'in_progress'; // เปลี่ยนสถานะเป็น 'กำลังทำ'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ตรวจสอบเงื่อนไขว่าผู้ใช้สามารถออกจากคำถามปัจจุบันไปยังข้ออื่นได้หรือไม่
|
||||
function canLeaveCurrent(): { allowed: boolean; reason?: string } {
|
||||
if (!currentQuestion.value) return { allowed: true };
|
||||
const q = currentQuestion.value;
|
||||
const a = answers.value[q.id];
|
||||
|
||||
// สามารถออกได้ถ้าคำถามทำถูกหรือโจทย์อนุญาตให้ข้ามได้
|
||||
if (a.status === 'completed' || a.is_saved) return { allowed: true };
|
||||
if (q.is_skippable) return { allowed: true };
|
||||
|
||||
// บังคับให้ตอบถ้าไม่ได้อนุญาตให้ข้าม และไม่ได้ตอบ
|
||||
if (!a.is_saved && a.value === null) {
|
||||
return { allowed: false, reason: 'This question is required.' };
|
||||
return { allowed: false, reason: 'ต้องการคำตอบสำหรับข้อบังคับนี้' };
|
||||
}
|
||||
|
||||
return { allowed: true };
|
||||
}
|
||||
|
||||
// ฟังก์ชันอัปเดตค่าตัวเลือกที่ผู้ใช้กดเลือกในข้อปัจจุบัน
|
||||
function updateAnswer(val: any) {
|
||||
if (!currentQuestion.value) return;
|
||||
const qId = currentQuestion.value.id;
|
||||
answers.value[qId].value = val;
|
||||
|
||||
// หากมีแก้ไขคำตอบหลังจากกดเซฟไปแล้ว ให้เปลี่ยนสถานะให้ระบบรู้ว่าต้องเซฟใหม่
|
||||
if (answers.value[qId].is_saved) {
|
||||
answers.value[qId].is_saved = false;
|
||||
answers.value[qId].status = 'in_progress';
|
||||
answers.value[qId].status = 'in_progress';
|
||||
}
|
||||
}
|
||||
|
||||
// ล็อกและบันทึกข้อสอบเมื่อกดปุ่ม "ตกลง/ส่งคำตอบ" สำหรับข้อนั้นๆ
|
||||
async function saveCurrentAnswer() {
|
||||
if (!currentQuestion.value) return;
|
||||
const qId = currentQuestion.value.id;
|
||||
const ans = answers.value[qId];
|
||||
|
||||
if (ans.value === null) {
|
||||
lastError.value = "Please provide an answer.";
|
||||
lastError.value = "กรุณาเลือกคำตอบอย่างน้อย 1 ตัวเลือก";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -115,30 +127,34 @@ export const useQuizRunner = () => {
|
|||
lastError.value = null;
|
||||
|
||||
try {
|
||||
// หมายเหตุ: การเชื่อมต่อ API หลักต้องทำที่ไฟล์ component, ตัวนี้จัดการแค่เรื่อง State
|
||||
ans.is_saved = true;
|
||||
ans.status = 'completed';
|
||||
ans.status = 'completed'; // มาร์คว่าเป็นข้อที่ทำเสร็จแล้ว
|
||||
ans.last_saved_at = new Date().toISOString();
|
||||
return true;
|
||||
} catch (e) {
|
||||
lastError.value = "Failed to save answer.";
|
||||
lastError.value = "เกิดข้อผิดพลาดในการบันทึกคำตอบ";
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// วินิจฉัยก่อนสั่งผู้ใช้ย้ายไปยังคำถามอื่นหน้าอื่นตามดัชนีระบุ
|
||||
function handleLeaveLogic(targetIndex: number) {
|
||||
if (targetIndex === currentQuestionIndex.value) return;
|
||||
|
||||
// ตรวจสอบขั้นสุดท้าย ป้องกันคนคลิกแอบหนีข้อที่บังคับทำ
|
||||
const check = canLeaveCurrent();
|
||||
if (!check.allowed) {
|
||||
lastError.value = check.reason || "Required question.";
|
||||
lastError.value = check.reason || "จำเป็นต้องตอบข้อนี้ก่อนข้าม";
|
||||
return false;
|
||||
}
|
||||
|
||||
const currQ = currentQuestion.value;
|
||||
if (currQ) {
|
||||
const currAns = answers.value[currQ.id];
|
||||
// หากผู้ใช้ทิ้งขว้างโดยที่ไม่บังคับ ให้ทิ้งสถานะเป็นข้าม ('skipped')
|
||||
if (currAns.status !== 'completed' && !currAns.is_saved) {
|
||||
currAns.status = 'skipped';
|
||||
}
|
||||
|
|
@ -147,6 +163,7 @@ export const useQuizRunner = () => {
|
|||
currentQuestionIndex.value = targetIndex;
|
||||
lastError.value = null;
|
||||
|
||||
// ติดตามสถานะ 'touched' ในข้อใหม่ที่เข้าไปล่าสุด
|
||||
if (questions.value[targetIndex]) {
|
||||
enterQuestion(questions.value[targetIndex].id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,41 @@
|
|||
import { useQuasar } from 'quasar'
|
||||
|
||||
/**
|
||||
* @composable useThemeMode
|
||||
* @description จัดการระบบโหมดสว่าง/มืด (Light/Dark Theme) ของแพลตฟอร์ม
|
||||
* ครอบคลุมการสั่งบันทึกการตั้งค่า, เปลี่ยนคลาส Tailwind และ Sync ซิงก์กับ Quasar UI
|
||||
*/
|
||||
export const useThemeMode = () => {
|
||||
const $q = useQuasar()
|
||||
|
||||
// deterministic on SSR: default = light
|
||||
// สถานะเริ่มต้นของโหมดมืด (สำหรับการทำ SSR ถูกเซ็ตเป็น false (สว่าง) ไว้ก่อน)
|
||||
const isDark = useState<boolean>('theme:isDark', () => false)
|
||||
|
||||
// ฟังก์ชันใช้คลาสกับ Tag <html> เพื่อให้ Tailwind หรือ CSS รันโหมดมืด
|
||||
const applyTheme = (value: boolean) => {
|
||||
if (!process.client) return
|
||||
if (!process.client) return // หากทำงานฝั่งเซิร์ฟเวอร์ จะไม่สั่งให้รัน DOM
|
||||
|
||||
// สลับคลาส 'dark' หรือปิด
|
||||
document.documentElement.classList.toggle('dark', value)
|
||||
|
||||
// สั่งให้ Quasar (UI Framework) ปรับโหมดสีให้ตรงกัน (มืด/สว่าง)
|
||||
$q.dark.set(value)
|
||||
|
||||
// บันทึกการตั้งค่าลงเครื่องระยะยาวเบราว์เซอร์
|
||||
localStorage.setItem('theme', value ? 'dark' : 'light')
|
||||
}
|
||||
|
||||
|
||||
|
||||
// จับตาดูเมื่อตัวแปรเปลี่ยนค่าค่อยทำการเปลี่ยนโหมดบนหน้าจอ
|
||||
watch(isDark, (v) => applyTheme(v))
|
||||
|
||||
// ฟังก์ชันสั่งสลับโหมด ไปมา (Toggle)
|
||||
const toggle = () => {
|
||||
isDark.value = !isDark.value
|
||||
}
|
||||
|
||||
// ฟังก์ชันสำหรับกำหนดตั้งค่าโหมดแบบเจาะจง
|
||||
const set = (v: boolean) => {
|
||||
isDark.value = v
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* @file landing.ts
|
||||
* @description Static data for the landing page.
|
||||
* @description ข้อมูลคงที่ (Static data) แบบจำลองที่เอาไว้แสดงผลบนหน้า Landing page
|
||||
*/
|
||||
|
||||
export const CATEGORY_CARDS = [
|
||||
|
|
|
|||
|
|
@ -117,7 +117,11 @@
|
|||
"foundTotal": "Found Total",
|
||||
"items": "items",
|
||||
"subtitle": "Choose to learn new skills from our curated quality courses",
|
||||
"searchBtn": "Search"
|
||||
"searchBtn": "Search",
|
||||
"allCategory": "All",
|
||||
"byInstructor": "by",
|
||||
"students": "students",
|
||||
"viewDetails": "View Details"
|
||||
},
|
||||
"myCourses": {
|
||||
"title": "My Courses",
|
||||
|
|
|
|||
|
|
@ -117,7 +117,11 @@
|
|||
"foundTotal": "พบทั้งหมด",
|
||||
"items": "รายการ",
|
||||
"subtitle": "เลือกเรียนรู้ทักษะใหม่ๆ จากหลักสูตรคุณภาพที่คัดสรรมาเพื่อคุณ",
|
||||
"searchBtn": "ค้นหา"
|
||||
"searchBtn": "ค้นหา",
|
||||
"allCategory": "ทั้งหมด",
|
||||
"byInstructor": "โดย",
|
||||
"students": "นักเรียน",
|
||||
"viewDetails": "ดูรายละเอียด"
|
||||
},
|
||||
"myCourses": {
|
||||
"title": "คอร์สของฉัน",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ onMounted(() => {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<!-- Auth Shell: Wrapper for authentication pages (Login, Register, etc.) -->
|
||||
<!-- Auth Shell: ครอบคลุมการแสดงผลหน้าสำหรับเข้าสู่ระบบหรือสมัครสมาชิก -->
|
||||
<div class="auth-shell bg-white w-full min-h-screen">
|
||||
<slot />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file dashboard-index.vue
|
||||
* @description Layout for the Dashboard Index page, without the sidebar.
|
||||
* Uses Quasar QLayout for responsive structure.
|
||||
* @description เลย์เอาต์สำหรับหน้าแรกของ Dashboard (ไม่มีแผงเมนูด้านข้างเพื่อเน้นพื้นที่เนื้อหา)
|
||||
* ใช้โครงสร้างจาก Quasar QLayout เพื่อให้รองรับ Responsive
|
||||
*/
|
||||
|
||||
// Initialize global theme management
|
||||
// เปิดใช้คอมโพสซิเบิลจัดการธีมแบบ Global
|
||||
useThemeMode()
|
||||
|
||||
const { currentUser, logout } = useAuth()
|
||||
|
|
@ -18,7 +18,7 @@ const toggleRightDrawer = () => {
|
|||
|
||||
<template>
|
||||
<q-layout view="hHh lpR fFf" class="bg-slate-50 dark:!bg-[#020617] text-slate-900 dark:!text-slate-50">
|
||||
<!-- Header -->
|
||||
<!-- แถบด้านบนของโครงสร้าง (Header) -->
|
||||
<q-header
|
||||
class="bg-white/80 dark:!bg-[#0f172a]/80 backdrop-blur-md text-slate-900 dark:!text-white"
|
||||
>
|
||||
|
|
@ -29,7 +29,7 @@ const toggleRightDrawer = () => {
|
|||
/>
|
||||
</q-header>
|
||||
|
||||
<!-- Master Mobile Drawer (The Everything Hub) -->
|
||||
<!-- แถบลิ้นชักมือถือหลัก (เมนูรวมทุกอย่างเมื่อปัดหน้าจอ/กดไอคอนบนสัดส่วนเล็ก) -->
|
||||
<q-drawer
|
||||
v-model="rightDrawerOpen"
|
||||
side="right"
|
||||
|
|
@ -39,7 +39,7 @@ const toggleRightDrawer = () => {
|
|||
:width="300"
|
||||
>
|
||||
<div class="flex flex-col h-full bg-white dark:bg-[#0f172a]">
|
||||
<!-- 1. Account Section (Premium Look) -->
|
||||
<!-- 1. ส่วนบัญชีผู้ใช้ (Account Section) ดีไซน์พรีเมียม -->
|
||||
<div class="p-6 bg-slate-50/50 dark:bg-slate-800/30 border-b border-slate-100 dark:border-slate-800">
|
||||
<div class="flex items-center justify-between mb-8">
|
||||
<div class="flex items-center gap-3">
|
||||
|
|
@ -62,10 +62,10 @@ const toggleRightDrawer = () => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 2. Integrated Content Hub -->
|
||||
<!-- 2. ศูนย์รวมเมนูและเนื้อหา (Integrated Content Hub) -->
|
||||
<div class="flex-grow overflow-y-auto pt-4">
|
||||
<q-list padding class="text-slate-600 dark:text-slate-300">
|
||||
<!-- Navigation -->
|
||||
<!-- การนำทาง (Navigation) -->
|
||||
<q-item-label header class="text-[11px] font-black tracking-[0.2em] text-slate-400 uppercase px-6 pb-2">เมนูหลัก</q-item-label>
|
||||
|
||||
<q-item to="/dashboard" clickable v-ripple class="px-6 py-4" active-class="bg-blue-50 text-blue-600 dark:bg-blue-900/20 dark:text-blue-400 font-bold" @click="rightDrawerOpen = false">
|
||||
|
|
@ -85,10 +85,10 @@ const toggleRightDrawer = () => {
|
|||
|
||||
<q-separator class="my-4 mx-6 opacity-50" />
|
||||
|
||||
<!-- Tools & Settings -->
|
||||
<!-- เครื่องมือทั่วไปและการตั้งค่าระบบ -->
|
||||
<q-item-label header class="text-[11px] font-black tracking-[0.2em] text-slate-400 uppercase px-6 pb-2">เครื่องมือและการตั้งค่า</q-item-label>
|
||||
|
||||
<!-- Language Selection -->
|
||||
<!-- ปุ่มสลับภาษา -->
|
||||
<q-item class="px-6 py-2">
|
||||
<q-item-section avatar><q-icon name="language" size="22px" /></q-item-section>
|
||||
<q-item-section>
|
||||
|
|
@ -99,7 +99,7 @@ const toggleRightDrawer = () => {
|
|||
</q-item-section>
|
||||
</q-item>
|
||||
|
||||
<!-- Dark Mode Toggle -->
|
||||
<!-- เปิดปิดโหมดมืด (Dark Mode Toggle) -->
|
||||
<q-item class="px-6 py-2">
|
||||
<q-item-section avatar><q-icon :name="isDark ? 'dark_mode' : 'light_mode'" size="22px" /></q-item-section>
|
||||
<q-item-section>
|
||||
|
|
@ -121,7 +121,7 @@ const toggleRightDrawer = () => {
|
|||
</q-list>
|
||||
</div>
|
||||
|
||||
<!-- 3. Bottom Actions -->
|
||||
<!-- 3. ส่วนล่างสุด เช่น ล็อกเอาต์ หรือระบุเวอร์ชันระบบ -->
|
||||
<div class="p-6 mt-auto border-t border-slate-100 dark:border-slate-800">
|
||||
<q-btn
|
||||
unelevated
|
||||
|
|
@ -138,18 +138,16 @@ const toggleRightDrawer = () => {
|
|||
</div>
|
||||
</q-drawer>
|
||||
|
||||
<!-- Sidebar Removed for this layout -->
|
||||
<!-- หมายเหตุ: สำหรับหน้านี้ จะไม่ได้มีการโชว์ Sidebar ที่เป็นลิ้นชักซ้าย -->
|
||||
|
||||
<!-- Main Content -->
|
||||
<!-- พื้นที่แสดงเนื้อหาหลัก -->
|
||||
<q-page-container>
|
||||
<q-page class="relative">
|
||||
<slot />
|
||||
</q-page>
|
||||
</q-page-container>
|
||||
|
||||
<!-- Mobile Bottom Nav - Optional, keeping it consistent with default but maybe not needed if full width?
|
||||
If we remove sidebar, we might still want mobile nav if it's main navigation.
|
||||
Let's keep it for now as it doesn't hurt. -->
|
||||
<!-- เมนูปุ่มกดล่างหน้าจอบนมือถือ (สำหรับช่วยให้เข้าถึงหน้าหลักได้ไวขึ้น) -->
|
||||
<q-footer
|
||||
v-if="$q.screen.lt.md"
|
||||
class="!bg-white dark:!bg-[#1e293b] text-primary"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file default.vue
|
||||
* @description Master layout for the EduLearn platform.
|
||||
* @description เลย์เอาต์หลัก (Master Layout) สำหรับผู้ใช้งานที่เข้าสู่ระบบแล้ว
|
||||
* ประกอบด้วยแถบเมนูด้านบน (Header), แถบเมนูด้านข้าง (Sidebar) และพื้นที่เนื้อหา
|
||||
*/
|
||||
|
||||
useThemeMode()
|
||||
|
|
@ -13,7 +14,7 @@ const toggleLeftDrawer = () => {
|
|||
}
|
||||
|
||||
const route = useRoute()
|
||||
// Show sidebar for these routes
|
||||
// ระบุว่า path ไหนบ้างที่ให้แสดงแถบเมนูด้านข้าง (Sidebar)
|
||||
const isDashboardRoute = computed(() => {
|
||||
const routes = ['/dashboard', '/browse', '/classroom', '/course']
|
||||
return routes.some(r => route.path.startsWith(r))
|
||||
|
|
@ -23,14 +24,14 @@ const isDashboardRoute = computed(() => {
|
|||
<template>
|
||||
<q-layout view="lHh Lpr lFf" class="bg-[#F8FAFC] dark:!bg-[#020617] text-slate-900 dark:!text-slate-50">
|
||||
|
||||
<!-- Header -->
|
||||
<!-- ส่วนหัว (Header) -->
|
||||
<q-header
|
||||
class="bg-transparent text-slate-900 dark:!text-white border-none shadow-none"
|
||||
>
|
||||
<AppHeader @toggleSidebar="toggleLeftDrawer" />
|
||||
</q-header>
|
||||
|
||||
<!-- Navigation Sidebar -->
|
||||
<!-- แถบเมนูด้านข้าง (Navigation Sidebar) -->
|
||||
<q-drawer
|
||||
v-model="leftDrawerOpen"
|
||||
show-if-above
|
||||
|
|
@ -42,7 +43,7 @@ const isDashboardRoute = computed(() => {
|
|||
<AppSidebar />
|
||||
</q-drawer>
|
||||
|
||||
<!-- Main Content Area -->
|
||||
<!-- พื้นที่แสดงเนื้อหาหลัก (Main Content Area) -->
|
||||
<q-page-container>
|
||||
<q-page class="px-3 py-6 md:p-8">
|
||||
<div class="max-w-[1600px] mx-auto">
|
||||
|
|
|
|||
|
|
@ -23,20 +23,20 @@ onMounted(() => {
|
|||
<q-layout view="lHh LpR lFf" class="bg-white text-slate-900">
|
||||
|
||||
|
||||
<!-- Header (Transparent & Overlay) -->
|
||||
<!-- ส่วนหัวของเพจ (แบบโปร่งใส และซ้อนทับให้โชว์เนื้อหาพื้นหลังได้) -->
|
||||
<q-header class="bg-transparent" style="height: auto;">
|
||||
<LandingHeader />
|
||||
</q-header>
|
||||
|
||||
<!-- Main Content -->
|
||||
<!-- padding-top: 0 forces content to go under the header (Hero effect) -->
|
||||
<!-- ส่วนเนื้อหาหลัก -->
|
||||
<!-- แทรก style padding-top: 0 บังคับให้เนื้อหาใต้ Header ชนชิดด้านบนสุด (ทำเป็น Hero section สวยๆ) -->
|
||||
<q-page-container style="padding-top: 0 !important;">
|
||||
<q-page>
|
||||
<slot />
|
||||
</q-page>
|
||||
</q-page-container>
|
||||
|
||||
<!-- Footer -->
|
||||
<!-- ส่วนท้ายของเพจ -->
|
||||
<LandingFooter />
|
||||
|
||||
|
||||
|
|
|
|||
8762
Frontend-Learner/package-lock.json
generated
8762
Frontend-Learner/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -19,9 +19,14 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@nuxt/eslint-config": "^1.12.1",
|
||||
"@nuxt/test-utils": "^4.0.0",
|
||||
"@nuxtjs/i18n": "^10.2.1",
|
||||
"@playwright/test": "^1.58.2",
|
||||
"@types/node": "^22.19.8",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
"eslint": "^9.39.2",
|
||||
"typescript": "^5.4.5"
|
||||
"jsdom": "^28.1.0",
|
||||
"typescript": "^5.4.5",
|
||||
"vitest": "^4.0.18"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ const isLoading = ref(false)
|
|||
const rememberMe = ref(false)
|
||||
const showPassword = ref(false)
|
||||
|
||||
// Form data model
|
||||
// ข้อมูลฟอร์มสำหรับเก็บค่าอีเมลและรหัสผ่าน
|
||||
const loginForm = reactive({
|
||||
email: '',
|
||||
password: ''
|
||||
|
|
@ -31,7 +31,7 @@ const loginForm = reactive({
|
|||
|
||||
type LoginField = keyof typeof loginForm
|
||||
|
||||
// Validation rules definition
|
||||
// การตั้งค่ากฎการตรวจสอบ (Validation Rules)
|
||||
// กำหนดกฎการตรวจสอบข้อมูล (Validation Rules)
|
||||
const loginRules = {
|
||||
email: {
|
||||
|
|
@ -108,12 +108,12 @@ const handleLogin = async () => {
|
|||
}
|
||||
|
||||
|
||||
// Show error on specific fields
|
||||
// Show generic error for security (or specific if role mismatch)
|
||||
// แสดงข้อผิดพลาดตามช่องหรือแสดงข้อผิดพลาดรวม (เพื่อความปลอดภัย)
|
||||
// กรณีเข้าสู่ระบบไม่สำเร็จ
|
||||
if (result.error === 'Email ไม่ถูกต้อง') {
|
||||
errors.value.email = result.error // Role mismatch case
|
||||
errors.value.email = result.error // กรณี Role ไม่ตรงกัน
|
||||
} else {
|
||||
// Generic login failure (401, 404, etc.)
|
||||
// ข้อผิดพลาดแบบเหมาสำหรับปัญหาการเข้าสู่ระบบทั่วไป (เช่น รหัสผิด, ไม่พบผู้ใช้)
|
||||
const msg = 'กรุณาเช็ค Email หรือ รหัสผ่านใหม่อีกครั้ง'
|
||||
errors.value.email = msg
|
||||
errors.value.password = msg
|
||||
|
|
@ -147,7 +147,7 @@ onMounted(() => {
|
|||
========================================== -->
|
||||
<div class="w-full max-w-[460px] relative z-10 slide-up">
|
||||
|
||||
<!-- Header / Logo -->
|
||||
<!-- ส่วนหัวโปรไฟล์ / โลโก้ (Header / Logo) -->
|
||||
<div class="text-center mb-8">
|
||||
<div class="inline-flex items-center justify-center w-14 h-14 rounded-2xl bg-gradient-to-tr from-blue-600 to-indigo-600 text-white shadow-lg shadow-blue-600/20 mb-6">
|
||||
<span class="font-black text-2xl">E</span>
|
||||
|
|
@ -158,10 +158,10 @@ onMounted(() => {
|
|||
|
||||
<div class="bg-white rounded-[2rem] p-8 md:p-10 shadow-xl shadow-slate-200/50 border border-slate-100 relative overflow-hidden">
|
||||
|
||||
<!-- Form -->
|
||||
<!-- ฟอร์มเข้าสู่ระบบ (Login Form) -->
|
||||
<form @submit.prevent="handleLogin" class="flex flex-col gap-5">
|
||||
|
||||
<!-- Email Input -->
|
||||
<!-- ช่องกรอกอีเมล (Email Input) -->
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-slate-700 mb-2 ml-1">อีเมล</label>
|
||||
<div class="relative group">
|
||||
|
|
@ -180,7 +180,7 @@ onMounted(() => {
|
|||
<span v-if="errors.email" class="text-xs text-red-500 font-medium ml-1 mt-1 block slide-up-sm">{{ errors.email }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Password Input -->
|
||||
<!-- ช่องกรอกรหัสผ่าน (Password Input) -->
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-slate-700 mb-2 ml-1">รหัสผ่าน</label>
|
||||
<div class="relative group">
|
||||
|
|
@ -206,7 +206,7 @@ onMounted(() => {
|
|||
<span v-if="errors.password" class="text-xs text-red-500 font-medium ml-1 mt-1 block slide-up-sm">{{ errors.password }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Options -->
|
||||
<!-- ตัวเลือกเพิ่มเติม (จดจำฉัน, ลืมรหัสผ่าน) (Options) -->
|
||||
<div class="flex items-center justify-between mt-1">
|
||||
<label class="flex items-center gap-2.5 cursor-pointer group select-none">
|
||||
<div class="relative flex items-center">
|
||||
|
|
@ -227,7 +227,7 @@ onMounted(() => {
|
|||
</NuxtLink>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<!-- ปุ่มยืนยันเข้าสู่ระบบ (Submit Button) -->
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="isLoading"
|
||||
|
|
@ -237,7 +237,7 @@ onMounted(() => {
|
|||
<div v-else class="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
|
||||
</button>
|
||||
|
||||
<!-- Test Credentials Box -->
|
||||
<!-- กล่องแนะนำบัญชีสำหรับทดสอบ (Test Credentials Box) -->
|
||||
<div class="mt-4 p-5 bg-blue-50/50 border border-blue-100 rounded-2xl flex flex-col items-center gap-2 animate-fade-in">
|
||||
<div class="text-[11px] font-black uppercase tracking-[0.2em] text-blue-600 mb-1">บัญชีสำหรับทดสอบ (Test Account)</div>
|
||||
<div class="flex flex-col items-center gap-1">
|
||||
|
|
@ -253,7 +253,7 @@ onMounted(() => {
|
|||
|
||||
</form>
|
||||
|
||||
<!-- Register Link -->
|
||||
<!-- ลิงก์สำหรับสมัครสมาชิกใหม่ (Register Link) -->
|
||||
<div class="text-center mt-8">
|
||||
<p class="text-slate-600 text-sm">
|
||||
ยังไม่มีบัญชีสมาชิก?
|
||||
|
|
@ -265,7 +265,7 @@ onMounted(() => {
|
|||
|
||||
</div>
|
||||
|
||||
<!-- Back Link -->
|
||||
<!-- ลิงก์ย้อนกลับ (Back Link) -->
|
||||
<div class="mt-8 text-center text-slate-500">
|
||||
<NuxtLink to="/" class="inline-flex items-center gap-2 text-sm font-medium hover:text-slate-800 transition-colors group px-4 py-2 rounded-lg hover:bg-white/50">
|
||||
<span class="group-hover:-translate-x-1 transition-transform">←</span> กลับไปหน้าแรก
|
||||
|
|
@ -276,7 +276,7 @@ onMounted(() => {
|
|||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Animations */
|
||||
/* เอฟเฟกต์การเคลื่อนไหว (Animations) */
|
||||
@keyframes pulse-slow {
|
||||
0%, 100% { opacity: 0.3; transform: scale(1); }
|
||||
50% { opacity: 0.5; transform: scale(1.15); }
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ const sortBy = ref('ยอดนิยม');
|
|||
const sortOptions = ['ยอดนิยม', 'ล่าสุด', 'ราคาต่ำ-สูงสุด', 'ราคาสูง-ต่ำสุด'];
|
||||
|
||||
const categories = ref<any[]>([]);
|
||||
const courses = ref<any[]>([]);
|
||||
const allCourses = ref<any[]>([]); // เก็บคอร์สทั้งหมดเพื่อกรอง client-side
|
||||
const selectedCourse = ref<any>(null);
|
||||
|
||||
const isLoading = ref(false);
|
||||
|
|
@ -76,20 +76,17 @@ const loadCategories = async () => {
|
|||
if (res.success) categories.value = res.data || [];
|
||||
};
|
||||
|
||||
const loadCourses = async (page = 1) => {
|
||||
const loadCourses = async () => {
|
||||
isLoading.value = true;
|
||||
const categoryId = activeCategory.value === 'all' ? undefined : activeCategory.value as number;
|
||||
|
||||
// โหลดคอร์สทั้งหมดครั้งเดียว (limit สูงๆ เพื่อ client-side filter)
|
||||
const res = await fetchCourses({
|
||||
category_id: categoryId,
|
||||
search: searchQuery.value,
|
||||
page: page,
|
||||
limit: itemsPerPage,
|
||||
limit: 500,
|
||||
forceRefresh: true,
|
||||
});
|
||||
|
||||
if (res.success) {
|
||||
courses.value = (res.data || []).map(c => {
|
||||
allCourses.value = (res.data || []).map(c => {
|
||||
const cat = categories.value.find(cat => cat.id === c.category_id);
|
||||
return {
|
||||
...c,
|
||||
|
|
@ -100,12 +97,33 @@ const loadCourses = async (page = 1) => {
|
|||
reviews_count: c.total_lessons ? c.total_lessons * 123 : Math.floor(Math.random() * 2000) + 100
|
||||
}
|
||||
});
|
||||
totalPages.value = res.totalPages || 1;
|
||||
currentPage.value = res.page || 1;
|
||||
}
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
// Computed: กรองคอร์สแบบ real-time ตาม searchQuery + activeCategory
|
||||
const filteredCourses = computed(() => {
|
||||
let result = allCourses.value;
|
||||
|
||||
// กรองตามหมวดหมู่
|
||||
if (activeCategory.value !== 'all') {
|
||||
result = result.filter(c => c.category_id === activeCategory.value);
|
||||
}
|
||||
|
||||
// กรองตามคำค้นหา (ค้นจากชื่อทั้ง th และ en)
|
||||
if (searchQuery.value.trim()) {
|
||||
const query = searchQuery.value.trim().toLowerCase();
|
||||
result = result.filter(c => {
|
||||
const titleTh = (c.title?.th || '').toLowerCase();
|
||||
const titleEn = (c.title?.en || '').toLowerCase();
|
||||
const titleStr = (typeof c.title === 'string' ? c.title : '').toLowerCase();
|
||||
return titleTh.includes(query) || titleEn.includes(query) || titleStr.includes(query);
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
const selectCourse = async (id: number) => {
|
||||
isLoadingDetail.value = true;
|
||||
selectedCourse.value = null;
|
||||
|
|
@ -137,10 +155,10 @@ watch(
|
|||
activeCategory,
|
||||
() => {
|
||||
currentPage.value = 1;
|
||||
loadCourses(1);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
onMounted(async () => {
|
||||
await loadCategories();
|
||||
|
||||
|
|
@ -150,7 +168,7 @@ onMounted(async () => {
|
|||
activeCategory.value = Number(route.query.category_id);
|
||||
}
|
||||
|
||||
await loadCourses(1);
|
||||
await loadCourses();
|
||||
|
||||
if (route.query.course_id) {
|
||||
selectCourse(Number(route.query.course_id));
|
||||
|
|
@ -162,19 +180,19 @@ onMounted(async () => {
|
|||
<div class="bg-[#F8F9FA] dark:bg-[#020617] min-h-screen p-4 md:p-8 transition-colors duration-300">
|
||||
<div class="max-w-[1240px] mx-auto">
|
||||
<!-- ส่วนของการค้นหาคอร์ส (Catalog View) -->
|
||||
<div v-if="!showDetail" class="bg-white dark:bg-slate-900 rounded-[2rem] p-6 md:p-8 shadow-[0_2px_15px_rgb(0,0,0,0.02)] border border-slate-100 dark:border-slate-800 min-h-[500px] mb-12">
|
||||
<div v-if="!showDetail" class="bg-white dark:!bg-slate-900 rounded-[2rem] p-6 md:p-8 shadow-[0_2px_15px_rgb(0,0,0,0.02)] border border-slate-100 dark:!border-slate-800 min-h-[500px] mb-12 transition-colors">
|
||||
|
||||
<!-- ส่วนหัวและการค้นหา -->
|
||||
<div class="flex flex-col md:flex-row md:items-center justify-between gap-6 mb-8">
|
||||
<h2 class="text-[1.35rem] font-bold text-slate-900 dark:text-white tracking-tight">คอร์สเรียนทั้งหมด</h2>
|
||||
<h2 class="text-[1.35rem] font-bold text-slate-900 dark:text-[#f8fafc] tracking-tight">{{ $t('discovery.title') }}</h2>
|
||||
<div class="flex flex-wrap sm:flex-nowrap items-center gap-3 w-full md:w-auto">
|
||||
<div class="relative w-full sm:w-[260px] flex-1">
|
||||
<q-icon name="search" size="18px" class="absolute left-4 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within:text-[#3B6BE8]" />
|
||||
<input v-model="searchQuery" @keyup.enter="loadCourses(1)" class="w-full bg-slate-100 dark:bg-slate-800 border-none rounded-xl py-2.5 pl-11 pr-4 text-sm font-medium text-slate-700 dark:text-slate-200 placeholder:text-slate-400 focus:ring-2 focus:ring-blue-500/20 outline-none transition-all shadow-sm" placeholder="ค้นหาคอร์ส..." />
|
||||
<q-icon name="search" size="18px" class="absolute left-4 top-1/2 -translate-y-1/2 text-slate-400" />
|
||||
<input v-model="searchQuery" class="w-full bg-slate-100 dark:bg-slate-800 border-none rounded-xl py-2.5 pl-11 pr-4 text-sm font-medium text-slate-700 dark:text-slate-200 placeholder:text-slate-400 focus:ring-2 focus:ring-blue-500/20 outline-none transition-all shadow-sm" :placeholder="$t('discovery.searchPlaceholder')" />
|
||||
</div>
|
||||
<div class="flex items-center gap-2 shrink-0">
|
||||
<button @click="viewMode = 'grid'" :class="viewMode === 'grid' ? 'bg-[#E9EFFD] dark:bg-blue-900/40 text-[#3B6BE8] border-[#3B6BE8]' : 'bg-white border-slate-200 dark:bg-slate-800 dark:border-slate-700 text-slate-400 hover:bg-slate-50'" class="w-[42px] h-[42px] flex items-center justify-center rounded-xl border transition-colors outline-none"><q-icon name="grid_view" size="20px" /></button>
|
||||
<button @click="viewMode = 'list'" :class="viewMode === 'list' ? 'bg-[#E9EFFD] dark:bg-blue-900/40 text-[#3B6BE8] border-[#3B6BE8]' : 'bg-white border-slate-200 dark:bg-slate-800 dark:border-slate-700 text-slate-400 hover:bg-slate-50'" class="w-[42px] h-[42px] flex items-center justify-center rounded-xl border transition-colors outline-none"><q-icon name="view_list" size="20px" /></button>
|
||||
<button @click="viewMode = 'grid'" :class="viewMode === 'grid' ? 'bg-[#E9EFFD] dark:!bg-blue-900/40 text-[#3B6BE8] dark:!text-blue-400 border-[#3B6BE8] dark:!border-blue-400' : 'bg-white border-slate-200 dark:!bg-slate-800 dark:!border-slate-700 text-slate-400 dark:!text-slate-300 hover:bg-slate-50 dark:hover:!bg-slate-700'" class="w-[42px] h-[42px] flex items-center justify-center rounded-xl border transition-colors outline-none"><q-icon name="grid_view" size="20px" /></button>
|
||||
<button @click="viewMode = 'list'" :class="viewMode === 'list' ? 'bg-[#E9EFFD] dark:!bg-blue-900/40 text-[#3B6BE8] dark:!text-blue-400 border-[#3B6BE8] dark:!border-blue-400' : 'bg-white border-slate-200 dark:!bg-slate-800 dark:!border-slate-700 text-slate-400 dark:!text-slate-300 hover:bg-slate-50 dark:hover:!bg-slate-700'" class="w-[42px] h-[42px] flex items-center justify-center rounded-xl border transition-colors outline-none"><q-icon name="view_list" size="20px" /></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -185,17 +203,17 @@ onMounted(async () => {
|
|||
<div class="flex flex-wrap items-center gap-3 w-full xl:w-auto">
|
||||
<button
|
||||
@click="activeCategory = 'all'"
|
||||
:class="activeCategory === 'all' ? 'bg-[#E9EFFD] dark:bg-blue-900/40 text-[#3B6BE8] border-transparent font-bold' : 'bg-white dark:bg-transparent border-slate-200 dark:border-slate-700 text-slate-800 dark:text-slate-300 hover:border-slate-300 font-medium'"
|
||||
:class="activeCategory === 'all' ? 'bg-[#E9EFFD] dark:!bg-blue-900/40 text-[#3B6BE8] dark:!text-blue-400 border-transparent font-bold' : 'bg-white dark:!bg-slate-800 border-slate-200 dark:!border-slate-700 text-slate-800 dark:!text-slate-200 hover:border-slate-300 dark:hover:!border-slate-600 font-medium'"
|
||||
class="px-5 py-2.5 rounded-full border text-[13px] sm:text-[14px] flex items-center justify-center gap-2 transition-all outline-none">
|
||||
<q-icon name="check_circle_outline" size="18px" :class="activeCategory === 'all' ? 'text-[#3B6BE8]' : 'text-slate-400'"/> ทั้งหมด
|
||||
<q-icon name="check_circle_outline" size="18px" :class="activeCategory === 'all' ? 'text-[#3B6BE8] dark:!text-blue-400' : 'text-slate-400 dark:!text-slate-400'"/> {{ $t('discovery.allCategory') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
v-for="cat in categories" :key="cat.id"
|
||||
@click="activeCategory = cat.id"
|
||||
:class="activeCategory === cat.id ? 'bg-[#E9EFFD] dark:bg-blue-900/40 text-[#3B6BE8] border-transparent font-bold' : 'bg-white dark:bg-transparent border-slate-200 dark:border-slate-700 text-slate-800 dark:text-slate-300 hover:border-slate-300 font-medium'"
|
||||
class="px-5 py-2.5 rounded-full border text-[13px] sm:text-[14px] flex items-center justify-center gap-2 transition-all outline-none bg-transparent">
|
||||
<q-icon :name="getCategoryIcon(cat.name)" size="18px" :class="activeCategory === cat.id ? 'text-[#3B6BE8]' : 'text-slate-600 dark:text-slate-400'"/>
|
||||
:class="activeCategory === cat.id ? 'bg-[#E9EFFD] dark:!bg-blue-900/40 text-[#3B6BE8] dark:!text-blue-400 border-transparent font-bold' : 'bg-white dark:!bg-slate-800 border-slate-200 dark:!border-slate-700 text-slate-800 dark:!text-slate-200 hover:border-slate-300 dark:hover:!border-slate-600 font-medium'"
|
||||
class="px-5 py-2.5 rounded-full border text-[13px] sm:text-[14px] flex items-center justify-center gap-2 transition-all outline-none">
|
||||
<q-icon :name="getCategoryIcon(cat.name)" size="18px" :class="activeCategory === cat.id ? 'text-[#3B6BE8] dark:!text-blue-400' : 'text-slate-600 dark:!text-slate-400'"/>
|
||||
{{ getLocalizedText(cat.name) }}
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -208,10 +226,10 @@ onMounted(async () => {
|
|||
<q-spinner size="3rem" color="primary" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="courses.length > 0">
|
||||
<div v-else-if="filteredCourses.length > 0">
|
||||
<!-- GRID VIEW -->
|
||||
<div v-if="viewMode === 'grid'" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
<div v-for="course in courses" :key="course.id" class="flex flex-col rounded-[1.5rem] bg-white dark:bg-slate-900 border border-slate-100 dark:border-slate-800 overflow-hidden shadow-[0_2px_10px_rgb(0,0,0,0.03)] hover:shadow-[0_8px_30px_rgb(0,0,0,0.08)] transition-all duration-300 group cursor-pointer" @click="selectCourse(course.id)">
|
||||
<div v-for="course in filteredCourses" :key="course.id" class="flex flex-col rounded-[1.5rem] bg-white dark:!bg-slate-900 border border-slate-100 dark:!border-slate-800 overflow-hidden shadow-[0_2px_10px_rgb(0,0,0,0.03)] hover:shadow-[0_8px_30px_rgb(0,0,0,0.08)] transition-all duration-300 group cursor-pointer" @click="selectCourse(course.id)">
|
||||
<!-- Thumbnail -->
|
||||
<div class="relative w-full aspect-[16/10] bg-slate-100 dark:bg-slate-800 overflow-hidden">
|
||||
<img :src="course.thumbnail_url" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500" />
|
||||
|
|
@ -222,7 +240,7 @@ onMounted(async () => {
|
|||
|
||||
<!-- Body -->
|
||||
<div class="p-5 flex flex-col flex-1">
|
||||
<h3 class="font-bold text-slate-900 dark:text-white text-[15px] leading-snug line-clamp-2 mb-2">{{ getLocalizedText(course.title) }}</h3>
|
||||
<h3 class="font-bold text-slate-900 dark:text-[#f8fafc] text-[15px] leading-snug line-clamp-2 mb-2 group-hover:text-blue-600 dark:group-hover:text-blue-400 transition-colors">{{ getLocalizedText(course.title) }}</h3>
|
||||
|
||||
|
||||
|
||||
|
|
@ -230,8 +248,7 @@ onMounted(async () => {
|
|||
<div class="font-[900] text-[18px]" :class="course.is_free ? 'text-green-500' : 'text-[#2563EB] dark:text-blue-400'">
|
||||
{{ course.formatted_price }}
|
||||
</div>
|
||||
<!-- Eye icon circle button -->
|
||||
<button class="w-[38px] h-[38px] rounded-full bg-slate-50 dark:bg-slate-800 text-slate-400 dark:text-slate-500 flex items-center justify-center hover:bg-blue-50 hover:text-blue-600 dark:hover:bg-slate-700 border border-slate-100 dark:border-slate-700 transition-colors shadow-sm outline-none">
|
||||
<button class="w-[38px] h-[38px] rounded-full bg-slate-50 dark:!bg-slate-800 text-slate-400 dark:!text-slate-300 flex items-center justify-center hover:bg-blue-50 hover:text-blue-600 dark:hover:!bg-slate-700 dark:hover:!text-blue-400 border border-slate-100 dark:!border-slate-700 transition-colors shadow-sm outline-none">
|
||||
<q-icon name="visibility" size="18px" />
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -241,7 +258,7 @@ onMounted(async () => {
|
|||
|
||||
<!-- LIST VIEW -->
|
||||
<div v-else class="flex flex-col gap-5">
|
||||
<div v-for="course in courses" :key="course.id" class="flex flex-col sm:flex-row rounded-[1.5rem] bg-white dark:bg-slate-900 border border-slate-100 dark:border-slate-800 p-3 sm:p-4 gap-4 sm:gap-6 shadow-sm hover:shadow-[0_8px_30px_rgb(0,0,0,0.06)] transition-all duration-300 group cursor-pointer" @click="selectCourse(course.id)">
|
||||
<div v-for="course in filteredCourses" :key="course.id" class="flex flex-col sm:flex-row rounded-[1.5rem] bg-white dark:!bg-slate-900 border border-slate-100 dark:!border-slate-800 p-3 sm:p-4 gap-4 sm:gap-6 shadow-sm hover:shadow-[0_8px_30px_rgb(0,0,0,0.06)] transition-all duration-300 group cursor-pointer" @click="selectCourse(course.id)">
|
||||
<div class="relative w-full sm:w-[260px] aspect-[16/10] sm:aspect-auto sm:h-[160px] rounded-[1rem] bg-slate-100 dark:bg-slate-800 overflow-hidden shrink-0">
|
||||
<img :src="course.thumbnail_url" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500" />
|
||||
<div v-if="course.category_name" class="absolute top-3 left-3 bg-white/95 dark:bg-slate-900/95 backdrop-blur-md text-[#3B6BE8] dark:text-blue-400 font-bold text-[10px] px-3.5 py-1.5 rounded-full shadow-sm" style="border-radius: 9999px; padding: 4px 12px;">
|
||||
|
|
@ -250,15 +267,15 @@ onMounted(async () => {
|
|||
</div>
|
||||
<div class="flex flex-col flex-1 py-1">
|
||||
<div class="flex-1">
|
||||
<h3 class="font-bold text-slate-900 dark:text-white text-[16px] md:text-[18px] leading-snug line-clamp-2 md:line-clamp-1 mb-2">{{ getLocalizedText(course.title) }}</h3>
|
||||
<h3 class="font-bold text-slate-900 dark:text-[#f8fafc] text-[16px] md:text-[18px] leading-snug line-clamp-2 md:line-clamp-1 mb-2 group-hover:text-blue-600 dark:group-hover:text-blue-400 transition-colors">{{ getLocalizedText(course.title) }}</h3>
|
||||
|
||||
</div>
|
||||
<div class="mt-4 sm:mt-auto flex items-center justify-between">
|
||||
<div class="font-[900] text-[20px]" :class="course.is_free ? 'text-green-500' : 'text-[#2563EB] dark:text-blue-400'">
|
||||
{{ course.formatted_price }}
|
||||
</div>
|
||||
<button class="px-6 py-2 rounded-full bg-slate-50 text-slate-600 dark:bg-slate-800 dark:text-slate-300 font-bold text-[13px] flex items-center gap-2 hover:bg-blue-50 border border-slate-100 dark:border-slate-700 hover:text-blue-600 transition-colors">
|
||||
<q-icon name="visibility" size="16px" /> ดูรายละเอียด
|
||||
<button class="px-6 py-2 rounded-full bg-slate-50 text-slate-600 dark:!bg-slate-800 dark:!text-slate-300 font-bold text-[13px] flex items-center gap-2 hover:bg-blue-50 hover:text-blue-600 dark:hover:!bg-slate-700 dark:hover:!text-blue-400 border border-slate-100 dark:!border-slate-700 transition-colors">
|
||||
<q-icon name="visibility" size="16px" /> {{ $t('discovery.viewDetails') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -272,9 +289,9 @@ onMounted(async () => {
|
|||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<div v-else class="flex flex-col items-center justify-center py-20 bg-white dark:bg-slate-900/40 rounded-3xl border border-dashed border-slate-200 dark:border-slate-800">
|
||||
<div v-else class="flex flex-col items-center justify-center py-20 bg-white dark:!bg-slate-900/50 rounded-3xl border border-dashed border-slate-200 dark:!border-slate-800">
|
||||
<q-icon name="search_off" size="64px" class="text-slate-300 dark:text-slate-600 mb-4" />
|
||||
<h3 class="text-xl font-bold text-slate-900 dark:text-white mb-2">{{ $t("discovery.emptyTitle") }}</h3>
|
||||
<h3 class="text-xl font-bold text-slate-900 dark:!text-white mb-2">{{ $t("discovery.emptyTitle") }}</h3>
|
||||
<p class="text-slate-500 dark:text-slate-400 text-center max-w-md">{{ $t("discovery.emptyDesc") }}</p>
|
||||
<button class="mt-6 font-bold text-blue-600 hover:text-blue-700 transition-colors" @click="searchQuery = ''; activeCategory = 'all';">
|
||||
{{ $t("discovery.showAll") }}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file index.vue
|
||||
* @description Page displaying all available courses in a public catalog format.
|
||||
* Matches the requested modern layout.
|
||||
* @description หน้าแสดงคอร์สเรียนทั้งหมดในรูปแบบแคตตาล็อกสาธารณะ
|
||||
* ดีไซน์ปรับให้ทันสมัยเพื่อดึงดูดผู้ใช้งานใหม่
|
||||
*/
|
||||
|
||||
definePageMeta({
|
||||
|
|
@ -13,6 +13,7 @@ useHead({
|
|||
title: 'คอร์สทั้งหมด - E-Learning System'
|
||||
})
|
||||
|
||||
const { t } = useI18n()
|
||||
const searchQuery = ref('')
|
||||
const { fetchCourses } = useCourse()
|
||||
const { fetchCategories, categories } = useCategory()
|
||||
|
|
@ -54,7 +55,7 @@ await useAsyncData('categories-list', () => fetchCategories())
|
|||
const { data: coursesResponse, pending: isLoading, error, refresh } = await useAsyncData(
|
||||
'browse-courses-list',
|
||||
() => {
|
||||
const params: any = {}
|
||||
const params: any = { limit: 500 }
|
||||
if (selectedCategory.value !== 'all') {
|
||||
const category = categories.value.find(c => c.slug === selectedCategory.value)
|
||||
if (category) {
|
||||
|
|
@ -126,16 +127,16 @@ const viewMode = ref<'grid' | 'list'>('grid')
|
|||
<template>
|
||||
<div class="bg-[#F8F9FA] dark:bg-[#020617] min-h-screen pt-32 pb-20 px-4 md:px-8 transition-colors duration-300">
|
||||
<div class="max-w-[1240px] mx-auto">
|
||||
<!-- Catalog View -->
|
||||
<!-- มุมมองแคตตาล็อกแสดงคอร์ส (Catalog View) -->
|
||||
<div class="bg-white dark:bg-slate-900 rounded-[2rem] p-6 md:p-8 shadow-[0_2px_15px_rgb(0,0,0,0.02)] border border-slate-100 dark:border-slate-800 min-h-[500px] mb-12">
|
||||
|
||||
<!-- ส่วนหัวและการค้นหา -->
|
||||
<div class="flex flex-col md:flex-row md:items-center justify-between gap-6 mb-8">
|
||||
<h2 class="text-[1.35rem] font-bold text-slate-900 dark:text-white tracking-tight">คอร์สเรียนทั้งหมด</h2>
|
||||
<h2 class="text-[1.35rem] font-bold text-slate-900 dark:text-white tracking-tight">{{ $t('discovery.title') }}</h2>
|
||||
<div class="flex flex-wrap sm:flex-nowrap items-center gap-3 w-full md:w-auto">
|
||||
<div class="relative w-full sm:w-[260px] flex-1">
|
||||
<q-icon name="search" size="18px" class="absolute left-4 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within:text-[#3B6BE8]" />
|
||||
<input v-model="searchQuery" class="w-full bg-slate-100 dark:bg-slate-800 border-none rounded-xl py-2.5 pl-11 pr-4 text-sm font-medium text-slate-700 dark:text-slate-200 placeholder:text-slate-400 focus:ring-2 focus:ring-blue-500/20 outline-none transition-all shadow-sm" placeholder="ค้นหาคอร์ส..." />
|
||||
<input v-model="searchQuery" class="w-full bg-slate-100 dark:bg-slate-800 border-none rounded-xl py-2.5 pl-11 pr-4 text-sm font-medium text-slate-700 dark:text-slate-200 placeholder:text-slate-400 focus:ring-2 focus:ring-blue-500/20 outline-none transition-all shadow-sm" :placeholder="$t('discovery.searchPlaceholder')" />
|
||||
</div>
|
||||
<div class="flex items-center gap-2 shrink-0">
|
||||
<button @click="viewMode = 'grid'" :class="viewMode === 'grid' ? 'bg-[#E9EFFD] dark:bg-blue-900/40 text-[#3B6BE8] border-[#3B6BE8]' : 'bg-white border-slate-200 dark:bg-slate-800 dark:border-slate-700 text-slate-400 hover:bg-slate-50'" class="w-[42px] h-[42px] flex items-center justify-center rounded-xl border transition-colors outline-none"><q-icon name="grid_view" size="20px" /></button>
|
||||
|
|
@ -144,14 +145,14 @@ const viewMode = ref<'grid' | 'list'>('grid')
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Filters Category -->
|
||||
<!-- ตัวกรองหมวดหมู่ (Filters Category) -->
|
||||
<div class="flex flex-col xl:flex-row xl:items-center justify-between gap-4 mb-10 w-full relative">
|
||||
<div class="flex flex-wrap items-center gap-3 w-full xl:w-auto">
|
||||
<button
|
||||
@click="selectCategory('all')"
|
||||
:class="selectedCategory === 'all' ? 'bg-[#E9EFFD] dark:bg-blue-900/40 text-[#3B6BE8] border-transparent font-bold' : 'bg-white dark:bg-transparent border-slate-200 dark:border-slate-700 text-slate-800 dark:text-slate-300 hover:border-slate-300 font-medium'"
|
||||
class="px-5 py-2.5 rounded-full border text-[13px] sm:text-[14px] flex items-center justify-center gap-2 transition-all outline-none">
|
||||
<q-icon name="check_circle_outline" size="18px" :class="selectedCategory === 'all' ? 'text-[#3B6BE8]' : 'text-slate-400'"/> ทั้งหมด
|
||||
<q-icon name="check_circle_outline" size="18px" :class="selectedCategory === 'all' ? 'text-[#3B6BE8]' : 'text-slate-400'"/> {{ $t('discovery.allCategory') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
|
|
@ -165,16 +166,16 @@ const viewMode = ref<'grid' | 'list'>('grid')
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loader -->
|
||||
<!-- ตัวแสดงการโหลด (Loader) -->
|
||||
<div v-if="isLoading" class="flex justify-center py-24">
|
||||
<q-spinner size="3rem" color="primary" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="filteredCourses.length > 0">
|
||||
<!-- GRID VIEW -->
|
||||
<!-- มุมมองแบบกริด (GRID VIEW) -->
|
||||
<div v-if="viewMode === 'grid'" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
<NuxtLink v-for="course in filteredCourses" :key="course.id" :to="`/course/${course.id}`" class="flex flex-col rounded-[1.5rem] bg-white dark:bg-slate-900 border border-slate-100 dark:border-slate-800 overflow-hidden shadow-[0_2px_10px_rgb(0,0,0,0.03)] hover:shadow-[0_8px_30px_rgb(0,0,0,0.08)] transition-all duration-300 group cursor-pointer">
|
||||
<!-- Thumbnail -->
|
||||
<!-- รูปหน้าปก (Thumbnail) -->
|
||||
<div class="relative w-full aspect-[16/10] bg-slate-100 dark:bg-slate-800 overflow-hidden">
|
||||
<img :src="course.thumbnail_url" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500" />
|
||||
<div v-if="course.category_name" class="absolute top-3 left-3 bg-white/95 dark:bg-slate-900/95 backdrop-blur-md text-[#3B6BE8] dark:text-blue-400 font-bold text-[10px] px-3.5 py-1 rounded-full shadow-sm" style="border-radius: 9999px; padding: 4px 12px;">
|
||||
|
|
@ -182,25 +183,25 @@ const viewMode = ref<'grid' | 'list'>('grid')
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Body -->
|
||||
<!-- เนื้อหาคอร์ส (Body) -->
|
||||
<div class="p-5 flex flex-col flex-1">
|
||||
<h3 class="font-bold text-slate-900 dark:text-white text-[15px] leading-snug line-clamp-2 mb-2 group-hover:text-blue-600 transition-colors">{{ getLocalizedText(course.title) }}</h3>
|
||||
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<span class="text-[12px] text-slate-500 font-medium">โดย {{ course.instructor_name }}</span>
|
||||
<span class="text-[12px] text-slate-500 font-medium">{{ $t('discovery.byInstructor') }} {{ course.instructor_name }}</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-1.5 mb-5">
|
||||
<q-icon name="star" class="text-amber-400" size="16px" />
|
||||
<span class="text-[13px] font-bold text-slate-800 dark:text-slate-200">{{ course.rating }}</span>
|
||||
<span class="text-[12px] text-slate-400">({{ course.reviews_count.toLocaleString() }} นักเรียน)</span>
|
||||
<span class="text-[12px] text-slate-400">({{ course.reviews_count.toLocaleString() }} {{ $t('discovery.students') }})</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-auto flex items-center justify-between">
|
||||
<div class="font-[900] text-[18px]" :class="course.is_free ? 'text-green-500' : 'text-[#2563EB] dark:text-blue-400'">
|
||||
{{ course.formatted_price }}
|
||||
</div>
|
||||
<!-- Eye icon circle button -->
|
||||
<!-- ปุ่มกดรูปตาเพื่อดูรายละเอียด (Eye icon circle button) -->
|
||||
<button class="w-[38px] h-[38px] rounded-full bg-slate-50 dark:bg-slate-800 text-slate-400 dark:text-slate-500 flex items-center justify-center hover:bg-blue-50 hover:text-blue-600 dark:hover:bg-slate-700 border border-slate-100 dark:border-slate-700 transition-colors shadow-sm outline-none">
|
||||
<q-icon name="visibility" size="18px" />
|
||||
</button>
|
||||
|
|
@ -209,7 +210,7 @@ const viewMode = ref<'grid' | 'list'>('grid')
|
|||
</NuxtLink>
|
||||
</div>
|
||||
|
||||
<!-- LIST VIEW -->
|
||||
<!-- มุมมองแบบรายการ (LIST VIEW) -->
|
||||
<div v-else class="flex flex-col gap-5">
|
||||
<NuxtLink v-for="course in filteredCourses" :key="course.id" :to="`/course/${course.id}`" class="flex flex-col sm:flex-row rounded-[1.5rem] bg-white dark:bg-slate-900 border border-slate-100 dark:border-slate-800 p-3 sm:p-4 gap-4 sm:gap-6 shadow-sm hover:shadow-[0_8px_30px_rgb(0,0,0,0.06)] transition-all duration-300 group cursor-pointer">
|
||||
<div class="relative w-full sm:w-[260px] aspect-[16/10] sm:aspect-auto sm:h-[160px] rounded-[1rem] bg-slate-100 dark:bg-slate-800 overflow-hidden shrink-0">
|
||||
|
|
@ -222,12 +223,12 @@ const viewMode = ref<'grid' | 'list'>('grid')
|
|||
<div class="flex-1">
|
||||
<h3 class="font-bold text-slate-900 dark:text-white text-[16px] md:text-[18px] leading-snug line-clamp-2 md:line-clamp-1 mb-2 group-hover:text-blue-600 transition-colors">{{ getLocalizedText(course.title) }}</h3>
|
||||
<div class="flex items-center gap-2 mb-3">
|
||||
<span class="text-[13px] text-slate-500 font-medium">โดย {{ course.instructor_name }}</span>
|
||||
<span class="text-[13px] text-slate-500 font-medium">{{ $t('discovery.byInstructor') }} {{ course.instructor_name }}</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1.5 mb-2">
|
||||
<q-icon name="star" class="text-amber-400" size="16px" />
|
||||
<span class="text-[13px] font-bold text-slate-800 dark:text-slate-200">{{ course.rating }}</span>
|
||||
<span class="text-[12px] text-slate-400">({{ course.reviews_count.toLocaleString() }} นักเรียน)</span>
|
||||
<span class="text-[12px] text-slate-400">({{ course.reviews_count.toLocaleString() }} {{ $t('discovery.students') }})</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 sm:mt-auto flex items-center justify-between">
|
||||
|
|
@ -235,7 +236,7 @@ const viewMode = ref<'grid' | 'list'>('grid')
|
|||
{{ course.formatted_price }}
|
||||
</div>
|
||||
<button class="px-6 py-2 rounded-full bg-slate-50 text-slate-600 dark:bg-slate-800 dark:text-slate-300 font-bold text-[13px] flex items-center gap-2 hover:bg-blue-50 border border-slate-100 dark:border-slate-700 hover:text-blue-600 transition-colors">
|
||||
<q-icon name="visibility" size="16px" /> ดูรายละเอียด
|
||||
<q-icon name="visibility" size="16px" /> {{ $t('discovery.viewDetails') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -243,13 +244,13 @@ const viewMode = ref<'grid' | 'list'>('grid')
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<!-- กรณีไม่พบข้อมูลคอร์ส (Empty State) -->
|
||||
<div v-else class="flex flex-col items-center justify-center py-20 bg-white dark:bg-slate-900/40 rounded-3xl border border-dashed border-slate-200 dark:border-slate-800">
|
||||
<q-icon name="search_off" size="64px" class="text-slate-300 dark:text-slate-600 mb-4" />
|
||||
<h3 class="text-xl font-bold text-slate-900 dark:text-white mb-2">{{ searchQuery ? 'ไม่พบคอร์สที่คุณค้นหา' : 'ไม่มีคอร์สในหมวดหมู่นี้' }}</h3>
|
||||
<p class="text-slate-500 dark:text-slate-400 text-center max-w-md">ลองใช้คำค้นหาอื่น หรือเลือกหมวดหมู่อื่นเพื่อดูคอร์สที่เรามีให้บริการ</p>
|
||||
<h3 class="text-xl font-bold text-slate-900 dark:text-white mb-2">{{ $t('discovery.emptyTitle') }}</h3>
|
||||
<p class="text-slate-500 dark:text-slate-400 text-center max-w-md">{{ $t('discovery.emptyDesc') }}</p>
|
||||
<button class="mt-6 font-bold text-blue-600 hover:text-blue-700 transition-colors" @click="searchQuery = ''; selectedCategory = 'all';">
|
||||
แสดงคอร์สทั้งหมด
|
||||
{{ $t('discovery.showAll') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -258,7 +259,7 @@ const viewMode = ref<'grid' | 'list'>('grid')
|
|||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Disable default scrollbar for filter container */
|
||||
/* ปิดการแสดงแถบเลื่อนบนคอนเทนเนอร์ของตัวกรอง (Disable default scrollbar for filter container) */
|
||||
.no-scrollbar::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const { user } = useAuth()
|
|||
const { fetchCourseLearningInfo, fetchLessonContent, saveVideoProgress, checkLessonAccess, fetchVideoProgress, fetchCourseAnnouncements, markLessonComplete, getLocalizedText } = useCourse()
|
||||
const $q = useQuasar()
|
||||
|
||||
// State management
|
||||
// การจัดการสถานะ (State management)
|
||||
const sidebarOpen = ref(false)
|
||||
const courseId = computed(() => Number(route.query.course_id))
|
||||
|
||||
|
|
@ -31,11 +31,11 @@ const courseId = computed(() => Number(route.query.course_id))
|
|||
// ==========================================
|
||||
// courseData: เก็บข้อมูลโครงสร้างคอร์ส (บทเรียนต่างๆ)
|
||||
const courseData = ref<any>(null)
|
||||
const announcements = ref<any[]>([]) // Announcements state
|
||||
const showAnnouncementsModal = ref(false) // Modal state
|
||||
const hasUnreadAnnouncements = ref(false) // Unread state tracking
|
||||
const announcements = ref<any[]>([]) // สถานะของประกาศ (Announcements state)
|
||||
const showAnnouncementsModal = ref(false) // สถานะของป๊อปอัป (Modal state)
|
||||
const hasUnreadAnnouncements = ref(false) // ติดตามสถานะที่ยังไม่ได้อ่าน (Unread state tracking)
|
||||
|
||||
// Helper for persistent read status
|
||||
// ฟังก์ชันช่วยเหลือสำหรับเก็บสถานะการอ่านถาวร (Helper for persistent read status)
|
||||
const getAnnouncementStorageKey = () => {
|
||||
if (!user.value?.id || !courseId.value) return ''
|
||||
return `read_announcements:${user.value.id}:${courseId.value}`
|
||||
|
|
@ -61,17 +61,17 @@ const checkUnreadAnnouncements = () => {
|
|||
const lastReadDate = new Date(lastRead).getTime()
|
||||
const hasNew = announcements.value.some(a => {
|
||||
const annDate = new Date(a.created_at || Date.now()).getTime()
|
||||
// Check if announcement is strictly newer than last read
|
||||
// ตรวจสอบว่าประกาศใหม่กว่าที่อ่านครั้งล่าสุดหรือไม่ (Check if announcement is strictly newer than last read)
|
||||
return annDate > lastReadDate
|
||||
})
|
||||
|
||||
hasUnreadAnnouncements.value = hasNew
|
||||
}
|
||||
|
||||
// Handler for opening announcements
|
||||
// ฟังก์ชันจัดการเมื่อเปิดประกาศ (Handler for opening announcements)
|
||||
const handleOpenAnnouncements = () => {
|
||||
showAnnouncementsModal.value = true
|
||||
hasUnreadAnnouncements.value = false // Clear unread badge on click
|
||||
hasUnreadAnnouncements.value = false // ลบป้ายแจ้งเตือนเมื่อคลิก (Clear unread badge on click)
|
||||
|
||||
const key = getAnnouncementStorageKey()
|
||||
if (key) {
|
||||
|
|
@ -98,7 +98,7 @@ const toggleSidebar = () => {
|
|||
sidebarOpen.value = !sidebarOpen.value
|
||||
}
|
||||
|
||||
// Logic Quiz Attempt Management
|
||||
// การจัดการตรรกะจำนวนครั้งในการทำแบบทดสอบ (Logic Quiz Attempt Management)
|
||||
const quizStatus = computed(() => {
|
||||
if (!currentLesson.value || currentLesson.value.type !== 'QUIZ' || !currentLesson.value.quiz) return null
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ const quizStatus = computed(() => {
|
|||
const latestAttempt = quiz.latest_attempt
|
||||
const allowMultiple = quiz.allow_multiple_attempts
|
||||
|
||||
// If never attempted
|
||||
// หากยังไม่เคยทดสอบ (If never attempted)
|
||||
if (!latestAttempt) {
|
||||
return {
|
||||
canStart: true,
|
||||
|
|
@ -116,7 +116,7 @@ const quizStatus = computed(() => {
|
|||
}
|
||||
}
|
||||
|
||||
// If multiple attempts allowed
|
||||
// หากอนุญาตให้ทดสอบได้หลายครั้ง (If multiple attempts allowed)
|
||||
if (allowMultiple) {
|
||||
return {
|
||||
canStart: true,
|
||||
|
|
@ -128,8 +128,8 @@ const quizStatus = computed(() => {
|
|||
}
|
||||
}
|
||||
|
||||
// allowMultiple is false (Single attempt only)
|
||||
// Lock the quiz regardless of pass/fail once attempted
|
||||
// ไม่อนุญาตให้สอบได้หลายครั้ง (allowMultiple is false (Single attempt only))
|
||||
// ล็อกแบบทดสอบหลังทำเสร็จไม่ว่าจะผ่านหรือไม่ผ่าน (Lock the quiz regardless of pass/fail once attempted)
|
||||
return {
|
||||
canStart: false,
|
||||
label: latestAttempt.is_passed ? t('quiz.passedStatus') : t('quiz.failedStatus'),
|
||||
|
|
@ -145,7 +145,7 @@ const handleStartQuiz = () => {
|
|||
|
||||
const quiz = currentLesson.value.quiz
|
||||
|
||||
// If multiple attempts are disabled and it's the first time
|
||||
// หากทำได้ครั้งเดียวและนี่เป็นครั้งแรก (If multiple attempts are disabled and it's the first time)
|
||||
if (!quiz.allow_multiple_attempts && !quiz.latest_attempt) {
|
||||
$q.dialog({
|
||||
title: `<div class="text-slate-900 dark:text-white font-black text-xl">${t('quiz.warningTitle')}</div>`,
|
||||
|
|
@ -193,18 +193,18 @@ const resetAndNavigate = (path: string) => {
|
|||
}
|
||||
}
|
||||
|
||||
// 2. Clear all localStorage
|
||||
// 2. ลบข้อมูลใน localStorage ทั้งหมด (Clear all localStorage)
|
||||
localStorage.clear()
|
||||
|
||||
// 3. Restore ONLY whitelisted keys
|
||||
// 3. คืนค่าเฉพาะคีย์ที่อนุญาต (Restore ONLY whitelisted keys)
|
||||
Object.keys(whitelist).forEach(key => {
|
||||
localStorage.setItem(key, whitelist[key])
|
||||
})
|
||||
|
||||
// 4. Force hard reload to the new path
|
||||
// 4. บังคับโหลดหน้าเว็บใหม่ไปยังเส้นทางใหม่ (Force hard reload to the new path)
|
||||
window.location.href = path
|
||||
} else {
|
||||
// SSR Fallback
|
||||
// การทำงานสำรองสำหรับ SSR (SSR Fallback)
|
||||
router.push(path)
|
||||
}
|
||||
}
|
||||
|
|
@ -213,13 +213,13 @@ const resetAndNavigate = (path: string) => {
|
|||
const handleLessonSelect = (lessonId: number) => {
|
||||
if (currentLesson.value?.id === lessonId) return
|
||||
|
||||
// 1. Update URL query params
|
||||
// 1. อัปเดตพารามิเตอร์ใน URL (Update URL query params)
|
||||
router.push({ query: { ...route.query, lesson_id: lessonId.toString() } })
|
||||
|
||||
// 2. Load content without refresh
|
||||
// 2. โหลดเนื้อหาโดยไม่ต้องรีเฟรชหน้าเว็บ (Load content without refresh)
|
||||
loadLesson(lessonId)
|
||||
|
||||
// Close sidebar on mobile
|
||||
// ปิดแถบด้านข้างบนมือถือ (Close sidebar on mobile)
|
||||
if (sidebarOpen.value) {
|
||||
sidebarOpen.value = false
|
||||
}
|
||||
|
|
@ -245,7 +245,7 @@ const loadCourseData = async () => {
|
|||
if (res.success) {
|
||||
courseData.value = res.data
|
||||
|
||||
// Auto-load logic: Check URL first, fallback to first available lesson
|
||||
// ตรรกะการโหลดอัตโนมัติ: เช็ค URL ก่อน หากไม่มีให้โหลดบทเรียนแรก (Auto-load logic: Check URL first, fallback to first available lesson)
|
||||
const urlLessonId = route.query.lesson_id ? Number(route.query.lesson_id) : null
|
||||
|
||||
if (urlLessonId) {
|
||||
|
|
@ -258,7 +258,7 @@ const loadCourseData = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Fetch Course Announcements
|
||||
// ดึงข้อมูลประกาศของคอร์สเรียน (Fetch Course Announcements)
|
||||
const annRes = await fetchCourseAnnouncements(courseId.value)
|
||||
if (annRes.success) {
|
||||
announcements.value = annRes.data || []
|
||||
|
|
@ -275,7 +275,7 @@ const loadCourseData = async () => {
|
|||
const loadLesson = async (lessonId: number) => {
|
||||
if (currentLesson.value?.id === lessonId) return
|
||||
|
||||
// Clear previous video state & unload component to force reset
|
||||
// ล้างสถานะวิดีโอเดิมเพื่อบังคับตั้งค่าใหม่ (Clear previous video state & unload component to force reset)
|
||||
isPlaying.value = false
|
||||
videoProgress.value = 0
|
||||
currentTime.value = 0
|
||||
|
|
@ -285,16 +285,16 @@ const loadLesson = async (lessonId: number) => {
|
|||
lastSavedTimestamp.value = 0
|
||||
lastLocalSaveTimestamp.value = 0
|
||||
currentDuration.value = 0
|
||||
currentLesson.value = null // This will unmount VideoPlayer and hide content
|
||||
currentLesson.value = null // ตัวนี้จะทำการซ่อนวิดีโอและซ่อนเนื้อหา (This will unmount VideoPlayer and hide content)
|
||||
|
||||
isLessonLoading.value = true
|
||||
try {
|
||||
// Optional: Check access first
|
||||
// ป้องกันไว้ก่อน: ตรวจสอบสิทธิ์การเข้าถึง (Optional: Check access first)
|
||||
const accessRes = await checkLessonAccess(courseId.value, lessonId)
|
||||
if (accessRes.success && !accessRes.data.is_accessible) {
|
||||
let msg = t('classroom.notAvailable')
|
||||
|
||||
// Handle specific lock reasons
|
||||
// จัดการเหตุผลล็อกเฉพาะจุด (Handle specific lock reasons)
|
||||
if (accessRes.data.lock_reason) {
|
||||
msg = accessRes.data.lock_reason
|
||||
} else if (accessRes.data.required_quiz_pass && !accessRes.data.required_quiz_pass.is_passed) {
|
||||
|
|
@ -314,32 +314,32 @@ const loadLesson = async (lessonId: number) => {
|
|||
return
|
||||
}
|
||||
|
||||
// 1. Fetch content
|
||||
// 1. ดึงข้อมูลเนื้อหา (Fetch content)
|
||||
const res = await fetchLessonContent(courseId.value, lessonId)
|
||||
if (res.success) {
|
||||
currentLesson.value = res.data
|
||||
|
||||
// Initialize progress object if missing (Critical for New Users)
|
||||
// กำหนดค่าออบเจ็กต์ความคืบหน้าหากไม่มี (สำคัญสำหรับผู้ใช้ใหม่) (Initialize progress object if missing)
|
||||
if (!currentLesson.value.progress) {
|
||||
currentLesson.value.progress = {}
|
||||
}
|
||||
|
||||
// Update Lesson Completion UI status safely
|
||||
// อัปเดตสถานะสำเร็จของบทเรียนบน UI อย่างปลอดภัย (Update Lesson Completion UI status safely)
|
||||
if (currentLesson.value?.progress?.is_completed && courseData.value) {
|
||||
for (const chapter of courseData.value.chapters) {
|
||||
const lesson = chapter.lessons.find((l: any) => l.id === lessonId)
|
||||
if (lesson) {
|
||||
if (!lesson.progress) lesson.progress = {}
|
||||
lesson.progress.is_completed = true
|
||||
lesson.is_completed = true // Standardize completion property
|
||||
lesson.is_completed = true // ตั้งค่าสถานะสำเร็จให้เป็นมาตรฐาน (Standardize completion property)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fetch Initial Progress (Resume Playback)
|
||||
// 2. ดึงความคืบหน้าเริ่มต้นเพื่อเล่นต่อ (Fetch Initial Progress (Resume Playback))
|
||||
if (currentLesson.value.type === 'VIDEO') {
|
||||
// If already completed, clear local resume point to allow fresh re-watch
|
||||
// หากเรียนจบแล้ว ให้ล้างจุดที่ดูล่าสุดเพื่อดูใหม่ได้ (If already completed, clear local resume point to allow fresh re-watch)
|
||||
const isCompleted = currentLesson.value.progress?.is_completed || false
|
||||
|
||||
if (isCompleted) {
|
||||
|
|
@ -351,7 +351,7 @@ const loadLesson = async (lessonId: number) => {
|
|||
maxWatchedTime.value = 0
|
||||
currentTime.value = 0
|
||||
} else {
|
||||
// Not completed? Resume from where we left off
|
||||
// ถ้ายังเรียนไม่จบ? กลับไปเล่นจากจุดเดิม (Not completed? Resume from where we left off)
|
||||
const progressRes = await fetchVideoProgress(lessonId)
|
||||
let serverProgress = 0
|
||||
if (progressRes.success && progressRes.data?.video_progress_seconds) {
|
||||
|
|
@ -379,24 +379,24 @@ const loadLesson = async (lessonId: number) => {
|
|||
}
|
||||
}
|
||||
|
||||
// Video Player Ref (Component)
|
||||
// ข้อมูลอ้างอิงวิดีโอ (Video Player Ref (Component))
|
||||
const videoPlayerComp = ref(null)
|
||||
|
||||
// Video & Progress State
|
||||
// สถานะความก้าวหน้าและวิดีโอ (Video & Progress State)
|
||||
const initialSeekTime = ref(0)
|
||||
const maxWatchedTime = ref(0) // Anti-rewind monotonic tracking
|
||||
const maxWatchedTime = ref(0) // การติดตามแบบไม่ย้อนกลับ (Anti-rewind monotonic tracking)
|
||||
const lastSavedTime = ref(-1)
|
||||
const lastSavedTimestamp = ref(0) // Server throttle timestamp
|
||||
const lastLocalSaveTimestamp = ref(0) // Local throttle timestamp
|
||||
const currentDuration = ref(0) // Track duration for save logic
|
||||
const lastSavedTimestamp = ref(0) // เวลาบันทึกในเซิร์ฟเวอร์ (Server throttle timestamp)
|
||||
const lastLocalSaveTimestamp = ref(0) // เวลาบันทึกในเครื่อง (Local throttle timestamp)
|
||||
const currentDuration = ref(0) // ติดตามเวลาของวิดีโอ (Track duration for save logic)
|
||||
|
||||
// Helper: Get Local Storage Key
|
||||
// ฟังก์ชันช่วยเหลือ: ชื่อคีย์สำหรับ Local Storage (Helper: Get Local Storage Key)
|
||||
const getLocalProgressKey = (lessonId: number) => {
|
||||
if (!user.value?.id) return null
|
||||
return `progress:${user.value.id}:${lessonId}`
|
||||
}
|
||||
|
||||
// Helper: Get Local Progress
|
||||
// ฟังก์ชันช่วยเหลือ: ดึงความคืบหน้าจากเครื่อง (Helper: Get Local Progress)
|
||||
const getLocalProgress = (lessonId: number): number => {
|
||||
try {
|
||||
const key = getLocalProgressKey(lessonId)
|
||||
|
|
@ -408,7 +408,7 @@ const getLocalProgress = (lessonId: number): number => {
|
|||
}
|
||||
}
|
||||
|
||||
// Helper: Save to Local Storage
|
||||
// ฟังก์ชันช่วยเหลือ: บันทึกลงเครื่อง (Helper: Save to Local Storage)
|
||||
const saveLocalProgress = (lessonId: number, time: number) => {
|
||||
try {
|
||||
const key = getLocalProgressKey(lessonId)
|
||||
|
|
@ -416,31 +416,31 @@ const saveLocalProgress = (lessonId: number, time: number) => {
|
|||
localStorage.setItem(key, time.toString())
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore storage errors
|
||||
// ข้ามกรณีเกิดข้อผิดพลาดในการบันทึก (Ignore storage errors)
|
||||
}
|
||||
}
|
||||
|
||||
// Handler: Video Time Update (from Component)
|
||||
// ฟังก์ชันจัดการเวลาของวิดีโอ (จาก Component) (Handler: Video Time Update (from Component))
|
||||
const handleVideoTimeUpdate = (cTime: number, dur: number) => {
|
||||
currentDuration.value = dur || 0
|
||||
|
||||
// Update Monotonic Progress
|
||||
// อัปเดตความคืบหน้าแบบทางเดียว (Update Monotonic Progress)
|
||||
if (cTime > maxWatchedTime.value) {
|
||||
maxWatchedTime.value = cTime
|
||||
}
|
||||
|
||||
// Logic: Periodic Save
|
||||
// ตรรกะ: บันทึกเป็นระยะ (Logic: Periodic Save)
|
||||
if (currentLesson.value?.id) {
|
||||
const now = Date.now()
|
||||
|
||||
// 1. Local Save Throttle (5 seconds)
|
||||
// 1. การหน่วงเวลาบันทึกในเครื่อง (5 วินาที) (Local Save Throttle (5 seconds))
|
||||
if (now - lastLocalSaveTimestamp.value > 5000) {
|
||||
saveLocalProgress(currentLesson.value.id, maxWatchedTime.value)
|
||||
lastLocalSaveTimestamp.value = now
|
||||
}
|
||||
|
||||
// 2. Server Save Throttle (handled inside performSaveProgress)
|
||||
// Note: We don't check isPlaying here because if time is updating, it IS playing.
|
||||
// 2. การหน่วงเวลาบันทึกบนเซิร์ฟเวอร์ (จัดการใน performSaveProgress)
|
||||
// หมายเหตุ: เราไม่เช็ค isPlaying ตรงนี้เพราะถ้าเวลาเดินแปลว่าเล่นอยู่ (Note: We don't check isPlaying here because if time is updating, it IS playing.)
|
||||
performSaveProgress(false, false)
|
||||
}
|
||||
}
|
||||
|
|
@ -451,49 +451,49 @@ const onVideoMetadataLoaded = (duration: number) => {
|
|||
}
|
||||
}
|
||||
|
||||
const isCompleting = ref(false) // Flag to prevent race conditions during completion
|
||||
const isCompleting = ref(false) // ตัวแปรกันการแย่งกันทำงานตอนเรียนจบ (Flag to prevent race conditions during completion)
|
||||
|
||||
// -----------------------------------------------------
|
||||
// ROBUST PROGRESS SAVING SYSTEM (Hybrid: Local + Server)
|
||||
// ระบบบันทึกความคืบหน้าที่แข็งแกร่ง (ไฮบริด: ในเครื่อง + เซิร์ฟเวอร์) (ROBUST PROGRESS SAVING SYSTEM (Hybrid: Local + Server))
|
||||
// -----------------------------------------------------
|
||||
|
||||
// Main Server Save Function
|
||||
// ฟังก์ชันหลักสำหรับบันทึกลงเซิร์ฟเวอร์ (Main Server Save Function)
|
||||
const performSaveProgress = async (force: boolean = false, keepalive: boolean = false) => {
|
||||
const lesson = currentLesson.value
|
||||
if (!lesson || lesson.type !== 'VIDEO') return
|
||||
|
||||
// Ensure progress object exists
|
||||
// ทำให้แน่ใจว่ามีออบเจ็กต์ความคืบหน้าอยู่ (Ensure progress object exists)
|
||||
if (!lesson.progress) lesson.progress = {}
|
||||
|
||||
// 1. Completed Guard: Stop everything if already completed
|
||||
// 1. ป้องกันเมื่อดูจบแล้ว: ไม่ต้องบันทึกอีกถ้าดูจบไปแล้ว (Completed Guard: Stop everything if already completed)
|
||||
if (lesson.progress.is_completed) return
|
||||
|
||||
// 2. Race Condition Guard: Stop if currently completing
|
||||
// 2. ป้องกันการเรียกซ้ำ: ไม่ทำงานถ้ากำลังบันทึกเวลาจบอยู่ (Race Condition Guard: Stop if currently completing)
|
||||
if (isCompleting.value) return
|
||||
|
||||
const now = Date.now()
|
||||
const maxSec = Math.floor(maxWatchedTime.value) // Use max watched time
|
||||
const maxSec = Math.floor(maxWatchedTime.value) // ใช้เวลาที่ดูไปมากที่สุด (Use max watched time)
|
||||
const durationSec = Math.floor(currentDuration.value || 0)
|
||||
|
||||
// 3. Monotonic Check: Allow saving 0 if it's the very first save (lastSavedTime is -1)
|
||||
// 3. ตรวจสอบการเดินหน้า: ยอมให้บันทึก 0 ได้ถ้าเป็นการบันทึกครั้งแรก (lastSavedTime is -1) (Monotonic Check: Allow saving 0 if it's the very first save)
|
||||
if (!force) {
|
||||
if (lastSavedTime.value === -1) {
|
||||
// First time save: allow 0 or more
|
||||
// บันทึกครั้งแรก: ยอมรับ 0 หรือมากกว่า (First time save: allow 0 or more)
|
||||
if (maxSec < 0) return
|
||||
} else if (maxSec <= lastSavedTime.value) {
|
||||
// Subsequent saves: must be greater than last saved
|
||||
// การบันทึกครั้งถัดไป: ต้องมากกว่าครั้งล่าสุด (Subsequent saves: must be greater than last saved)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Throttle Check: Server Throttle (15 seconds)
|
||||
// 4. ตรวจสอบการหน่วงเวลา: เซิร์ฟเวอร์ (15 วินาที) (Throttle Check: Server Throttle (15 seconds))
|
||||
if (!force && (now - lastSavedTimestamp.value < 15000)) return
|
||||
|
||||
// Prepare for Save
|
||||
// เตรียมบันทึก (Prepare for Save)
|
||||
lastSavedTime.value = maxSec
|
||||
lastSavedTimestamp.value = now
|
||||
|
||||
// Check if this save might complete the lesson (e.g. 100% or forced end)
|
||||
// เช็คว่าการบันทึกนี้จะทำให้จบบทเรียนหรือไม่ (เช่น 100% หรือบังคับจบ) (Check if this save might complete the lesson)
|
||||
const isFinishing = force || (durationSec > 0 && maxSec >= durationSec)
|
||||
|
||||
if (isFinishing) {
|
||||
|
|
@ -503,8 +503,8 @@ const performSaveProgress = async (force: boolean = false, keepalive: boolean =
|
|||
try {
|
||||
const res = await saveVideoProgress(lesson.id, maxSec, durationSec, keepalive)
|
||||
|
||||
// Handle Completion (Frontend-only strategy: 95% threshold)
|
||||
// This ensures the checkmark appears at 95% to match backend.
|
||||
// จัดการเมื่อดูจบ (กลยุทธ์เฉพาะฝั่งหน้าเว็บ: ให้ผ่านที่ 95%) (Handle Completion (Frontend-only strategy: 95% threshold))
|
||||
// เพื่อให้เครื่องหมายถูกขึ้นที่ 95% ตรงกับหลังบ้าน (This ensures the checkmark appears at 95% to match backend.)
|
||||
const progressPercentage = durationSec > 0 ? (maxSec / durationSec) : 0
|
||||
const isCompletedNow = res.success && (res.data?.is_completed || progressPercentage >= 0.95)
|
||||
|
||||
|
|
@ -513,7 +513,7 @@ const performSaveProgress = async (force: boolean = false, keepalive: boolean =
|
|||
markLessonAsCompletedLocally(lesson.id)
|
||||
if (lesson.progress) lesson.progress.is_completed = true
|
||||
|
||||
// If newly completed, reload course data to unlock next lesson in sidebar
|
||||
// หากเพิ่งเรียนจบใหม่ ให้โหลดเนื้อหาใหม่เพื่อปลดล็อกบทถัดไป (If newly completed, reload course data to unlock next lesson in sidebar)
|
||||
if (!wasAlreadyCompleted) {
|
||||
await loadCourseData()
|
||||
}
|
||||
|
|
@ -527,13 +527,13 @@ const performSaveProgress = async (force: boolean = false, keepalive: boolean =
|
|||
}
|
||||
}
|
||||
|
||||
// Helper to update Sidebar UI
|
||||
// ฟังก์ชันช่วยเหลือสำหรับอัปเดตแถบด้านข้าง (Helper to update Sidebar UI)
|
||||
const markLessonAsCompletedLocally = (lessonId: number) => {
|
||||
if (courseData.value) {
|
||||
for (const chapter of courseData.value.chapters) {
|
||||
const lesson = chapter.lessons.find((l: any) => l.id === lessonId)
|
||||
if (lesson) {
|
||||
// Compatible with API structure
|
||||
// สอดคล้องกับโครงสร้าง API (Compatible with API structure)
|
||||
lesson.is_completed = true
|
||||
if (!lesson.progress) lesson.progress = {}
|
||||
lesson.progress.is_completed = true
|
||||
|
|
@ -547,11 +547,11 @@ const videoSrc = computed(() => {
|
|||
if (!currentLesson.value) return ''
|
||||
let url = ''
|
||||
|
||||
// Use explicit video_url from API first
|
||||
// ใช่ video_url โดยตรงจาก API ก่อน (Use explicit video_url from API first)
|
||||
if (currentLesson.value.video_url) {
|
||||
url = currentLesson.value.video_url
|
||||
} else {
|
||||
// Fallback (deprecated logic)
|
||||
// สำรอง (ตรรกะแบบเก่า)
|
||||
const content = getLocalizedText(currentLesson.value.content)
|
||||
if (content && (content.startsWith('http') || content.startsWith('/')) && !content.includes(' ')) {
|
||||
url = content
|
||||
|
|
@ -560,7 +560,7 @@ const videoSrc = computed(() => {
|
|||
|
||||
if (!url) return ''
|
||||
|
||||
// Support Resume for YouTube
|
||||
// รองรับการเล่นต่อสำหรับ YouTube (Support Resume for YouTube)
|
||||
const isYoutube = url.toLowerCase().includes('youtube.com') || url.toLowerCase().includes('youtu.be')
|
||||
if (isYoutube && initialSeekTime.value > 0) {
|
||||
const separator = url.includes('?') ? '&' : '?'
|
||||
|
|
@ -575,7 +575,7 @@ const onVideoEnded = async () => {
|
|||
const lesson = currentLesson.value
|
||||
if (!lesson) return
|
||||
|
||||
// Clear local storage on end since it's completed
|
||||
// ล้าง localStorage เนื่องจากดจบแล้ว (Clear local storage on end since it's completed)
|
||||
const key = getLocalProgressKey(lesson.id)
|
||||
if (key && typeof window !== 'undefined') {
|
||||
localStorage.removeItem(key)
|
||||
|
|
@ -598,7 +598,7 @@ onMounted(() => {
|
|||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// Clear state when leaving the page to ensure fresh start on return
|
||||
// ล้างสถานะเมื่อออกจากหน้าเพื่อให้หน้าเหมือนใหม่ตอนกลับมา (Clear state when leaving the page to ensure fresh start on return)
|
||||
courseData.value = null
|
||||
currentLesson.value = null
|
||||
})
|
||||
|
|
@ -665,7 +665,7 @@ onBeforeUnmount(() => {
|
|||
</q-toolbar>
|
||||
</q-header>
|
||||
|
||||
<!-- Sidebar (Curriculum) - Positioned Right via component prop -->
|
||||
<!-- แถบด้านข้าง (บทเรียน) - วางชิดขวาผ่านพร็อพพ์ -->
|
||||
<CurriculumSidebar
|
||||
v-model="sidebarOpen"
|
||||
:courseData="courseData"
|
||||
|
|
@ -676,14 +676,14 @@ onBeforeUnmount(() => {
|
|||
@open-announcements="handleOpenAnnouncements"
|
||||
/>
|
||||
|
||||
<!-- Main Content -->
|
||||
<!-- พื้นที่เนื้อหาหลัก (Main Content) -->
|
||||
<q-page-container class="bg-white dark:bg-slate-900">
|
||||
<q-page class="flex flex-col h-full bg-slate-50 dark:bg-[#0B0F1A]">
|
||||
<!-- Video Player & Content Area -->
|
||||
<!-- กรอบวิดีโอและพื้นที่เนื้อหา (Video Player & Content Area) -->
|
||||
<div class="w-full h-full p-4 md:p-6 flex-grow overflow-y-auto">
|
||||
<!-- 1. LOADING STATE (Comprehensive Skeleton) -->
|
||||
<!-- 1. สถานะกำลังโหลด (โครงสร้างเสมือน (Skeleton) สมบูรณ์แบบ) (LOADING STATE (Comprehensive Skeleton)) -->
|
||||
<div v-if="isLessonLoading" class="animate-fade-in">
|
||||
<!-- Video Skeleton -->
|
||||
<!-- โครงภาพวิดีโอ (Video Skeleton) -->
|
||||
<div class="aspect-video bg-slate-200 dark:bg-slate-800 rounded-3xl animate-pulse flex items-center justify-center mb-10 overflow-hidden relative shadow-xl focus:outline-none">
|
||||
<img
|
||||
v-if="courseData?.course?.thumbnail_url"
|
||||
|
|
@ -697,7 +697,7 @@ onBeforeUnmount(() => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Info Skeleton -->
|
||||
<!-- โครงข้อมูล (Info Skeleton) -->
|
||||
<div class="bg-white dark:bg-slate-800/50 p-8 rounded-3xl border border-slate-100 dark:border-white/5 shadow-sm">
|
||||
<div class="h-10 bg-slate-200 dark:bg-slate-800 rounded-xl w-3/4 mb-4 animate-pulse"></div>
|
||||
<div class="h-4 bg-slate-100 dark:bg-slate-800 rounded-lg w-full mb-2 animate-pulse"></div>
|
||||
|
|
@ -705,9 +705,9 @@ onBeforeUnmount(() => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 2. READY STATE (Real Lesson Content) -->
|
||||
<!-- 2. สถานะพร้อมใช้งาน (ข้อมูลบทเรียนจริง) (READY STATE (Real Lesson Content)) -->
|
||||
<div v-else-if="currentLesson" class="animate-fade-in">
|
||||
<!-- Video Player -->
|
||||
<!-- ส่วนการเล่นวิดีโอ (Video Player) -->
|
||||
<VideoPlayer
|
||||
v-if="videoSrc"
|
||||
ref="videoPlayerComp"
|
||||
|
|
@ -719,7 +719,7 @@ onBeforeUnmount(() => {
|
|||
@loadedmetadata="(d: number) => onVideoMetadataLoaded(d)"
|
||||
/>
|
||||
|
||||
<!-- Lesson Info -->
|
||||
<!-- ข้อมูลบทเรียน (Lesson Info) -->
|
||||
<div class="bg-[var(--bg-surface)] p-6 md:p-8 rounded-3xl shadow-sm border border-[var(--border-color)]">
|
||||
<!-- ใช้สีจากตัวแปรกลาง: จะแยกโหมดให้อัตโนมัติ (สว่าง=ดำ / มืด=ขาว) -->
|
||||
<div class="flex items-start justify-between gap-4 mb-4">
|
||||
|
|
@ -728,7 +728,7 @@ onBeforeUnmount(() => {
|
|||
|
||||
<p class="text-slate-600 dark:text-slate-400 text-base md:text-lg leading-relaxed mb-6" v-if="currentLesson.description">{{ getLocalizedText(currentLesson.description) }}</p>
|
||||
|
||||
<!-- Lesson Content Area (Text/HTML) -->
|
||||
<!-- ช่องบทเรียน (Text/HTML) (Lesson Content Area) -->
|
||||
<div v-if="currentLesson.type === 'QUIZ'" class="p-8 bg-gradient-to-br from-blue-50/50 to-indigo-50/50 dark:from-slate-800/50 dark:to-slate-900/50 rounded-2xl border border-blue-100 dark:border-white/5 text-center">
|
||||
<div class="bg-white dark:bg-slate-800 w-20 h-20 rounded-full flex items-center justify-center mx-auto mb-4 shadow-sm text-blue-500 dark:text-blue-400 border dark:border-white/10">
|
||||
<q-icon name="quiz" size="40px" />
|
||||
|
|
@ -783,7 +783,7 @@ onBeforeUnmount(() => {
|
|||
<div v-html="getLocalizedText(currentLesson.content)" class="leading-relaxed text-slate-800 dark:text-slate-200"></div>
|
||||
</div>
|
||||
|
||||
<!-- Attachments Section -->
|
||||
<!-- ส่วนเอกสารแนบ (Attachments Section) -->
|
||||
<div v-if="currentLesson.attachments && currentLesson.attachments.length > 0" class="mt-8 pt-6 border-t border-gray-100 dark:border-white/5">
|
||||
<h3 class="text-lg font-bold mb-4 text-slate-900 dark:text-white flex items-center gap-2">
|
||||
<div class="w-8 h-8 rounded-lg bg-orange-100 dark:bg-orange-900/30 text-orange-600 flex items-center justify-center">
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file quiz.vue
|
||||
* @description Quiz Interface.
|
||||
* Manages the entire quiz lifecycle: Start -> Taking -> Results -> Review.
|
||||
* Features a timer, question navigation, and detailed result analysis.
|
||||
* @description หน้าสำหรับทำแบบทดสอบ (Quiz Interface)
|
||||
* จัดการวงจรชีวิตของการทำแบบทดสอบทั้งหมด: เริ่มต้น -> ทำข้อสอบ -> ผลลัพธ์ -> ทบทวน
|
||||
* มีฟีเจอร์จับเวลา การนำทางระหว่างคำถาม และการวิเคราะห์ผลลัพธ์อย่างละเอียด
|
||||
*/
|
||||
|
||||
definePageMeta({
|
||||
|
|
@ -17,7 +17,7 @@ const router = useRouter()
|
|||
const $q = useQuasar()
|
||||
const { fetchCourseLearningInfo, fetchLessonContent, submitQuiz: apiSubmitQuiz, markLessonComplete } = useCourse()
|
||||
|
||||
// State Management
|
||||
// การจัดการสถานะ (State Management)
|
||||
const currentScreen = ref<'start' | 'taking' | 'result' | 'review'>('start')
|
||||
const timeLeft = ref(0)
|
||||
let timerInterval: ReturnType<typeof setInterval> | null = null
|
||||
|
|
@ -30,20 +30,24 @@ const quizData = ref<any>(null)
|
|||
const isLoading = ref(true)
|
||||
const isSubmitting = ref(false)
|
||||
|
||||
// Quiz Taking State
|
||||
// สถานะขณะทำแบบทดสอบ (Quiz Taking State)
|
||||
const currentQuestionIndex = ref(0)
|
||||
const userAnswers = ref<Record<number, number>>({}) // questionId -> choiceId
|
||||
const visitedQuestions = ref<Set<number>>(new Set()) // Track visited indices
|
||||
const userAnswers = ref<Record<number, number>>({}) // ID คำถาม -> ID คำตอบ (questionId -> choiceId)
|
||||
const visitedQuestions = ref<Set<number>>(new Set()) // ติดตามข้อที่เคยเปิดดูแล้ว (Track visited indices)
|
||||
const quizResult = ref<any>(null)
|
||||
|
||||
// Tracking visited questions
|
||||
const questionPageSize = 10
|
||||
const questionPage = ref(0)
|
||||
|
||||
// ติดตามคำถามที่เปิดดูแล้ว (Tracking visited questions)
|
||||
watch(currentQuestionIndex, (newVal) => {
|
||||
visitedQuestions.value.add(newVal)
|
||||
questionPage.value = Math.floor(newVal / questionPageSize)
|
||||
}, { immediate: true })
|
||||
|
||||
// Helper: Get Status Color Class
|
||||
// ฟังก์ชันช่วยเหลือ: ดึงคลาสสีสำหรับสถานะคำถาม (Helper: Get Status Color Class)
|
||||
const getQuestionStatusClass = (index: number, questionId: number) => {
|
||||
// 1. Current = Blue
|
||||
// 1. ข้อปัจจุบัน = สีฟ้า (Current = Blue)
|
||||
if (index === currentQuestionIndex.value) {
|
||||
return 'bg-blue-500 text-white border-blue-600 ring-2 ring-blue-200 dark:ring-blue-900'
|
||||
}
|
||||
|
|
@ -51,32 +55,29 @@ const getQuestionStatusClass = (index: number, questionId: number) => {
|
|||
const hasAnswer = userAnswers.value[questionId] !== undefined
|
||||
const isVisited = visitedQuestions.value.has(index)
|
||||
|
||||
// 2. Completed = Green
|
||||
// 2. ตอบแล้ว = สีเขียว (Completed = Green)
|
||||
if (hasAnswer) {
|
||||
return 'bg-emerald-500 text-white border-emerald-600'
|
||||
}
|
||||
|
||||
// 3. Skipped = Orange (Visited but no answer)
|
||||
// Note: If we are strictly following "Skipped" definition:
|
||||
// "user pressed Skip or moved forward on a skippable question without saving an answer"
|
||||
// In this linear flow, merely visiting and leaving empty counts as skipped.
|
||||
// 3. ข้าม = สีส้ม (เปิดดูแล้วแต่ยังไม่ตอบ) (Skipped = Orange (Visited but no answer))
|
||||
// หมายเหตุ: ตามคำนิยามของการข้าม หากคลิกแล้วหน้าเว็บไม่บันทึกข้อมูลจะถือว่าเป็นการข้าม
|
||||
// ในขั้นตอนนี้การดูเฉยๆ แล้วผ่านถือเป็นการข้ามเช่นกัน
|
||||
if (isVisited && !hasAnswer) {
|
||||
return 'bg-orange-500 text-white border-orange-600'
|
||||
}
|
||||
|
||||
// 4. Not Started = Grey
|
||||
// 4. ยังไม่เริ่ม = สีเทา (Not Started = Grey)
|
||||
return 'bg-slate-200 text-slate-400 border-slate-300 dark:bg-white/5 dark:border-white/5 dark:text-slate-600 hover:bg-slate-300 dark:hover:bg-white/10'
|
||||
}
|
||||
|
||||
const jumpToQuestion = (targetIndex: number) => {
|
||||
if (targetIndex === currentQuestionIndex.value) return
|
||||
|
||||
// Validation before leaving current (same logic as Next)
|
||||
// ตรวจสอบก่อนออกจากข้อปัจจุบัน (Validation before leaving current)
|
||||
if (targetIndex > currentQuestionIndex.value) {
|
||||
// If jumping forward, we must validate the CURRENT question requirements
|
||||
// unless we treat grid jumps as free navigation?
|
||||
// Req: "user cannot go Next until the question is answered and saved" (if not skippable).
|
||||
// So we must check restriction on the current spot before leaving.
|
||||
// หากข้ามไปข้างหน้า จะต้องตรวจสอบว่าข้อปัจจุบันทำไปถึงไหนแล้ว
|
||||
// ควรบังคับให้คลิกคำตอบก่อนจึงข้ามได้ (เงื่อนไขสำหรับคำถามที่ไม่ให้ข้าม)
|
||||
const isAnswered = userAnswers.value[currentQuestion.value.id] !== undefined
|
||||
const isSkippable = quizData.value?.is_skippable
|
||||
|
||||
|
|
@ -91,12 +92,35 @@ const jumpToQuestion = (targetIndex: number) => {
|
|||
}
|
||||
}
|
||||
|
||||
// If jumping backward? Usually allowed freely.
|
||||
// อนุญาตให้ย้อนกลับได้อย่างอิสระ (If jumping backward? Usually allowed freely.)
|
||||
|
||||
currentQuestionIndex.value = targetIndex
|
||||
}
|
||||
|
||||
// Computed
|
||||
const totalQuestionPages = computed(() => Math.ceil(totalQuestions.value / questionPageSize))
|
||||
|
||||
const visibleQuestions = computed(() => {
|
||||
if (!quizData.value?.questions) return []
|
||||
const start = questionPage.value * questionPageSize
|
||||
return quizData.value.questions.slice(start, start + questionPageSize).map((q: any, i: number) => ({
|
||||
...q,
|
||||
originalIndex: start + i
|
||||
}))
|
||||
})
|
||||
|
||||
const nextQuestionPage = () => {
|
||||
if (questionPage.value < totalQuestionPages.value - 1) {
|
||||
questionPage.value++
|
||||
}
|
||||
}
|
||||
|
||||
const prevQuestionPage = () => {
|
||||
if (questionPage.value > 0) {
|
||||
questionPage.value--
|
||||
}
|
||||
}
|
||||
|
||||
// ตัวแปรแบบ Computed (Computed Properties)
|
||||
const currentQuestion = computed(() => {
|
||||
if (!quizData.value || !quizData.value.questions) return null
|
||||
return quizData.value.questions[currentQuestionIndex.value]
|
||||
|
|
@ -116,7 +140,7 @@ const timerDisplay = computed(() => {
|
|||
return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`
|
||||
})
|
||||
|
||||
// Helper for localization
|
||||
// ฟังก์ชันช่วยเหลือสำหรับการแปลภาษา (Helper for localization)
|
||||
const getLocalizedText = (text: any) => {
|
||||
if (!text) return ''
|
||||
if (typeof text === 'string') return text
|
||||
|
|
@ -126,7 +150,7 @@ const getLocalizedText = (text: any) => {
|
|||
|
||||
const lessonProgress = ref<any>(null)
|
||||
|
||||
// Data Fetching
|
||||
// โหลดข้อมูล (Data Fetching)
|
||||
const loadData = async () => {
|
||||
isLoading.value = true
|
||||
try {
|
||||
|
|
@ -138,9 +162,9 @@ const loadData = async () => {
|
|||
if (courseId && lessonId) {
|
||||
const lessonRes = await fetchLessonContent(courseId, lessonId)
|
||||
if (lessonRes.success) {
|
||||
// Determine if data is directly the quiz or nested
|
||||
// กำหนดข้อมูลแบบทดสอบ (Determine if data is directly the quiz or nested)
|
||||
quizData.value = lessonRes.data.quiz || lessonRes.data
|
||||
lessonProgress.value = lessonRes.progress // Capture progress
|
||||
lessonProgress.value = lessonRes.progress // บันทึกความคืบหน้า (Capture progress)
|
||||
if (quizData.value?.time_limit) {
|
||||
timeLeft.value = quizData.value.time_limit * 60
|
||||
}
|
||||
|
|
@ -153,7 +177,7 @@ const loadData = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
// Helper for shuffling
|
||||
// ฟังก์ชันช่วยสุ่มเรียงลำดับอาร์เรย์ (Helper for shuffling)
|
||||
const shuffleArray = <T>(array: T[]): T[] => {
|
||||
return array
|
||||
.map(value => ({ value, sort: Math.random() }))
|
||||
|
|
@ -161,18 +185,18 @@ const shuffleArray = <T>(array: T[]): T[] => {
|
|||
.map(({ value }) => value)
|
||||
}
|
||||
|
||||
// Quiz Actions
|
||||
// การกระทำในแบบทดสอบ (Quiz Actions)
|
||||
const startQuiz = () => {
|
||||
// Deep copy to reset and apply shuffle
|
||||
// รีเซ็ตข้อมูลโดยคัดลอกใหม่เพื่อนำมาสุ่ม (Deep copy to reset and apply shuffle)
|
||||
const rawQuiz = JSON.parse(JSON.stringify(quizData.value))
|
||||
|
||||
if (rawQuiz) {
|
||||
// Shuffle Questions
|
||||
// สุ่มคำถาม (Shuffle Questions)
|
||||
if (rawQuiz.shuffle_questions && rawQuiz.questions) {
|
||||
rawQuiz.questions = shuffleArray(rawQuiz.questions)
|
||||
}
|
||||
|
||||
// Shuffle Choices
|
||||
// สุ่มตัวเลือกคำตอบ (Shuffle Choices)
|
||||
if (rawQuiz.shuffle_choices && rawQuiz.questions) {
|
||||
rawQuiz.questions.forEach((q: any) => {
|
||||
if (q.choices) {
|
||||
|
|
@ -180,7 +204,7 @@ const startQuiz = () => {
|
|||
}
|
||||
})
|
||||
}
|
||||
// Update state with shuffled data
|
||||
// อัปเดตข้อมูลให้เป็นแบบสุ่ม (Update state with shuffled data)
|
||||
quizData.value = rawQuiz
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +220,7 @@ const startQuiz = () => {
|
|||
}, 1000)
|
||||
}
|
||||
|
||||
// Mark first as visited
|
||||
// ทำเครื่องหมายข้อแรกว่าเปิดดูแล้ว (Mark first as visited)
|
||||
visitedQuestions.value = new Set([0])
|
||||
}
|
||||
|
||||
|
|
@ -209,12 +233,12 @@ const selectAnswer = (choiceId: number) => {
|
|||
const nextQuestion = () => {
|
||||
if (!currentQuestion.value) return
|
||||
|
||||
// Allow skip if quiz is skippable or question is answered
|
||||
// อนุญาตให้ข้ามได้หากโหมดข้ามเปิดอยู่ หรือ ตอบแล้ว (Allow skip if quiz is skippable or question is answered)
|
||||
const isAnswered = userAnswers.value[currentQuestion.value.id] !== undefined
|
||||
const isSkippable = quizData.value?.is_skippable
|
||||
|
||||
if (!isAnswered && !isSkippable) {
|
||||
// Show warning
|
||||
// แสดงข้อความเตือน (Show warning)
|
||||
$q.notify({
|
||||
type: 'warning',
|
||||
message: t('quiz.pleaseSelectAnswer', 'กรุณาเลือกคำตอบ'),
|
||||
|
|
@ -241,7 +265,7 @@ const retryQuiz = () => {
|
|||
}
|
||||
|
||||
const submitQuiz = async (auto = false) => {
|
||||
// 1. Manual Validation: Check if all questions are answered
|
||||
// 1. ตรวจสอบก่อนว่าทำครบทุกข้อหรือยัง (Manual Validation: Check if all questions are answered)
|
||||
if (!auto) {
|
||||
const answeredCount = Object.keys(userAnswers.value).length
|
||||
if (answeredCount < totalQuestions.value) {
|
||||
|
|
@ -254,7 +278,7 @@ const submitQuiz = async (auto = false) => {
|
|||
return
|
||||
}
|
||||
|
||||
// Premium Confirmation before submission
|
||||
// หน้าต่างยืนยันส่งข้อสอบแบบสวยงาม (Premium Confirmation before submission)
|
||||
$q.dialog({
|
||||
title: `<div class="text-slate-900 dark:text-white font-black text-xl">${t('quiz.warningTitle')}</div>`,
|
||||
message: `<div class="text-slate-600 dark:text-slate-300 text-base leading-relaxed mt-2">${t('quiz.submitConfirm')}</div>`,
|
||||
|
|
@ -285,33 +309,33 @@ const submitQuiz = async (auto = false) => {
|
|||
}
|
||||
|
||||
const processSubmitQuiz = async (auto = false) => {
|
||||
// 2. Start Submission Process
|
||||
// 2. เริ่มขั้นตอนการส่งข้อสอบ (Start Submission Process)
|
||||
if (timerInterval) clearInterval(timerInterval)
|
||||
|
||||
isSubmitting.value = true
|
||||
currentScreen.value = 'result' // Switch to result screen to show progress
|
||||
currentScreen.value = 'result' // เปลี่ยนหน้าไปที่หน้าสรุปผล (Switch to result screen to show progress)
|
||||
|
||||
try {
|
||||
// Prepare Payload
|
||||
// เตรียมข้อมูลยิง API (Prepare Payload)
|
||||
const answersPayload = Object.entries(userAnswers.value).map(([qId, cId]) => ({
|
||||
question_id: Number(qId),
|
||||
choice_id: cId
|
||||
}))
|
||||
|
||||
// Check if already passed
|
||||
// ตรวจสอบว่าเคยผ่านแล้วหรือไม่ (Check if already passed)
|
||||
const alreadyPassed = lessonProgress.value?.is_passed || lessonProgress.value?.is_completed || false
|
||||
|
||||
// Call API
|
||||
// เรียก API (Call API)
|
||||
const res = await apiSubmitQuiz(courseId, lessonId, answersPayload, alreadyPassed)
|
||||
|
||||
if (res.success && res.data) {
|
||||
quizResult.value = res.data
|
||||
// Update local progress if passed and not previously passed
|
||||
// อัปเดตข้อมูลบนเว็บหากผ่านแบบทดสอบ (Update local progress if passed and not previously passed)
|
||||
if (res.data.is_passed && !alreadyPassed) {
|
||||
if (lessonProgress.value) lessonProgress.value.is_passed = true
|
||||
}
|
||||
} else {
|
||||
// Fallback error handling
|
||||
// การจัดการเมื่อเกิดข้อผิดพลาดฉุกเฉิน (Fallback error handling)
|
||||
$q.notify({
|
||||
type: 'negative',
|
||||
message: res.error || 'Failed to submit quiz'
|
||||
|
|
@ -364,14 +388,14 @@ const reviewQuiz = () => {
|
|||
currentScreen.value = 'review'
|
||||
}
|
||||
|
||||
// Helper to get choice label (A, B, C...)
|
||||
// เปลี่ยน ID เป็นตัวอักษรเพื่อความสวยงาม (A, B, C...) (Helper to get choice label (A, B, C...))
|
||||
const getChoiceLabel = (index: number) => {
|
||||
return String.fromCharCode(65 + index) // 65 is 'A'
|
||||
}
|
||||
|
||||
const getCorrectChoiceId = (questionId: number) => {
|
||||
if (!quizResult.value?.answers_review) return null
|
||||
// Type checking for safety
|
||||
// เช็คข้อมูลก่อนพัง (Type checking for safety)
|
||||
const review = Array.isArray(quizResult.value.answers_review)
|
||||
? quizResult.value.answers_review.find((r: any) => r.question_id === questionId)
|
||||
: null
|
||||
|
|
@ -384,7 +408,7 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
<q-page-container>
|
||||
<q-page>
|
||||
<div class="quiz-shell min-h-screen bg-slate-50 dark:bg-[#0b0f1a] text-slate-900 dark:text-slate-200 antialiased selection:bg-blue-500/20 transition-colors">
|
||||
<!-- Header -->
|
||||
<!-- ส่วนหัว (Header) -->
|
||||
<header class="h-14 bg-white dark:!bg-[var(--bg-surface)] fixed top-0 inset-x-0 z-[100] flex items-center px-6 border-b border-slate-200 dark:border-white/5 transition-colors">
|
||||
<div class="flex items-center w-full justify-between">
|
||||
<div class="flex items-center">
|
||||
|
|
@ -410,7 +434,7 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Main Content Area -->
|
||||
<!-- พื้นที่เนื้อหาหลัก (Main Content Area) -->
|
||||
<main class="pt-14 h-screen flex items-center justify-center overflow-y-auto px-4 custom-scrollbar">
|
||||
|
||||
<div v-if="isLoading" class="flex flex-col items-center gap-4">
|
||||
|
|
@ -435,9 +459,9 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
</div>
|
||||
|
||||
<template v-else>
|
||||
<!-- 1. START SCREEN -->
|
||||
<!-- 1. หน้าเริ่มต้น (START SCREEN) -->
|
||||
<div v-if="currentScreen === 'start'" class="w-full max-w-[640px] animate-fade-in py-12">
|
||||
<!-- ... (Start Screen is unchanged but needs to be here for context) ... -->
|
||||
<!-- ... (หน้าแรกยังคงเหมือนเดิม แปะไว้เป็น reference) ... -->
|
||||
<div class="bg-white dark:!bg-[#1e293b] border border-slate-200 dark:border-white/5 rounded-[32px] p-8 md:p-14 shadow-lg dark:shadow-2xl relative overflow-hidden transition-colors">
|
||||
|
||||
<div class="flex justify-center mb-10">
|
||||
|
|
@ -459,7 +483,7 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Instruction Box -->
|
||||
<!-- กล่องคำแนะนำ (Instruction Box) -->
|
||||
<div class="bg-slate-50 dark:bg-[#0b121f]/80 p-8 rounded-3xl mb-8 border border-slate-100 dark:border-white/5">
|
||||
<h3 class="text-[12px] font-black text-slate-500 dark:text-slate-400 mb-6 uppercase tracking-[0.2em] flex items-center gap-2">
|
||||
{{ $t('quiz.instructionTitle') }}
|
||||
|
|
@ -483,35 +507,58 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 2. TAKING SCREEN -->
|
||||
<!-- 2. TAKING SCREEN -->
|
||||
<!-- 2. หน้าทำแบบทดสอบ (TAKING SCREEN) -->
|
||||
<div v-if="currentScreen === 'taking'" class="w-full max-w-[840px] animate-fade-in py-12">
|
||||
<div v-if="currentQuestion" class="bg-white dark:!bg-[#1e293b] border border-slate-200 dark:border-white/5 rounded-[32px] p-8 md:p-12 shadow-xl relative overflow-hidden">
|
||||
|
||||
<!-- Progress Bar -->
|
||||
<!-- แถบความคืบหน้า (Progress Bar) -->
|
||||
<div class="absolute top-0 left-0 right-0 h-1.5 bg-slate-100 dark:bg-white/5">
|
||||
<div class="h-full bg-blue-500 transition-all duration-300" :style="{ width: ((currentQuestionIndex + 1) / totalQuestions) * 100 + '%' }"></div>
|
||||
</div>
|
||||
|
||||
<!-- Question Map / Pagination -->
|
||||
<div class="flex flex-wrap gap-2 mb-8 mt-4">
|
||||
<button
|
||||
v-for="(q, idx) in quizData?.questions"
|
||||
:key="q.id"
|
||||
@click="jumpToQuestion(Number(idx))"
|
||||
class="w-8 h-8 md:w-10 md:h-10 rounded-lg flex items-center justify-center text-xs md:text-sm font-bold transition-all border"
|
||||
:class="getQuestionStatusClass(Number(idx), q.id)"
|
||||
<!-- แผนที่คำถาม / การเปลี่ยนหน้า (Question Map / Pagination) -->
|
||||
<div class="flex items-center justify-center gap-2 mb-8 mt-4 select-none bg-slate-50 dark:bg-[#0b121f]/50 p-2 rounded-2xl border border-slate-100 dark:border-white/5 w-fit mx-auto">
|
||||
<!-- ปุ่มย้อนกลับ (หน้าก่อนหน้า) -->
|
||||
<button
|
||||
v-if="totalQuestionPages > 1"
|
||||
@click="prevQuestionPage"
|
||||
:disabled="questionPage === 0"
|
||||
class="w-8 h-8 md:w-10 md:h-10 rounded-lg flex items-center justify-center transition-all flex-shrink-0"
|
||||
:class="questionPage === 0 ? 'text-slate-300 dark:text-slate-600 bg-transparent cursor-not-allowed' : 'text-slate-600 dark:text-slate-300 bg-white dark:bg-[#1e293b] hover:bg-slate-200 dark:hover:bg-white/10 shadow-sm border border-slate-200 dark:border-white/10 text-lg hover:-translate-x-0.5'"
|
||||
>
|
||||
{{ Number(idx) + 1 }}
|
||||
<q-icon name="chevron_left" />
|
||||
</button>
|
||||
|
||||
<div class="flex flex-wrap items-center justify-center gap-2">
|
||||
<button
|
||||
v-for="q in visibleQuestions"
|
||||
:key="q.id"
|
||||
@click="jumpToQuestion(q.originalIndex)"
|
||||
class="w-8 h-8 md:w-10 md:h-10 rounded-lg flex items-center justify-center text-xs md:text-sm font-bold transition-all border"
|
||||
:class="getQuestionStatusClass(q.originalIndex, q.id)"
|
||||
>
|
||||
{{ q.originalIndex + 1 }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- ปุ่มถัดไป (หน้าถัดไป) -->
|
||||
<button
|
||||
v-if="totalQuestionPages > 1"
|
||||
@click="nextQuestionPage"
|
||||
:disabled="questionPage === totalQuestionPages - 1"
|
||||
class="w-8 h-8 md:w-10 md:h-10 rounded-lg flex items-center justify-center transition-all flex-shrink-0"
|
||||
:class="questionPage === totalQuestionPages - 1 ? 'text-slate-300 dark:text-slate-600 bg-slate-100 dark:bg-white/5 cursor-not-allowed' : 'text-slate-600 dark:text-slate-300 bg-white dark:bg-[#1e293b] hover:bg-slate-100 dark:hover:bg-white/10 shadow-sm border border-slate-200 dark:border-white/10 text-lg hover:translate-x-0.5'"
|
||||
>
|
||||
<q-icon name="chevron_right" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Question Title -->
|
||||
<!-- ชื่อคำถาม (Question Title) -->
|
||||
<h3 class="text-xl md:text-2xl font-bold text-slate-900 dark:text-white mb-10 leading-relaxed">
|
||||
{{ getLocalizedText(currentQuestion.question) }}
|
||||
</h3>
|
||||
|
||||
<!-- Choices -->
|
||||
<!-- ส่วนการเลือกคำตอบ (Choices) -->
|
||||
<div class="flex flex-col gap-4 mb-12">
|
||||
<button
|
||||
v-for="choice in currentQuestion.choices"
|
||||
|
|
@ -533,7 +580,7 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
|
||||
|
||||
|
||||
<!-- Controls -->
|
||||
<!-- ปุ่มควบคุมต่างๆ (Controls) -->
|
||||
<div class="flex justify-between items-center pt-8 border-t border-slate-100 dark:border-white/5">
|
||||
<button
|
||||
@click="prevQuestion"
|
||||
|
|
@ -563,7 +610,7 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
|
||||
|
||||
|
||||
<!-- 3. RESULT SCREEN -->
|
||||
<!-- 3. หน้าผลลัพธ์การทำแบบทดสอบ (RESULT SCREEN) -->
|
||||
<div v-if="currentScreen === 'result'" class="w-full max-w-[640px] animate-fade-in py-12">
|
||||
<div class="bg-white dark:!bg-[#1e293b] border border-slate-200 dark:border-white/5 rounded-[40px] p-10 shadow-2xl text-center relative overflow-hidden">
|
||||
|
||||
|
|
@ -586,7 +633,7 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Score Card -->
|
||||
<!-- บัตรแสดงคะแนน (Score Card) -->
|
||||
<div class="bg-slate-50 dark:bg-[#0b121f] rounded-3xl p-6 mb-8 flex items-center justify-around border border-slate-100 dark:border-white/5">
|
||||
<div class="text-center">
|
||||
<div class="text-xs font-black text-slate-400 uppercase tracking-widest mb-1">{{ $t('quiz.scoreLabel') }}</div>
|
||||
|
|
@ -626,7 +673,7 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 4. REVIEW SCREEN -->
|
||||
<!-- 4. หน้าทบทวนข้อสอบ (REVIEW SCREEN) -->
|
||||
<div v-if="currentScreen === 'review'" class="w-full max-w-[840px] animate-fade-in py-12 pb-24">
|
||||
<div class="space-y-6">
|
||||
<div
|
||||
|
|
@ -652,7 +699,7 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
'border-slate-100 dark:border-white/5 opacity-80 dark:opacity-40': userAnswers[question.id] !== choice.id && choice.id !== getCorrectChoiceId(question.id)
|
||||
}"
|
||||
>
|
||||
<!-- Indicator Icon -->
|
||||
<!-- ไอคอนสถานะ (Indicator Icon) -->
|
||||
<div
|
||||
class="w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 font-bold text-sm border-2"
|
||||
:class="{
|
||||
|
|
@ -668,7 +715,7 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
|
||||
<span class="font-medium text-slate-700 dark:text-slate-300">{{ getLocalizedText(choice.text) }}</span>
|
||||
|
||||
<!-- Label Badge -->
|
||||
<!-- ป้ายแสดงสถานะ (Label Badge) -->
|
||||
<div v-if="choice.id === getCorrectChoiceId(question.id)" class="ml-auto px-2 py-0.5 bg-emerald-100 dark:bg-emerald-500/20 text-emerald-700 dark:text-emerald-300 text-xs font-bold rounded uppercase tracking-wider">
|
||||
{{ $t('quiz.correctLabel', 'Correct') }}
|
||||
</div>
|
||||
|
|
@ -695,11 +742,11 @@ const getCorrectChoiceId = (questionId: number) => {
|
|||
</main>
|
||||
|
||||
|
||||
</div> <!-- Close quiz-shell -->
|
||||
</div> <!-- ปิดส่วนเปลือกข้อสอบ (Close quiz-shell) -->
|
||||
|
||||
|
||||
<!-- Question Navigator Sidebar/Floating (Desktop) - Outside Main Flow -->
|
||||
<!-- Using QPageSticky properly inside q-page/q-layout context we added -->
|
||||
<!-- ป๊อปอัปแผนที่คำถาม (เดสก์ท็อป) - อยู่นอกพื้นที่ทำงานปกติ (Question Navigator Sidebar/Floating (Desktop) - Outside Main Flow) -->
|
||||
<!-- ใช้งาน QPageSticky ให้ถูกที่ (Using QPageSticky properly inside q-page/q-layout context we added) -->
|
||||
<q-page-sticky
|
||||
v-if="false"
|
||||
position="top-right"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file [id].vue
|
||||
* @description Dynamic Course Detail Page.
|
||||
* Displays detailed information about a specific course based on the ID.
|
||||
* @description หน้าแสดงรายละเอียดคอร์ส (Dynamic Course Detail Page)
|
||||
* ดึงข้อมูลคอร์สเรียนตาม ID ที่ส่งมาใน URL และมีปุ่มสำหรับចុះทะเบียน
|
||||
*/
|
||||
|
||||
definePageMeta({
|
||||
|
|
@ -114,7 +114,7 @@ useHead({
|
|||
/>
|
||||
</div>
|
||||
|
||||
<!-- Loading / Error State -->
|
||||
<!-- ส่วนแสดงผลขณะโหลดข้อมูลหรือเกิดข้อผิดพลาด (Loading / Error State) -->
|
||||
<div v-else class="text-center py-20">
|
||||
<div v-if="error" class="text-red-500 mb-4">
|
||||
<p class="font-bold">เกิดข้อผิดพลาดในการโหลดข้อมูล</p>
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file announcements.vue
|
||||
* @description Page displaying system and course-related announcements.
|
||||
* Uses the default layout and requires authentication.
|
||||
* @description หน้าแสดงประกาศระบบและข่าวสารเกี่ยวกับคอร์สเรียน (Page displaying system and course-related announcements.)
|
||||
* ใช้เลย์เอาต์เริ่มต้นและต้องตรวจสอบสิทธิ์ (Uses the default layout and requires authentication.)
|
||||
*/
|
||||
|
||||
// Define page metadata: usage of 'default' layout and 'auth' middleware
|
||||
// ข้อมูล metadata ของหน้า: ใช้เลย์เอาต์ 'default' และระบบตรวจสอบสิทธิ์ 'auth' (Define page metadata: usage of 'default' layout and 'auth' middleware)
|
||||
definePageMeta({
|
||||
layout: 'default',
|
||||
middleware: 'auth'
|
||||
})
|
||||
|
||||
// Set page title for SEO
|
||||
// กำหนดชื่อหัวหน้าเว็บสำหรับ SEO (Set page title for SEO)
|
||||
useHead({
|
||||
title: 'ประกาศ - e-Learning'
|
||||
})
|
||||
|
|
@ -19,22 +19,22 @@ useHead({
|
|||
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<!-- Page Header -->
|
||||
<!-- ส่วนหัวหน้าเว็บ (Page Header) -->
|
||||
<h1 class="text-3xl font-black mb-10 text-slate-900 dark:text-white">ประกาศ</h1>
|
||||
|
||||
<!--
|
||||
Main Layout: 12-column Grid
|
||||
- Left Column (span-8): Main announcements content
|
||||
- Right Column (span-4): Categories/Filter sidebar
|
||||
โครงสร้างหลัก: กริด 12 คอลัมน์ (Main Layout: 12-column Grid)
|
||||
- คอลัมน์ซ้าย (span-8): เนื้อหาประกาศหลัก (Left Column: Main announcements content)
|
||||
- คอลัมน์ขวา (span-4): แถบหมวดหมู่/ตัวกรอง (Right Column: Categories/Filter sidebar)
|
||||
-->
|
||||
<div class="grid-12">
|
||||
|
||||
<!-- ==========================================
|
||||
MAIN CONTENT AREA (Left)
|
||||
พื้นที่เนื้อหาหลัก (ด้านซ้าย) (MAIN CONTENT AREA (Left))
|
||||
========================================== -->
|
||||
<div class="col-span-8">
|
||||
|
||||
<!-- Feature 1: Critical System Announcement -->
|
||||
<!-- หน้าที่ 1: ประกาศระบบสำคัญ (Feature 1: Critical System Announcement) -->
|
||||
<div class="card mb-6">
|
||||
<div class="flex items-center gap-2 mb-2">
|
||||
<span class="status-pill status-warning">สำคัญ</span>
|
||||
|
|
@ -42,13 +42,13 @@ useHead({
|
|||
</div>
|
||||
<h2 class="text-xl font-bold mb-4 text-slate-900 dark:text-white">แจ้งปิดปรับปรุงระบบ</h2>
|
||||
<p class="mb-4">เราจะทำการปิดปรับปรุงระบบในวันที่ 25 ธ.ค. เวลา 02:00 - 04:00 น. ขออภัยในความไม่สะดวก</p>
|
||||
<!-- Attachment Block -->
|
||||
<!-- ส่วนแนบไฟล์ (Attachment Block) -->
|
||||
<div class="flex items-center gap-2 p-3 rounded" style="background: var(--neutral-50); border: 1px solid var(--border-color); width: fit-content;">
|
||||
<span>📎</span> <span class="text-sm font-bold">ตารางการปิดปรับปรุง.pdf</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Announcement: UX/UI Course Update -->
|
||||
<!-- ประกาศ: อัปเดตคอร์ส UX/UI (Announcement: UX/UI Course Update) -->
|
||||
<div class="card mb-4" style="border-left: 4px solid var(--primary);">
|
||||
<div class="flex justify-between items-start mb-2" style="flex-wrap: wrap; gap: 8px;">
|
||||
<div>
|
||||
|
|
@ -61,7 +61,7 @@ useHead({
|
|||
<NuxtLink to="/browse/discovery" class="text-sm" style="color: var(--primary);">ดูรายละเอียดคอร์ส</NuxtLink>
|
||||
</div>
|
||||
|
||||
<!-- Announcement: Accessibility (WCAG) Material -->
|
||||
<!-- ประกาศ: เอกสารประกอบการเรียนด้านการเข้าถึงเว็บ (WCAG) (Announcement: Accessibility (WCAG) Material) -->
|
||||
<div class="card mb-4" style="border-left: 4px solid var(--success);">
|
||||
<div class="flex justify-between items-start mb-2" style="flex-wrap: wrap; gap: 8px;">
|
||||
<div>
|
||||
|
|
@ -71,13 +71,13 @@ useHead({
|
|||
<span class="text-sm text-slate-600 dark:text-slate-400">22 ธ.ค. 2024</span>
|
||||
</div>
|
||||
<p class="text-slate-700 dark:text-slate-300 mb-2">เราได้เพิ่มไฟล์ PDF สรุปเกณฑ์ WCAG 2.2 ในส่วนของเอกสารประกอบการเรียนแล้ว...</p>
|
||||
<!-- Small Attachment -->
|
||||
<!-- ไฟล์แนบแบบเล็ก (Small Attachment) -->
|
||||
<div class="flex items-center gap-2 p-2 rounded mt-2" style="background: var(--neutral-50); border: 1px dotted var(--border-color); width: fit-content;">
|
||||
<span>📄</span> <span class="text-xs">WCAG_2.2_Summary.pdf</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Announcement: React Course Update -->
|
||||
<!-- ประกาศ: อัปเดตคอร์ส React (Announcement: React Course Update) -->
|
||||
<div class="card mb-4" style="border-left: 4px solid var(--warning);">
|
||||
<div class="flex justify-between items-start mb-2" style="flex-wrap: wrap; gap: 8px;">
|
||||
<div>
|
||||
|
|
@ -90,7 +90,7 @@ useHead({
|
|||
<NuxtLink to="/classroom/learning" class="btn btn-secondary text-sm" style="width: fit-content;">เข้าสู่บทเรียน</NuxtLink>
|
||||
</div>
|
||||
|
||||
<!-- Announcement: General New Course -->
|
||||
<!-- ประกาศ: คอร์สใหม่ทั่วไป (Announcement: General New Course) -->
|
||||
<div class="card mb-4">
|
||||
<div class="flex justify-between items-start mb-2" style="flex-wrap: wrap; gap: 8px;">
|
||||
<h3 class="font-bold text-slate-900 dark:text-white">คอร์สใหม่: Advanced Python</h3>
|
||||
|
|
@ -100,7 +100,7 @@ useHead({
|
|||
<a href="#" class="text-sm" style="color: var(--primary);">อ่านเพิ่มเติม</a>
|
||||
</div>
|
||||
|
||||
<!-- Announcement: Platform Update -->
|
||||
<!-- ประกาศ: อัปเดตแพลตฟอร์ม (Announcement: Platform Update) -->
|
||||
<div class="card mb-4">
|
||||
<div class="flex justify-between items-start mb-2" style="flex-wrap: wrap; gap: 8px;">
|
||||
<h3 class="font-bold text-slate-900 dark:text-white">ยินดีต้อนรับสู่ดีไซน์ใหม่!</h3>
|
||||
|
|
@ -112,24 +112,24 @@ useHead({
|
|||
</div>
|
||||
|
||||
<!-- ==========================================
|
||||
SIDEBAR (Right)
|
||||
Category Filters
|
||||
แถบด้านข้าง (ด้านขวา) (SIDEBAR (Right))
|
||||
ตัวกรองหมวดหมู่ (Category Filters)
|
||||
========================================== -->
|
||||
<div class="col-span-4">
|
||||
<div class="card">
|
||||
<h3 class="font-bold mb-4 text-slate-900 dark:text-white">หมวดหมู่</h3>
|
||||
<ul class="flex flex-col gap-2">
|
||||
<!-- Filter Option: All -->
|
||||
<!-- ตัวเลือกตัวกรอง: ทั้งหมด (Filter Option: All) -->
|
||||
<li class="flex justify-between items-center p-2 rounded cursor-pointer" style="background: var(--neutral-50);">
|
||||
<span>ทั้งหมด</span>
|
||||
<span class="text-muted">15</span>
|
||||
</li>
|
||||
<!-- Filter Option: System Updates -->
|
||||
<!-- ตัวเลือกตัวกรอง: อัปเดตระบบ (Filter Option: System Updates) -->
|
||||
<li class="flex justify-between items-center p-2 rounded cursor-pointer">
|
||||
<span>อัปเดตระบบ</span>
|
||||
<span class="text-muted">3</span>
|
||||
</li>
|
||||
<!-- Filter Option: Course News -->
|
||||
<!-- ตัวเลือกตัวกรอง: ข่าวสารคอร์ส (Filter Option: Course News) -->
|
||||
<li class="flex justify-between items-center p-2 rounded cursor-pointer">
|
||||
<span>ข่าวสารคอร์ส</span>
|
||||
<span class="text-muted">11</span>
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ const navigateToCategory = (catName: string) => {
|
|||
<div class="bg-[#F8F9FA] dark:bg-[#020617] min-h-screen font-inter p-4 md:p-8 transition-colors duration-300">
|
||||
<div class="max-w-[1400px] mx-auto grid grid-cols-1 xl:grid-cols-3 gap-8">
|
||||
|
||||
<!-- Left Column (Main Content) -->
|
||||
<!-- คอลัมน์ซ้าย (เนื้อหาหลัก) -->
|
||||
<div class="xl:col-span-2 space-y-6">
|
||||
|
||||
<!-- ป้ายต้อนรับ (Welcome Banner) -->
|
||||
|
|
@ -179,7 +179,7 @@ const navigateToCategory = (catName: string) => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Continue Learning (เรียนต่อจากครั้งก่อน) -->
|
||||
<!-- ส่วนเรียนต่อจากครั้งก่อน (Continue Learning) -->
|
||||
<div class="bg-white dark:!bg-slate-900 rounded-[2rem] p-6 md:p-8 shadow-sm border border-slate-100 dark:border-slate-800 transition-colors">
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h2 class="text-[1.35rem] font-bold text-slate-900 dark:text-white tracking-tight">{{ $t('dashboard.continueLearningTitle') }}</h2>
|
||||
|
|
@ -195,7 +195,7 @@ const navigateToCategory = (catName: string) => {
|
|||
|
||||
<div class="flex-1 w-full flex flex-col">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<!-- Category Badge -->
|
||||
<!-- ป้ายบอกหมวดหมู่ (Category Badge) -->
|
||||
<div v-if="heroCourse.category">
|
||||
<span class="bg-[#E9EFFD] dark:bg-blue-900/40 text-[#3B6BE8] dark:text-blue-400 px-3 py-1 rounded-full text-[11px] font-bold tracking-wide">{{ getLocalizedText(heroCourse.category) }}</span>
|
||||
</div>
|
||||
|
|
@ -208,7 +208,7 @@ const navigateToCategory = (catName: string) => {
|
|||
<h3 class="text-2xl font-bold text-slate-900 dark:text-white mb-2 leading-snug line-clamp-2">
|
||||
{{ getLocalizedText(heroCourse.title) || 'Advanced UI/UX Design มาสเตอร์คลาส' }}
|
||||
</h3>
|
||||
<!-- Removed Lesson Title/Number as per request -->
|
||||
<!-- ไม่แสดงเลขบทเรียนตามที่ได้รับคำขอมา (Removed Lesson Title/Number as per request) -->
|
||||
|
||||
<div class="mb-6 mt-4">
|
||||
<div class="flex justify-between text-[13px] font-bold mb-2">
|
||||
|
|
@ -245,11 +245,11 @@ const navigateToCategory = (catName: string) => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right Column (Sidebar/Profile Content) -->
|
||||
<!-- คอลัมน์ขวา (แถบข้อมูลโปรไฟล์และคอร์สแนะนำ) -->
|
||||
<div class="xl:col-span-1 space-y-6">
|
||||
<!-- Profile Widget -->
|
||||
<!-- วิดเจ็ตโปรไฟล์ผู้ใช้ -->
|
||||
<div class="bg-white dark:!bg-slate-900 rounded-[2rem] p-8 shadow-sm border border-slate-100 dark:border-slate-800 text-center flex flex-col items-center relative overflow-hidden transition-colors">
|
||||
<!-- decorative bg -->
|
||||
<!-- พื้นหลังตกแต่ง (decorative bg) -->
|
||||
<div class="absolute top-0 left-0 right-0 h-24 bg-gradient-to-b from-[#F8FAFC] to-white dark:from-slate-800 dark:to-slate-900"></div>
|
||||
|
||||
<div class="relative z-10 w-24 h-24 rounded-full bg-white dark:bg-slate-800 mb-4 shadow-md flex items-center justify-center">
|
||||
|
|
@ -270,28 +270,28 @@ const navigateToCategory = (catName: string) => {
|
|||
|
||||
<div class="flex w-full gap-3 mt-7 relative z-10 px-2">
|
||||
<div class="flex-1 bg-[#F8FAFC] dark:bg-slate-800 rounded-2xl p-3.5 flex flex-col items-center justify-center transition-colors shadow-sm">
|
||||
<span class="text-[1.35rem] font-black text-[#3B6BE8] dark:text-blue-400 mb-1 leading-none">{{ String(enrolledCourses.length || 0).padStart(2, '0') }}</span>
|
||||
<span class="text-slate-400 text-[10px] font-bold tracking-wider">{{ $t('myCourses.filterProgress') }}</span>
|
||||
<span class="text-[1.35rem] font-black text-[#3B6BE8] dark:text-blue-400 mb-1 leading-none">{{ enrolledCourses.length || 0 }}</span>
|
||||
<span class="text-slate-400 text-[10px] font-bold tracking-wider">{{ $t('sidebar.onlineCourses') }}</span>
|
||||
</div>
|
||||
<div class="flex-1 bg-[#F8FAFC] dark:bg-slate-800 rounded-2xl p-3.5 flex flex-col items-center justify-center transition-colors shadow-sm">
|
||||
<span class="text-[1.35rem] font-black text-[#10B981] dark:text-emerald-400 mb-1 leading-none z-10">{{ String(enrolledCourses.filter(c => c.progress >= 100).length || 0).padStart(2, '0') }}</span>
|
||||
<span class="text-[1.35rem] font-black text-[#10B981] dark:text-emerald-400 mb-1 leading-none z-10">{{ enrolledCourses.filter(c => c.progress >= 100).length || 0 }}</span>
|
||||
<span class="text-slate-400 text-[10px] font-bold tracking-wider z-10">{{ $t('myCourses.filterCompleted') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Recommended Courses Widget -->
|
||||
<!-- วิดเจ็ตคอร์สแนะนำ -->
|
||||
<div v-if="recommendedCourses.length > 0" class="bg-white dark:!bg-slate-900 rounded-[2rem] p-6 shadow-sm border border-slate-100 dark:border-slate-800 transition-colors">
|
||||
<h2 class="text-[1.1rem] font-bold text-slate-900 dark:text-white mb-5 tracking-tight flex items-center justify-between">
|
||||
{{ $t('dashboard.recommendedCourses') }}
|
||||
</h2>
|
||||
<div class="flex flex-col gap-5">
|
||||
<div v-for="course in recommendedCourses.slice(0, 3)" :key="course.id" class="flex gap-4 group cursor-pointer transition-all" @click="navigateTo(`/browse/discovery?course_id=${course.id}`)">
|
||||
<!-- Thumbnail -->
|
||||
<!-- รูปหน้าปก (Thumbnail) -->
|
||||
<div class="w-24 h-[68px] rounded-xl overflow-hidden bg-slate-100 shrink-0 relative shadow-sm">
|
||||
<img :src="course.image" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500" />
|
||||
</div>
|
||||
<!-- Info -->
|
||||
<!-- ข้อมูลคอร์ส (Info) -->
|
||||
<div class="flex-1 flex flex-col justify-center min-w-0">
|
||||
<h3 class="font-bold text-[13px] text-slate-900 dark:text-white leading-snug line-clamp-2 mb-1.5 group-hover:text-[#3B6BE8] transition-colors pr-1">{{ getLocalizedText(course.title) }}</h3>
|
||||
<div class="flex items-center justify-between mt-auto">
|
||||
|
|
|
|||
|
|
@ -171,17 +171,17 @@ onMounted(() => {
|
|||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
<div v-for="course in inProgressCourses.slice(0, 2)" :key="course.id" class="border border-slate-100 dark:border-slate-800 rounded-3xl p-4 flex flex-col sm:flex-row gap-5 items-center bg-[#F8FAFC] dark:bg-slate-800/50 hover:border-blue-100 dark:hover:border-blue-900/50 transition-colors">
|
||||
<!-- Image -->
|
||||
<!-- ส่วนรูปภาพหน้าปก (Image) -->
|
||||
<div class="w-full sm:w-[160px] h-[120px] rounded-[1.25rem] overflow-hidden bg-slate-200 shrink-0 relative group">
|
||||
<img :src="course.thumbnail_url" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"/>
|
||||
<!-- Quick play overlay -->
|
||||
<!-- เลเยอร์เล่นวิดีโอด่วน (Quick play overlay) -->
|
||||
<div @click="navigateTo(`/classroom/learning?course_id=${course.id}`)" class="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center cursor-pointer">
|
||||
<div class="bg-white/30 backdrop-blur-md rounded-full w-10 h-10 flex flex-col items-center justify-center">
|
||||
<q-icon name="play_arrow" color="white" size="20px" class="ml-0.5" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Info -->
|
||||
<!-- ส่วนข้อมูลเนื้อหา (Info) -->
|
||||
<div class="flex-1 flex flex-col justify-center min-w-0 py-1 w-full">
|
||||
<div class="mb-2" v-if="course.category_name">
|
||||
<span class="bg-[#E9EFFD] dark:bg-blue-900/40 text-[#3B6BE8] dark:text-blue-400 px-3.5 py-1.5 rounded-full text-[10px] font-bold tracking-wide">{{ course.category_name }}</span>
|
||||
|
|
@ -249,19 +249,19 @@ onMounted(() => {
|
|||
|
||||
<div v-else-if="filteredEnrolledCourses.length > 0">
|
||||
|
||||
<!-- GRID VIEW -->
|
||||
<!-- หมวดแสดงสไตล์กริดตาราง (GRID VIEW) -->
|
||||
<div v-if="viewMode === 'grid'" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
<div v-for="course in filteredEnrolledCourses" :key="course.id" class="flex flex-col rounded-[1.5rem] bg-white dark:!bg-slate-900 border border-slate-100 dark:border-slate-800 overflow-hidden shadow-sm hover:shadow-[0_8px_30px_rgb(0,0,0,0.06)] transition-all duration-300 group cursor-pointer" @click="navigateTo(`/classroom/learning?course_id=${course.id}`)">
|
||||
<!-- Thumbnail -->
|
||||
<!-- ส่วนรูปภาพหน้าปก (Thumbnail) -->
|
||||
<div class="relative w-full aspect-[4/3] bg-slate-100 dark:bg-slate-800 overflow-hidden">
|
||||
<img :src="course.thumbnail_url" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500" />
|
||||
<!-- Badge inside Image Map Top Left -->
|
||||
<!-- ป้ายหมวดหมู่บนมุมซ้ายของรูป (Badge inside Image Map Top Left) -->
|
||||
<div v-if="course.category_name" class="absolute top-3 left-3 bg-white/95 dark:bg-slate-900/95 backdrop-blur-md text-[#3B6BE8] dark:text-blue-400 font-bold text-[10px] px-3.5 py-1 rounded-full shadow-sm">
|
||||
{{ course.category_name }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Card Body -->
|
||||
<!-- ตัวการ์ด (Card Body) -->
|
||||
<div class="p-5 flex flex-col flex-1">
|
||||
<h3 class="font-bold text-slate-900 dark:text-white text-[14px] leading-snug line-clamp-2 mb-3">{{ getLocalizedText(course.title) }}</h3>
|
||||
|
||||
|
|
@ -275,11 +275,11 @@ onMounted(() => {
|
|||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col sm:flex-row items-stretch sm:items-center gap-2 mt-3 sm:mt-0">
|
||||
<!-- Certificate Button -->
|
||||
<!-- ปุ่มดาวน์โหลดใบเซอร์ (Certificate Button) -->
|
||||
<button v-if="course.completed" @click.stop="handleDownloadCertificate(course.id)" class="border border-green-100 bg-green-50 text-green-600 dark:border-green-900/50 dark:bg-green-900/30 dark:text-green-400 rounded-full px-3 py-1.5 text-[11px] font-bold hover:bg-green-100 dark:hover:bg-green-900/50 transition-colors shrink-0 flex items-center justify-center gap-1">
|
||||
<q-icon name="workspace_premium" size="14px" /> {{ $t('course.certificate') }}
|
||||
</button>
|
||||
<!-- Continue/Replay Button -->
|
||||
<!-- ปุ่มเรียนต่อหรือเรียนซ้ำ (Continue/Replay Button) -->
|
||||
<button class="bg-[#3B6BE8] text-white border-transparent hover:bg-blue-700 shadow-sm rounded-full px-5 py-1.5 text-[11px] font-bold transition-colors shrink-0 text-center cursor-pointer">
|
||||
{{ course.completed ? $t('course.studyAgain') : $t('dashboard.continue') }}
|
||||
</button>
|
||||
|
|
@ -289,20 +289,20 @@ onMounted(() => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- LIST VIEW -->
|
||||
<!-- หมวดแสดงสไตล์บรรทัดรายการ (LIST VIEW) -->
|
||||
<div v-else class="flex flex-col gap-4">
|
||||
<div v-for="course in filteredEnrolledCourses" :key="course.id" class="flex flex-col sm:flex-row items-center rounded-[1.5rem] bg-white dark:!bg-slate-900 border border-slate-100 dark:border-slate-800 p-4 gap-6 shadow-sm hover:shadow-[0_8px_30px_rgb(0,0,0,0.06)] transition-all duration-300 cursor-pointer group" @click="navigateTo(`/classroom/learning?course_id=${course.id}`)">
|
||||
|
||||
<!-- Thumbnail Left -->
|
||||
<!-- ส่วนภาพหน้าปกด้านซ้าย (Thumbnail Left) -->
|
||||
<div class="relative w-full sm:w-[240px] aspect-[16/10] sm:aspect-auto sm:h-[130px] rounded-2xl bg-slate-100 dark:bg-slate-800 overflow-hidden shrink-0">
|
||||
<img :src="course.thumbnail_url" class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500" />
|
||||
<!-- Badge inside Image -->
|
||||
<!-- ป้ายหมวดหมู่ในรูปภาพ (Badge inside Image) -->
|
||||
<div v-if="course.category_name" class="absolute top-2.5 left-2.5 bg-white/95 dark:bg-slate-900/95 backdrop-blur-md text-[#3B6BE8] dark:text-blue-400 font-bold text-[10px] px-3.5 py-1 rounded-full shadow-sm">
|
||||
{{ course.category_name }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content Right -->
|
||||
<!-- เนื้อหาอยู่ทางขวา (Content Right) -->
|
||||
<div class="flex-1 w-full flex flex-col md:flex-row gap-6 md:items-center">
|
||||
|
||||
<div class="flex-1 min-w-0">
|
||||
|
|
@ -310,7 +310,7 @@ onMounted(() => {
|
|||
|
||||
</div>
|
||||
|
||||
<!-- Progress and Button Zone -->
|
||||
<!-- โซนความคืบหน้าและปุ่มกด (Progress and Button Zone) -->
|
||||
<div class="flex md:flex-col items-center md:items-end justify-between md:justify-center gap-4 shrink-0 md:w-[200px]">
|
||||
<div class="w-full max-w-[140px] md:max-w-full">
|
||||
<div class="flex justify-between items-center text-[11px] font-bold text-slate-700 dark:text-slate-300 mb-2 tracking-wide">
|
||||
|
|
@ -323,11 +323,11 @@ onMounted(() => {
|
|||
</div>
|
||||
|
||||
<div class="flex flex-col items-stretch md:items-end gap-2 mt-3 sm:mt-0 w-full sm:w-auto">
|
||||
<!-- Certificate Button -->
|
||||
<!-- ปุ่มดาวน์โหลดใบเซอร์ (Certificate Button) -->
|
||||
<button v-if="course.completed" @click.stop="handleDownloadCertificate(course.id)" class="border border-green-100 bg-green-50 text-green-600 dark:border-green-900/50 dark:bg-green-900/30 dark:text-green-400 rounded-full px-4 py-2 text-[12px] font-bold hover:bg-green-100 dark:hover:bg-green-900/50 transition-colors shrink-0 flex items-center justify-center gap-1 w-full sm:w-auto">
|
||||
<q-icon name="workspace_premium" size="16px" /> {{ $t('course.downloadCertificate') }}
|
||||
</button>
|
||||
<!-- Continue/Replay Button -->
|
||||
<!-- ปุ่มเรียนต่อหรือเรียนซ้ำ (Continue/Replay Button) -->
|
||||
<button class="bg-[#3B6BE8] text-white border-transparent hover:bg-blue-700 shadow-sm rounded-full px-6 py-2 text-[12px] font-bold transition-colors shrink-0 text-center w-full sm:w-auto cursor-pointer">
|
||||
{{ course.completed ? $t('course.studyAgain') : $t('dashboard.continue') }}
|
||||
</button>
|
||||
|
|
@ -340,7 +340,7 @@ onMounted(() => {
|
|||
|
||||
</div>
|
||||
|
||||
<!-- Empty filter state -->
|
||||
<!-- กรณีที่ค้นหา/กรองแล้วไม่พบข้อมูล (Empty filter state) -->
|
||||
<div v-else class="flex flex-col items-center justify-center py-20">
|
||||
<q-icon name="search_off" size="48px" class="text-slate-300 dark:text-slate-600 mb-4" />
|
||||
<h3 class="text-lg font-bold text-slate-900 dark:text-white mb-2">{{ $t('myCourses.searchNoResult') }}</h3>
|
||||
|
|
@ -350,7 +350,7 @@ onMounted(() => {
|
|||
|
||||
</div>
|
||||
|
||||
<!-- MODAL: Enrollment Success -->
|
||||
<!-- หน้าต่างแจ้งเตือน: ลงทะเบียนสำเร็จ (MODAL: Enrollment Success) -->
|
||||
<q-dialog v-model="showEnrollModal" backdrop-filter="blur(4px)">
|
||||
<q-card class="rounded-[1.5rem] shadow-2xl p-8 max-w-sm w-full text-center relative overflow-hidden bg-white dark:bg-slate-800">
|
||||
<div class="absolute top-0 left-0 w-full h-2 bg-gradient-to-r from-green-400 to-emerald-600"></div>
|
||||
|
|
|
|||
|
|
@ -67,22 +67,22 @@ const showPassword = reactive({
|
|||
})
|
||||
|
||||
|
||||
// Rules have been moved to components
|
||||
// กฎต่างๆ ถูกย้ายไปที่คอมโพเนนต์แล้ว (Rules have been moved to components)
|
||||
|
||||
const fileInput = ref<HTMLInputElement | null>(null) // Used in view mode (outside component)
|
||||
const fileInput = ref<HTMLInputElement | null>(null) // ใช้ในโหมดมุมมอง (อยู่นอกคอมโพเนนต์) (Used in view mode (outside component))
|
||||
|
||||
const toggleEdit = (edit: boolean) => {
|
||||
isEditing.value = edit
|
||||
}
|
||||
|
||||
// Updated to accept File object directly (or Event for view mode compatibility if needed)
|
||||
// อัปเดตให้รับออบเจ็กต์ File ได้โดยตรง (หรือ Event สำหรับความเข้ากันได้ของโหมดมุมมองหากจำเป็น) (Updated to accept File object directly (or Event for view mode compatibility if needed))
|
||||
const handleFileUpload = async (fileOrEvent: File | Event) => {
|
||||
let file: File | null = null
|
||||
|
||||
if (fileOrEvent instanceof File) {
|
||||
file = fileOrEvent
|
||||
} else {
|
||||
// Fallback for native input change event
|
||||
// การทำงานสำรองสำหรับอีเวนต์ input change แบบเนทีฟ (Fallback for native input change event)
|
||||
const target = (fileOrEvent as Event).target as HTMLInputElement
|
||||
if (target.files && target.files[0]) {
|
||||
file = target.files[0]
|
||||
|
|
@ -112,7 +112,7 @@ const handleFileUpload = async (fileOrEvent: File | Event) => {
|
|||
}
|
||||
}
|
||||
|
||||
// Trigger upload for VIEW mode avatar click
|
||||
// เรียกการอัปโหลดเมื่อคลิกที่รูปโปรไฟล์ในโหมด View (Trigger upload for VIEW mode avatar click)
|
||||
const triggerUpload = () => {
|
||||
fileInput.value?.click()
|
||||
}
|
||||
|
|
@ -191,7 +191,7 @@ const handleUpdatePassword = async () => {
|
|||
isPasswordSaving.value = false
|
||||
}
|
||||
|
||||
// Watch for changes in global user state (e.g. after avatar upload or profile update)
|
||||
// เฝ้าดูการเปลี่ยนแปลงในสถานะผู้ใช้ส่วนกลาง (เช่น หลังจากอัปโหลดรูปโปรไฟล์หรืออัปเดตข้อมูลส่วนตัว) (Watch for changes in global user state (e.g. after avatar upload or profile update))
|
||||
watch(() => currentUser.value, (newUser) => {
|
||||
if (newUser) {
|
||||
userData.value.photoURL = newUser.photoURL || ''
|
||||
|
|
@ -220,7 +220,7 @@ onMounted(async () => {
|
|||
<q-spinner size="3rem" color="primary" />
|
||||
</div>
|
||||
|
||||
<!-- MAIN PROFILE SETTINGS -->
|
||||
<!-- การตั้งค่าโปรไฟล์หลัก (MAIN PROFILE SETTINGS) -->
|
||||
<div v-else class="max-w-5xl mx-auto pb-20 fade-in pt-4">
|
||||
|
||||
<!-- บัตรข้อมูลโปรไฟล์ (Profile Card) -->
|
||||
|
|
@ -255,7 +255,7 @@ onMounted(async () => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Form Inputs (2 Column Grid) -->
|
||||
<!-- ฟิลด์ข้อมูลฟอร์ม (แบ่งเป็น 2 คอลัมน์) (Form Inputs (2 Column Grid)) -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-6 mb-4">
|
||||
<div class="md:col-span-2 relative">
|
||||
<label class="block text-[13px] font-bold text-slate-700 dark:text-slate-300 mb-2">{{ $t('profile.prefix') }}</label>
|
||||
|
|
@ -300,7 +300,7 @@ onMounted(async () => {
|
|||
|
||||
</div>
|
||||
|
||||
<!-- Footer Buttons -->
|
||||
<!-- ปุ่มกดยืนยันต่างๆ (Footer Buttons) -->
|
||||
<div class="px-6 sm:px-8 py-5 border-t border-slate-200 dark:border-slate-800 flex flex-col sm:flex-row justify-center sm:justify-end gap-3 items-center bg-white dark:!bg-slate-900">
|
||||
<button class="w-full sm:w-auto text-[13px] font-bold text-slate-600 dark:text-slate-400 hover:text-slate-900 dark:hover:text-white px-4 py-2 transition order-2 sm:order-1" @click="fetchUserProfile(true)">{{ $t('common.cancel') }}</button>
|
||||
<button @click="handleUpdateProfile" :disabled="isProfileSaving" class="w-full sm:w-auto bg-[#3B6BE8] hover:bg-blue-700 text-white px-6 py-2.5 rounded-lg text-[13px] font-bold transition shadow-sm disabled:opacity-50 order-1 sm:order-2">
|
||||
|
|
@ -310,7 +310,7 @@ onMounted(async () => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Security Card -->
|
||||
<!-- การ์ดความปลอดภัย (Security Card) -->
|
||||
<div class="bg-white dark:!bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-2xl shadow-sm overflow-hidden">
|
||||
<div class="p-8 border-b border-slate-200 dark:border-slate-800">
|
||||
<h2 class="text-xl font-bold text-slate-900 dark:text-white">{{ $t('profile.security') }}</h2>
|
||||
|
|
@ -337,7 +337,7 @@ onMounted(async () => {
|
|||
|
||||
</div>
|
||||
|
||||
<!-- Password Modal -->
|
||||
<!-- โมดอลเปลี่ยนรหัสผ่าน (Password Modal) -->
|
||||
<q-dialog v-model="showPasswordModal">
|
||||
<q-card class="w-full max-w-md rounded-2xl p-2 dark:bg-slate-900 shadow-xl">
|
||||
<q-form @submit="handleUpdatePassword">
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const { user } = useAuth()
|
|||
const categoryCards = CATEGORY_CARDS
|
||||
const whyChooseUs = WHY_CHOOSE_US
|
||||
|
||||
//ระดับความยาก
|
||||
// ระดับความยาก (Level)
|
||||
const levelModel = ref('ระดับทั้งหมด')
|
||||
const levelOptions = ['ระดับทั้งหมด','ระดับเริ่มต้น', 'ระดับกลาง', 'ระดับสูง']
|
||||
|
||||
|
|
@ -59,6 +59,19 @@ const loadData = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
const getCategoryIcon = (categoryName: string) => {
|
||||
if (!categoryName) return 'o_category'
|
||||
const text = categoryName.toLowerCase()
|
||||
|
||||
if (text.includes('ออกแบบ') || text.includes('design')) return 'o_palette'
|
||||
if (text.includes('โปรแกรม') || text.includes('code') || text.includes('dev')) return 'o_terminal'
|
||||
if (text.includes('ธุรกิจ') || text.includes('business') || text.includes('การตลาด') || text.includes('market')) return 'o_storefront'
|
||||
if (text.includes('ภาษา') || text.includes('language')) return 'o_language'
|
||||
if (text.includes('ข้อมูล') || text.includes('data')) return 'o_analytics'
|
||||
|
||||
return 'o_interests'
|
||||
}
|
||||
|
||||
const goBrowse = (slug: string) => {
|
||||
navigateTo({ path: '/browse', query: { category: slug } })
|
||||
}
|
||||
|
|
@ -95,22 +108,22 @@ onMounted(() => {
|
|||
<!-- Section 1: Hero Section -->
|
||||
<section class="container mx-auto py-24 md:py-24 lg:py-28 px-6 lg:px-12 pb-16">
|
||||
<div class="flex flex-col lg:flex-row items-center gap-10 lg:gap-10 justify-between animate-fade-in">
|
||||
<!-- Left Content -->
|
||||
<!-- ด้านซ้าย: ข้อความและปุ่มกด (Left Content) -->
|
||||
<div class="flex flex-col items-start gap-6 flex-1 max-w-2xl ">
|
||||
<!-- Heading -->
|
||||
<!-- หัวข้อหลัก (Heading) -->
|
||||
<h1 class="text-4xl sm:text-5xl lg:text-[55px] font-bold leading-tight lg:leading-[66px] slide-up" style="animation-delay: 0.2s;">
|
||||
<span class="text-slate-900">ขยายขอบเขตความรู้ของคุณ</span><br>
|
||||
<span class="text-blue-600">ด้วยการเรียนรู้ออนไลน์</span>
|
||||
</h1>
|
||||
|
||||
<!-- Subtitle -->
|
||||
<!-- คำอธิบายรอง (Subtitle) -->
|
||||
<p class="text-slate-500 text-lg sm:text-xl leading-relaxed slide-up" style="animation-delay: 0.3s;">
|
||||
จุดประกายความรู้ของคุณ และเริ่มต้นอัปสกิลกับผู้เชี่ยวชาญ
|
||||
ในอุตสาหกรรมที่มีความรู้รอบด้านหลากหลายในหลายสาขา
|
||||
เรียนได้ทุกที่ ทุกเวลา
|
||||
</p>
|
||||
|
||||
<!-- Buttons -->
|
||||
<!-- ปุ่มกดต่างๆ (Buttons) -->
|
||||
<div class=" w-full flex flex-col sm:flex-row items-center gap-4 pt-5 slide-up" style="animation-delay: 0.4s;">
|
||||
<q-btn
|
||||
unelevated
|
||||
|
|
@ -134,7 +147,7 @@ onMounted(() => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right - Hero Image -->
|
||||
<!-- ด้านขวา: รูปภาพฮีโร่ (Right - Hero Image) -->
|
||||
<div class="flex-1 w-full max-w-lg md:max-w-md lg:max-w-xl pl-0 py-10">
|
||||
<div class="relative rounded-2xl overflow-hidden shadow-[0_25px_50px_-12px_rgba(0,0,0,0.25)] aspect-square">
|
||||
<img
|
||||
|
|
@ -144,7 +157,7 @@ onMounted(() => {
|
|||
/>
|
||||
<div class="absolute inset-0 bg-gradient-to-t from-black/40 via-transparent to-transparent" />
|
||||
|
||||
<!-- Course Card Overlay -->
|
||||
<!-- ส่วนทับซ้อนสำหรับทำโมเดลการ์ดคอร์ส (Course Card Overlay) -->
|
||||
<!-- <div class="absolute bottom-5 left-5 right-5">
|
||||
<div class="bg-white/85 backdrop-blur-sm border border-white/20 rounded-3xl px-6 py-5">
|
||||
<div class="flex items-center gap-4">
|
||||
|
|
@ -170,7 +183,7 @@ onMounted(() => {
|
|||
<!-- Section 2: ทำไมต้องเลือกแพลตฟอร์มของเรา -->
|
||||
<section class="pt-20 pb-14 bg-white relative flex-col">
|
||||
<div class="container mx-auto px-6 lg:px-12">
|
||||
<!-- Heading -->
|
||||
<!-- หัวข้อหลัก (Heading) -->
|
||||
<div class="text-center mb-16 slide-up">
|
||||
<h2 class="text-4xl md:text-[2.4rem] font-bold text-slate-900 mb-6">
|
||||
ทำไมต้องเลือกแพลตฟอร์มของเรา?
|
||||
|
|
@ -180,7 +193,7 @@ onMounted(() => {
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Horizontal Cards -->
|
||||
<!-- โซนแนะนำแบบการ์ดแนวนอน (Horizontal Cards) -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
|
||||
<div v-for="(item, i) in whyChooseUs" :key="i"
|
||||
class="slide-up p-10 rounded-2xl bg-[#F8FAFC] border border-[#f1f2f9] hover:border-[#2463eb61] hover:bg-white transition-all duration-500 group"
|
||||
|
|
@ -203,25 +216,25 @@ onMounted(() => {
|
|||
<!-- Section 3: เลือกเรียนตามเรื่องที่คุณสนใจ -->
|
||||
<section class="py-20 md:py-24 bg-white">
|
||||
<div class="container mx-auto px-6 lg:px-12">
|
||||
<!-- Heading -->
|
||||
<!-- หัวข้อ (Heading) -->
|
||||
<div class="mb-12 slide-up">
|
||||
<h2 class="text-[1.4rem] text-3xl md:text-4xl font-semibold text-slate-900 px-4">
|
||||
เลือกเรียนตามเรื่องที่คุณสนใจ
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<!-- Horizontal Cards -->
|
||||
<!-- โซนหมวดหมู่แบบการ์ดแนวนอน (Horizontal Cards) -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 justify-center gap-6 px-4">
|
||||
<div v-for="(card, i) in categoryCards" :key="i"
|
||||
class="cursor-pointer bg-white rounded-3xl p-6 border border-slate-200/80 shadow-[0px_1px_2px_0px_rgba(0,0,0,0.05)] hover:shadow-2xl hover:shadow-blue-600/5 hover:-translate-y-1 hover:border-[#2463eb61] transition-all duration-500 flex items-center gap-5"
|
||||
@click="goBrowse(card.slug)"
|
||||
>
|
||||
<!-- Icon Box -->
|
||||
<!-- กล่องไอคอน (Icon Box) -->
|
||||
<div class="flex-shrink-0 w-16 h-16 rounded-2xl flex items-center justify-center bg-slate-50 group-hover:scale-110 transition-transform duration-500">
|
||||
<q-icon :name="card.icon" size="35px" class="text-blue-600" />
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<!-- เนื้อหาข้อความ (Content) -->
|
||||
<div class="flex-grow pr-2">
|
||||
<h3 class="text-lg md:text-xl font-bold text-slate-900 mb-1 group-hover:text-blue-600 transition-colors leading-tight">
|
||||
{{ card.title }}
|
||||
|
|
@ -231,7 +244,7 @@ onMounted(() => {
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Arrow -->
|
||||
<!-- ลูกศรชี้ขวา (Arrow) -->
|
||||
<div class="gt-xs flex-shrink-0 text-slate-300 group-hover:text-blue-600 transition-colors transform group-hover:translate-x-1 duration-300">
|
||||
<q-icon name="chevron_right" size="24px" />
|
||||
</div>
|
||||
|
|
@ -243,7 +256,7 @@ onMounted(() => {
|
|||
<!-- Section 4: "คอร์สออนไลน์" -->
|
||||
<section class="py-12 md:py-24 bg-slate-50">
|
||||
<div class="container mx-auto px-6 lg:px-12">
|
||||
<!-- Heading -->
|
||||
<!-- หัวข้อหลักและลิงก์เพิ่มเติม (Heading) -->
|
||||
<div class="flex flex-col md:flex-row items-start md:items-end justify-between mb-5 gap-8">
|
||||
<div class="slide-up">
|
||||
<h2 class="text-4xl md:text-[2.4rem] font-bold text-slate-900 mb-4">คอร์สออนไลน์</h2>
|
||||
|
|
@ -254,9 +267,9 @@ onMounted(() => {
|
|||
</NuxtLink>
|
||||
</div>
|
||||
|
||||
<!-- Filters Row -->
|
||||
<!-- แถวตัวกรองคอร์ส (Filters Row) -->
|
||||
<div class="flex items-center gap-2 mb-8 overflow-x-auto no-scrollbar slide-up justify-between">
|
||||
<!-- Category Filters -->
|
||||
<!-- ตัวกรองหมวดหมู่คอร์ส (Category Filters) -->
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
class="py-2 px-5 rounded-full font-medium text-lg transition-all whitespace-nowrap border-2"
|
||||
|
|
@ -274,7 +287,7 @@ onMounted(() => {
|
|||
:class="selectedCategory === category.slug ? 'bg-blue-600 text-white border-blue-600 font-semibold' : 'bg-white border-slate-200 text-slate-700 hover:border-slate-300'"
|
||||
@click="selectedCategory = category.slug"
|
||||
>
|
||||
<q-icon :name="category.icon || 'o_label'" size="20px" class="mr-1" />
|
||||
<q-icon :name="getCategoryIcon(getLocalizedText(category.name))" size="20px" class="mr-1" />
|
||||
{{ getLocalizedText(category.name) }}
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -296,7 +309,7 @@ onMounted(() => {
|
|||
</div> -->
|
||||
</div>
|
||||
|
||||
<!-- Courses Carousel -->
|
||||
<!-- ระบบเลื่อนสไลด์ดูคอร์ส (Courses Carousel) -->
|
||||
<div v-if="isLoading" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||
<div v-for="i in 4" :key="i" class="bg-white rounded-2xl h-[450px] animate-pulse" />
|
||||
</div>
|
||||
|
|
@ -326,7 +339,7 @@ onMounted(() => {
|
|||
class="flex flex-col flex-1 min-w-0 rounded-2xl border border-slate-100 bg-white shadow-sm overflow-hidden hover:shadow-lg hover:-translate-y-1 transition-all duration-300 cursor-pointer"
|
||||
@click="navigateTo(`/course/${course.id}`)"
|
||||
>
|
||||
<!-- Image-->
|
||||
<!-- รูปภาพหน้าปกคอร์ส (Image) -->
|
||||
<div class="relative flex-shrink-0">
|
||||
<img
|
||||
v-if="course.thumbnail_url"
|
||||
|
|
@ -339,23 +352,23 @@ onMounted(() => {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<!-- เนื้อหาของคอร์ส (Content) -->
|
||||
<div class="flex flex-col flex-1 p-6">
|
||||
|
||||
|
||||
<!-- Title -->
|
||||
<!-- ชื่อคอร์ส (Title) -->
|
||||
<h3 class="text-[#0F172A] font-semibold text-lg leading-snug mb-2 line-clamp-2">
|
||||
{{ getLocalizedText(course.title) }}
|
||||
</h3>
|
||||
|
||||
<!-- Description -->
|
||||
<!-- รายละเอียดแบบย่อ (Description) -->
|
||||
<p class="text-slate-500 text-sm leading-relaxed mb-4 flex-1 line-clamp-2">
|
||||
{{ getLocalizedText(course.description) }}
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
<!-- Price + Button -->
|
||||
<!-- ส่วนแถบราคาและปุ่มกด (Price + Button) -->
|
||||
<div class="flex items-center justify-between pt-6 border-t border-slate-100 gap-2">
|
||||
<div class="flex flex-col">
|
||||
<span v-if="course.price > 0" class="text-[#0F172A] font-bold text-xl">
|
||||
|
|
@ -378,7 +391,7 @@ onMounted(() => {
|
|||
</q-carousel-slide>
|
||||
</q-carousel>
|
||||
|
||||
<!-- Custom Carousel Navigation -->
|
||||
<!-- ระบบนำทางสไลด์แบบกำหนดเอง (Custom Carousel Navigation) -->
|
||||
<button
|
||||
v-if="courseChunks.length > 1"
|
||||
class="absolute -left-4 md:-left-12 top-1/2 -translate-y-1/2 z-10 w-12 h-12 rounded-full bg-white shadow-xl border border-slate-100 flex items-center justify-center text-slate-500 hover:text-blue-600 transition-all hover:scale-110"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<div class="min-h-screen bg-gray-50 p-4 md:p-8">
|
||||
<div class="max-w-4xl mx-auto">
|
||||
|
||||
<!-- Header / Title -->
|
||||
<!-- ส่วนหัว / ชื่อเรื่อง (Header / Title) -->
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-gray-800">Quiz Runner</h1>
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-12 gap-6">
|
||||
|
||||
<!-- Sidebar: Question Navigator -->
|
||||
<!-- แถบด้านข้าง: ตัวนำทางคำถาม (Sidebar: Question Navigator) -->
|
||||
<div class="lg:col-span-3 order-2 lg:order-1">
|
||||
<QCard class="bg-white shadow-sm sticky top-4">
|
||||
<QCardSection>
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Legend -->
|
||||
<!-- คำอธิบายสัญลักษณ์ (Legend) -->
|
||||
<div class="mt-6 space-y-2 text-xs text-gray-600">
|
||||
<div class="flex items-center gap-2"><div class="w-3 h-3 rounded-full bg-blue-500"></div> Current</div>
|
||||
<div class="flex items-center gap-2"><div class="w-3 h-3 rounded-full bg-green-500"></div> Completed</div>
|
||||
|
|
@ -44,11 +44,11 @@
|
|||
</QCard>
|
||||
</div>
|
||||
|
||||
<!-- Main Content: Question -->
|
||||
<!-- เนื้อหาหลัก: คำถาม (Main Content: Question) -->
|
||||
<div class="lg:col-span-9 order-1 lg:order-2">
|
||||
<QCard v-if="store.currentQuestion" class="bg-white shadow-md min-h-[400px] flex flex-col">
|
||||
|
||||
<!-- Question Header -->
|
||||
<!-- ส่วนหัวคำถาม (Question Header) -->
|
||||
<QCardSection class="bg-gray-50 border-b border-gray-100 py-4">
|
||||
<div class="flex justify-between items-start">
|
||||
<div>
|
||||
|
|
@ -57,18 +57,18 @@
|
|||
</QBadge>
|
||||
<h2 class="text-xl font-medium text-gray-800">
|
||||
<span class="text-gray-400 mr-2">{{ store.currentQuestionIndex + 1 }}.</span>
|
||||
{{ store.currentQuestion.title }}
|
||||
{{ getLocalizedString(store.currentQuestion.question) }}
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
</QCardSection>
|
||||
|
||||
<!-- Question Body -->
|
||||
<!-- ส่วนเนื้อหาคำถาม (Question Body) -->
|
||||
<QCardSection class="flex-grow py-8 px-6">
|
||||
|
||||
<!-- Single Choice -->
|
||||
<!-- เลือกคำตอบเดียว (Single Choice) -->
|
||||
<div v-if="store.currentQuestion.type === 'single'">
|
||||
<div v-for="opt in store.currentQuestion.options" :key="opt.id"
|
||||
<div v-for="opt in store.currentQuestion.choices" :key="opt.id"
|
||||
class="mb-3 p-3 border rounded-lg hover:bg-blue-50 cursor-pointer transition-colors"
|
||||
:class="{ 'border-blue-500 bg-blue-50': currentVal === opt.id, 'border-gray-200': currentVal !== opt.id }"
|
||||
@click="handleInput(opt.id)">
|
||||
|
|
@ -77,14 +77,14 @@
|
|||
:class="{ 'border-blue-500': currentVal === opt.id, 'border-gray-300': currentVal !== opt.id }">
|
||||
<div v-if="currentVal === opt.id" class="w-2.5 h-2.5 rounded-full bg-blue-500"></div>
|
||||
</div>
|
||||
<span class="text-gray-700">{{ opt.label }}</span>
|
||||
<span class="text-gray-700">{{ getLocalizedString(opt.text) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Multiple Choice -->
|
||||
<!-- เลือกหลายคำตอบ (Multiple Choice) -->
|
||||
<div v-else-if="store.currentQuestion.type === 'multiple'">
|
||||
<div v-for="opt in store.currentQuestion.options" :key="opt.id"
|
||||
<div v-for="opt in store.currentQuestion.choices" :key="opt.id"
|
||||
class="mb-3 p-3 border rounded-lg hover:bg-blue-50 cursor-pointer transition-colors"
|
||||
:class="{ 'border-blue-500 bg-blue-50': isSelected(opt.id), 'border-gray-200': !isSelected(opt.id) }"
|
||||
@click="toggleSelection(opt.id)">
|
||||
|
|
@ -93,12 +93,12 @@
|
|||
:class="{ 'border-blue-500 bg-blue-500': isSelected(opt.id), 'border-gray-300': !isSelected(opt.id) }">
|
||||
<QIcon v-if="isSelected(opt.id)" name="check" class="text-white text-xs" />
|
||||
</div>
|
||||
<span class="text-gray-700">{{ opt.label }}</span>
|
||||
<span class="text-gray-700">{{ getLocalizedString(opt.text) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Text Input -->
|
||||
<!-- พิมพ์ข้อความ (Text Input) -->
|
||||
<div v-else-if="store.currentQuestion.type === 'text'">
|
||||
<QInput
|
||||
v-model="textModel"
|
||||
|
|
@ -113,7 +113,7 @@
|
|||
|
||||
</QCardSection>
|
||||
|
||||
<!-- Error Banner -->
|
||||
<!-- แบนเนอร์แสดงข้อผิดพลาด (Error Banner) -->
|
||||
<QBanner v-if="store.lastError" class="bg-red-50 text-red-600 px-6 py-2 border-t border-red-100">
|
||||
<template v-slot:avatar>
|
||||
<QIcon name="warning" color="red" />
|
||||
|
|
@ -121,7 +121,7 @@
|
|||
{{ store.lastError }}
|
||||
</QBanner>
|
||||
|
||||
<!-- Actions Footer -->
|
||||
<!-- ส่วนท้ายปุ่มกดต่างๆ (Actions Footer) -->
|
||||
<QCardSection class="border-t border-gray-100 bg-gray-50 p-4 flex flex-wrap gap-4 items-center justify-between">
|
||||
|
||||
<QBtn
|
||||
|
|
@ -140,7 +140,7 @@
|
|||
flat
|
||||
color="orange-8"
|
||||
label="Skip for now"
|
||||
@click="store.skipQuestion()"
|
||||
@click="store.nextQuestion()"
|
||||
no-caps
|
||||
/>
|
||||
|
||||
|
|
@ -178,11 +178,11 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, ref, onMounted, watch, reactive } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
// Composable is auto-imported in Nuxt
|
||||
// คอมโพสิเบิลถูกนำเข้าอัตโนมัติใน Nuxt (Composable is auto-imported in Nuxt)
|
||||
// import { useQuizRunner } from '@/composables/useQuizRunner';
|
||||
|
||||
const route = useRoute();
|
||||
// Wrap in reactive to unwrap refs, mimicking Pinia store behavior for template
|
||||
// ห่อหุ้มใน reactive เพื่อแกะค่า refs ทำให้เหมือนพฤติกรรม Pinia store สำหรับ template (Wrap in reactive to unwrap refs, mimicking Pinia store behavior for template)
|
||||
const store = reactive(useQuizRunner());
|
||||
|
||||
onMounted(() => {
|
||||
|
|
@ -190,7 +190,16 @@ onMounted(() => {
|
|||
store.initQuiz(quizId);
|
||||
});
|
||||
|
||||
// -- Helpers for Input Handling --
|
||||
// -- ตัวช่วยสำหรับการจัดการการป้อนข้อมูล (Helpers for Input Handling) --
|
||||
|
||||
// ฟังก์ชันช่วยเหลือสำหรับแปลภาษา (Helper to safely format text)
|
||||
const getLocalizedString = (val: any): string => {
|
||||
if (typeof val === 'string') return val;
|
||||
if (val && typeof val === 'object') {
|
||||
return val.th || val.en || String(val);
|
||||
}
|
||||
return String(val || '');
|
||||
}
|
||||
|
||||
const currentVal = computed(() => {
|
||||
return store.currentAnswer?.value;
|
||||
|
|
@ -200,23 +209,23 @@ const isSaved = computed(() => {
|
|||
return store.currentAnswer?.is_saved;
|
||||
});
|
||||
|
||||
// Single Choice
|
||||
function handleInput(val: string) {
|
||||
// เลือกคำตอบเดียว (Single Choice)
|
||||
function handleInput(val: number) {
|
||||
store.updateAnswer(val);
|
||||
}
|
||||
|
||||
// Text Choice
|
||||
// พิมพ์ข้อความ (Text Choice)
|
||||
const textModel = ref('');
|
||||
// Watch for question changes to reset text model
|
||||
// จับตาดูการเปลี่ยนแปลงคำถามเพื่อล้างค่า (Watch for question changes to reset text model)
|
||||
watch(
|
||||
() => store.currentQuestionIndex,
|
||||
() => {
|
||||
if (store.currentQuestion?.type === 'text') {
|
||||
textModel.value = (store.currentAnswer?.value as string) || '';
|
||||
}
|
||||
// Clear error when changing question
|
||||
// ล้างข้อผิดพลาดเมื่อเปลี่ยนคำถาม (Clear error when changing question)
|
||||
store.lastError = null;
|
||||
// Scroll to top
|
||||
// เลื่อนหน้าจอขึ้นบนสุด (Scroll to top)
|
||||
if (typeof window !== 'undefined') {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
|
|
@ -224,7 +233,7 @@ watch(
|
|||
{ immediate: true }
|
||||
);
|
||||
|
||||
// Watch for error to scroll to error/field
|
||||
// จับตาดูข้อผิดพลาดเพื่อเลื่อนหน้าจอไปยังฟิลด์นั้น (Watch for error to scroll to error/field)
|
||||
watch(
|
||||
() => store.lastError,
|
||||
(newVal) => {
|
||||
|
|
@ -245,8 +254,8 @@ function handleTextInput(val: string | number | null) {
|
|||
store.updateAnswer(val as string);
|
||||
}
|
||||
|
||||
// Multiple Choice
|
||||
function isSelected(id: string) {
|
||||
// เลือกหลายคำตอบ (Multiple Choice)
|
||||
function isSelected(id: number) {
|
||||
const val = store.currentAnswer?.value;
|
||||
if (Array.isArray(val)) {
|
||||
return val.includes(id);
|
||||
|
|
@ -254,9 +263,9 @@ function isSelected(id: string) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function toggleSelection(id: string) {
|
||||
function toggleSelection(id: number) {
|
||||
const val = store.currentAnswer?.value;
|
||||
let currentArr: string[] = [];
|
||||
let currentArr: number[] = [];
|
||||
if (Array.isArray(val)) {
|
||||
currentArr = [...val];
|
||||
}
|
||||
|
|
@ -270,10 +279,10 @@ function toggleSelection(id: string) {
|
|||
store.updateAnswer(currentArr);
|
||||
}
|
||||
|
||||
// -- Helpers for Styling --
|
||||
// -- ตัวช่วยสำหรับการจัดแต่งทรง (Helpers for Styling) --
|
||||
|
||||
function getIndicatorClass(index: number, qId: number) {
|
||||
// 1. Current = Blue
|
||||
// 1. ปัจจุบัน = สีน้ำเงิน (Current = Blue)
|
||||
if (index === store.currentQuestionIndex) {
|
||||
return 'bg-blue-500 text-white border-blue-600';
|
||||
}
|
||||
|
|
@ -286,7 +295,8 @@ function getIndicatorClass(index: number, qId: number) {
|
|||
case 'skipped':
|
||||
return 'bg-orange-500 text-white border-orange-600';
|
||||
case 'in_progress':
|
||||
// If it's in_progress but NOT current (should be rare/impossible with strict logic, but handled)
|
||||
// กรณีที่เป็น in_progress แต่ไม่ใช่คำถามปัจจุบัน (จริงๆ เกิดยากตามตรรกะที่เข้มงวด แต่เผื่อไว้ก่อน)
|
||||
// (If it's in_progress but NOT current (should be rare/impossible with strict logic, but handled))
|
||||
return 'bg-blue-200 text-blue-800 border-blue-300';
|
||||
case 'not_started':
|
||||
default:
|
||||
|
|
@ -297,5 +307,5 @@ function getIndicatorClass(index: number, qId: number) {
|
|||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* Optional: Transitions */
|
||||
/* ส่วนเสริม: ทรานสิชั่น (Optional: Transitions) */
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file reset-password.vue
|
||||
* @description Reset Password Page.
|
||||
* Allows user to set a new password after verifying their email link (simulated).
|
||||
* @description หน้าตั้งรหัสผ่านใหม่ (Reset Password Page.
|
||||
* อนุญาตให้ผู้ใช้ตั้งรหัสผ่านใหม่หลังจากยืนยันลิงก์อีเมล)
|
||||
*/
|
||||
|
||||
definePageMeta({
|
||||
|
|
@ -44,9 +44,9 @@ const handlePasswordInput = (field: keyof typeof resetForm, val: string) => {
|
|||
resetForm[field] = val
|
||||
if (/[\u0E00-\u0E7F]/.test(val)) {
|
||||
if (field === 'password') errors.value.password = 'ห้ามใส่ภาษาไทย'
|
||||
// We don't necessarily need to flag confirmPassword individually if it just needs to match, but let's be consistent if we want
|
||||
// ไม่จำเป็นต้องแจ้งเตือน confirmPassword แยกต่างหากถ้ามันแค่ต้องตรงกัน แต่เพื่อให้สอดคล้องกันเราก็ควรทำ (We don't necessarily need to flag confirmPassword individually if it just needs to match, but let's be consistent if we want)
|
||||
} else {
|
||||
// Clear error if it was "Thai characters"
|
||||
// ลบข้อผิดพลาดถ้าเป็น "ห้ามใส่ภาษาไทย" (Clear error if it was "Thai characters")
|
||||
if (field === 'password' && errors.value.password === 'ห้ามใส่ภาษาไทย') {
|
||||
clearFieldError('password')
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ onMounted(() => {
|
|||
const resetPassword = async () => {
|
||||
if (!validate(resetForm, resetRules)) return
|
||||
|
||||
// Extract token from query
|
||||
// ดึงโทเคนจาก URL query (Extract token from query)
|
||||
const token = route.query.token as string
|
||||
|
||||
if (!token) {
|
||||
|
|
@ -92,7 +92,7 @@ const resetPassword = async () => {
|
|||
<template>
|
||||
<div class="relative min-h-screen w-full flex items-center justify-center p-4 overflow-hidden bg-slate-50 transition-colors">
|
||||
<!-- ==========================================
|
||||
BACKGROUND EFFECTS (Light Mode Only)
|
||||
เอฟเฟกต์พื้นหลัง (แสดงเฉพาะโหมดสว่าง) (BACKGROUND EFFECTS (Light Mode Only))
|
||||
========================================== -->
|
||||
<div class="fixed inset-0 overflow-hidden pointer-events-none -z-10">
|
||||
<div class="absolute inset-0 bg-gradient-to-br from-white via-slate-50 to-blue-50/50"></div>
|
||||
|
|
@ -101,11 +101,11 @@ const resetPassword = async () => {
|
|||
</div>
|
||||
|
||||
<!-- ==========================================
|
||||
RESET PASSWORD CARD
|
||||
การ์ดตั้งรหัสผ่านใหม่ (RESET PASSWORD CARD)
|
||||
========================================== -->
|
||||
<div class="w-full max-w-[460px] relative z-10 slide-up">
|
||||
|
||||
<!-- Header / Logo -->
|
||||
<!-- หัวข้อ / โลโก้ (Header / Logo) -->
|
||||
<div class="text-center mb-8">
|
||||
<div class="inline-flex items-center justify-center w-14 h-14 rounded-2xl bg-gradient-to-tr from-blue-600 to-indigo-600 text-white shadow-lg shadow-blue-600/20 mb-6">
|
||||
<span class="font-black text-2xl">E</span>
|
||||
|
|
@ -116,10 +116,10 @@ const resetPassword = async () => {
|
|||
|
||||
<div class="bg-white rounded-[2rem] p-8 md:p-10 shadow-xl shadow-slate-200/50 border border-slate-100 relative overflow-hidden">
|
||||
|
||||
<!-- Form -->
|
||||
<!-- ฟอร์ม (Form) -->
|
||||
<form @submit.prevent="resetPassword" class="flex flex-col gap-6">
|
||||
|
||||
<!-- New Password -->
|
||||
<!-- รหัสผ่านใหม่ (New Password) -->
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-slate-700 mb-2 ml-1">รหัสผ่านใหม่ <span class="text-red-500">*</span></label>
|
||||
<div class="relative group">
|
||||
|
|
@ -145,7 +145,7 @@ const resetPassword = async () => {
|
|||
<span v-if="errors.password" class="text-xs text-red-500 font-medium ml-1 mt-1 block slide-up-sm">{{ errors.password }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Confirm Password -->
|
||||
<!-- ยืนยันรหัสผ่านใหม่ (Confirm Password) -->
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-slate-700 mb-2 ml-1">ยืนยันรหัสผ่านใหม่ <span class="text-red-500">*</span></label>
|
||||
<div class="relative group">
|
||||
|
|
@ -171,7 +171,7 @@ const resetPassword = async () => {
|
|||
<span v-if="errors.confirmPassword" class="text-xs text-red-500 font-medium ml-1 mt-1 block slide-up-sm">{{ errors.confirmPassword }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Submit Button -->
|
||||
<!-- ปุ่มยืนยัน (Submit Button) -->
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="isLoading"
|
||||
|
|
@ -183,7 +183,7 @@ const resetPassword = async () => {
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Back Link -->
|
||||
<!-- ลิงก์ย้อนกลับ (Back Link) -->
|
||||
<div class="mt-8 text-center text-slate-500">
|
||||
<NuxtLink to="/auth/login" class="inline-flex items-center gap-2 text-sm font-medium hover:text-slate-800 transition-colors group px-4 py-2 rounded-lg hover:bg-white/50">
|
||||
<span class="group-hover:-translate-x-1 transition-transform">←</span> กลับไปหน้าเข้าสู่ระบบ
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* @file verify-email.vue
|
||||
* @description Page for handling email verification process.
|
||||
* Displays loading state while processing token, then shows success or error message.
|
||||
* @description หน้าสำหรับกระบวนการยืนยันอีเมล (Page for handling email verification process.
|
||||
* แสดงสถานะกำลังโหลดระหว่างประมวลผลโทเคน จากนั้นแสดงข้อความสำเร็จหรือข้อผิดพลาด)
|
||||
*/
|
||||
|
||||
definePageMeta({
|
||||
|
|
@ -28,7 +28,7 @@ onMounted(async () => {
|
|||
return
|
||||
}
|
||||
|
||||
// Call verify API
|
||||
// เรียกใช้ API เพื่อยืนยัน (Call verify API)
|
||||
const result = await verifyEmail(token)
|
||||
|
||||
isLoading.value = false
|
||||
|
|
@ -39,7 +39,7 @@ onMounted(async () => {
|
|||
isSuccess.value = false
|
||||
if (result.code === 400) {
|
||||
errorMessage.value = t('profile.emailAlreadyVerified')
|
||||
// If already verified, show success state with specific message
|
||||
// หากยืนยันแล้วให้แสดงสถานะสำเร็จพร้อมด้วยข้อความเฉพาะ (If already verified, show success state with specific message)
|
||||
isSuccess.value = true
|
||||
} else if (result.code === 401) {
|
||||
errorMessage.value = t('auth.tokenExpired')
|
||||
|
|
@ -58,7 +58,7 @@ const navigateToHome = () => {
|
|||
<div class="min-h-screen flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8 bg-slate-50 dark:bg-[#0f172a]">
|
||||
<div class="auth-card max-w-md w-full space-y-8 p-8 rounded-2xl text-center">
|
||||
|
||||
<!-- Loading State -->
|
||||
<!-- สถานะกำลังโหลด (Loading State) -->
|
||||
<div v-if="isLoading" class="flex flex-col items-center justify-center py-8">
|
||||
<q-spinner-dots size="4rem" color="primary" />
|
||||
<h2 class="mt-6 text-xl font-bold text-slate-900 dark:text-white animate-pulse">
|
||||
|
|
@ -66,7 +66,7 @@ const navigateToHome = () => {
|
|||
</h2>
|
||||
</div>
|
||||
|
||||
<!-- Success State -->
|
||||
<!-- สถานะสำเร็จ (Success State) -->
|
||||
<div v-else-if="isSuccess" class="flex flex-col items-center animate-bounce-in">
|
||||
<div class="w-24 h-24 rounded-full bg-green-500 flex items-center justify-center mb-10 shadow-lg shadow-green-500/20">
|
||||
<q-icon name="check" class="text-5xl text-white font-black" />
|
||||
|
|
@ -89,7 +89,7 @@ const navigateToHome = () => {
|
|||
/>
|
||||
</div>
|
||||
|
||||
<!-- Error State -->
|
||||
<!-- สถานะข้อผิดพลาด (Error State) -->
|
||||
<div v-else class="flex flex-col items-center animate-shake">
|
||||
<div class="w-24 h-24 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center mb-6">
|
||||
<q-icon name="error" class="text-6xl text-red-500" />
|
||||
|
|
@ -126,11 +126,15 @@ const navigateToHome = () => {
|
|||
}
|
||||
|
||||
.auth-card {
|
||||
@apply bg-white border-slate-100 shadow-xl;
|
||||
background-color: white;
|
||||
border-color: #f1f5f9;
|
||||
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
||||
border-width: 1px;
|
||||
}
|
||||
.dark .auth-card {
|
||||
@apply bg-[#1e293b] border-white/5 shadow-none;
|
||||
:global(.dark) .auth-card {
|
||||
background-color: #1e293b;
|
||||
border-color: rgba(255, 255, 255, 0.05);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
@keyframes bounceIn {
|
||||
|
|
|
|||
85
Frontend-Learner/playwright-report/index.html
Normal file
85
Frontend-Learner/playwright-report/index.html
Normal file
File diff suppressed because one or more lines are too long
57
Frontend-Learner/playwright.config.ts
Normal file
57
Frontend-Learner/playwright.config.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { defineConfig, devices } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* @file playwright.config.ts
|
||||
* @description ไฟล์ตั้งค่าสำหรับการทำ Automated E2E Testing ด้วย Playwright
|
||||
*/
|
||||
export default defineConfig({
|
||||
// โฟลเดอร์ที่เก็บไฟล์เทส (ชี้ไปที่โฟลเดอร์ปลายทางที่เราสร้าง)
|
||||
testDir: './tests/e2e',
|
||||
|
||||
// รันเทสแบบขนาน (พร้อมๆ กันหลายไฟล์) เพื่อให้เสร็จเร็วขึ้น
|
||||
fullyParallel: true,
|
||||
|
||||
// หากการรันเทสบน CI/CD ล้มเหลว ให้ลองรันซ้ำ 2 ครั้ง
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
|
||||
// จำนวน Worker ที่ใช้รันเทส
|
||||
workers: process.env.CI ? 1 : undefined,
|
||||
|
||||
// รูปแบบการแสดงผลลัพธ์ (Reporter)
|
||||
reporter: 'html',
|
||||
|
||||
use: {
|
||||
// กำหนดล่วงหน้าว่าเว็บที่เรากำลังจะพุ่งไปหาคือ URL อะไร (พอร์ต 3000 ของ Nuxt)
|
||||
baseURL: 'http://localhost:3000',
|
||||
|
||||
// ตั้งค่าให้เก็บประวัติแบบติดตามผล (Trace) ถ้าระบบพัง จะได้กลับมาดูได้
|
||||
trace: 'on-first-retry',
|
||||
|
||||
// ตั้งค่าเก็บรูปภาพหน้าจอเมื่อพัง (Screenshot on failure)
|
||||
screenshot: 'only-on-failure'
|
||||
},
|
||||
|
||||
// ตั้งค่าอุปกรณ์ที่ใช้ทดสอบ (Browsers)
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
// หากต้องการเทสบน Firefox หรือ Safari สามารถเปิดคอมเมนต์บรรทัดถัดไปได้เลย
|
||||
// {
|
||||
// name: 'firefox',
|
||||
// use: { ...devices['Desktop Firefox'] },
|
||||
// },
|
||||
// {
|
||||
// name: 'webkit',
|
||||
// use: { ...devices['Desktop Safari'] },
|
||||
// },
|
||||
],
|
||||
|
||||
// (Optional) หากต้องการให้เปิด Local Server อัตโนมัติก่อนรันเทส สามารถเอาคอมเมนต์ออกได้
|
||||
// webServer: {
|
||||
// command: 'npm run dev',
|
||||
// url: 'http://localhost:3000',
|
||||
// reuseExistingServer: !process.env.CI,
|
||||
// },
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue