Compare commits
42 commits
backend-de
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
522a0eec8a | ||
|
|
b6c1aebe30 | ||
|
|
1c63e79db1 | ||
|
|
9bb941b45e | ||
|
|
ebcae0b3e7 | ||
|
|
a3b2e55443 | ||
|
|
9bc24fbe8a | ||
|
|
734d922393 | ||
|
|
03f16cf2fd | ||
|
|
c8ef372d4e | ||
|
|
dccf808c2b | ||
|
|
ad11c6b7c5 | ||
|
|
aceeb80d9a | ||
|
|
3a9da1007b | ||
|
|
5b9cf72046 | ||
|
|
9dc8636d31 | ||
|
|
5ad7184e6c | ||
|
|
c697a15525 | ||
|
|
8cbef76b1e | ||
|
|
797e3db644 | ||
|
|
031ca5c984 | ||
|
|
01d249c19a | ||
|
|
0588ad7acd | ||
|
|
ce2a472cac | ||
|
|
096b5bbc52 | ||
|
|
13ad2097df | ||
|
|
45b9c6516b | ||
|
|
e3873f616e | ||
|
|
f26a94076c | ||
|
|
0f92f0d00c | ||
|
|
c118e5c3dc | ||
|
|
743d3b8c2f | ||
|
|
0f88aeb06f | ||
|
|
76b64a30ae | ||
|
|
1b9119e606 | ||
|
|
3fa236cff5 | ||
|
|
b56f604890 | ||
|
|
c5aa195b13 | ||
|
|
5442f1beb6 | ||
|
|
af14610442 | ||
|
|
45941fbe6c | ||
|
|
21273fcaeb |
187 changed files with 13966 additions and 4038 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/bcrypt": "^5.0.2",
|
||||||
"@types/cors": "^2.8.17",
|
"@types/cors": "^2.8.17",
|
||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
|
"@types/jest": "^30.0.0",
|
||||||
"@types/jsonwebtoken": "^9.0.7",
|
"@types/jsonwebtoken": "^9.0.7",
|
||||||
"@types/multer": "^1.4.12",
|
"@types/multer": "^1.4.12",
|
||||||
"@types/node": "^22.10.5",
|
"@types/node": "^22.10.5",
|
||||||
|
|
|
||||||
171
Backend/pnpm-lock.yaml
generated
171
Backend/pnpm-lock.yaml
generated
|
|
@ -78,6 +78,9 @@ importers:
|
||||||
'@types/express':
|
'@types/express':
|
||||||
specifier: ^5.0.0
|
specifier: ^5.0.0
|
||||||
version: 5.0.6
|
version: 5.0.6
|
||||||
|
'@types/jest':
|
||||||
|
specifier: ^30.0.0
|
||||||
|
version: 30.0.0
|
||||||
'@types/jsonwebtoken':
|
'@types/jsonwebtoken':
|
||||||
specifier: ^9.0.7
|
specifier: ^9.0.7
|
||||||
version: 9.0.10
|
version: 9.0.10
|
||||||
|
|
@ -119,7 +122,7 @@ importers:
|
||||||
version: 7.2.2
|
version: 7.2.2
|
||||||
ts-jest:
|
ts-jest:
|
||||||
specifier: ^29.2.5
|
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:
|
tsconfig-paths:
|
||||||
specifier: ^4.2.0
|
specifier: ^4.2.0
|
||||||
version: 4.2.0
|
version: 4.2.0
|
||||||
|
|
@ -615,6 +618,10 @@ packages:
|
||||||
node-notifier:
|
node-notifier:
|
||||||
optional: true
|
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':
|
'@jest/environment@29.7.0':
|
||||||
resolution: {integrity: sha512-aQIfHDq33ExsN4jP1NWGXhxgQ/wixs60gDiKO+XVMd8Mn0NWPWgc34ZQDTb2jKaUWQ7MuwoitXAsN2XVXNMpAw==}
|
resolution: {integrity: sha512-aQIfHDq33ExsN4jP1NWGXhxgQ/wixs60gDiKO+XVMd8Mn0NWPWgc34ZQDTb2jKaUWQ7MuwoitXAsN2XVXNMpAw==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||||
|
|
@ -623,6 +630,10 @@ packages:
|
||||||
resolution: {integrity: sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==}
|
resolution: {integrity: sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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':
|
'@jest/expect@29.7.0':
|
||||||
resolution: {integrity: sha512-8uMeAMycttpva3P1lBHB8VciS9V0XAr3GymPpipdyQXbBcuhkLQOSe8E/p92RyAdToS6ZD1tFkX+CkhoECE0dQ==}
|
resolution: {integrity: sha512-8uMeAMycttpva3P1lBHB8VciS9V0XAr3GymPpipdyQXbBcuhkLQOSe8E/p92RyAdToS6ZD1tFkX+CkhoECE0dQ==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||||
|
|
@ -631,10 +642,18 @@ packages:
|
||||||
resolution: {integrity: sha512-q4DH1Ha4TTFPdxLsqDXK1d3+ioSL7yL5oCMJZgDYm6i+6CygW5E5xVr/D1HdsGxjt1ZWSfUAs9OxSB/BNelWrQ==}
|
resolution: {integrity: sha512-q4DH1Ha4TTFPdxLsqDXK1d3+ioSL7yL5oCMJZgDYm6i+6CygW5E5xVr/D1HdsGxjt1ZWSfUAs9OxSB/BNelWrQ==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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':
|
'@jest/globals@29.7.0':
|
||||||
resolution: {integrity: sha512-mpiz3dutLbkW2MNFubUGUEVLkTGiqW6yLVTA+JbP6fI6J5iL9Y0Nlg8k95pcF8ctKwCS7WVxteBs29hhfAotzQ==}
|
resolution: {integrity: sha512-mpiz3dutLbkW2MNFubUGUEVLkTGiqW6yLVTA+JbP6fI6J5iL9Y0Nlg8k95pcF8ctKwCS7WVxteBs29hhfAotzQ==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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':
|
'@jest/reporters@29.7.0':
|
||||||
resolution: {integrity: sha512-DApq0KJbJOEzAFYjHADNNxAE3KbhxQB1y5Kplb5Waqw6zVbuWatSnMjE5gs8FUgEPmNsnZA3NCWl9NG0ia04Pg==}
|
resolution: {integrity: sha512-DApq0KJbJOEzAFYjHADNNxAE3KbhxQB1y5Kplb5Waqw6zVbuWatSnMjE5gs8FUgEPmNsnZA3NCWl9NG0ia04Pg==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||||
|
|
@ -648,6 +667,10 @@ packages:
|
||||||
resolution: {integrity: sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==}
|
resolution: {integrity: sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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':
|
'@jest/source-map@29.6.3':
|
||||||
resolution: {integrity: sha512-MHjT95QuipcPrpLM+8JMSzFx6eHp5Bm+4XeFDJlwsvVBjmKNiIAvasGK2fxz2WbGRlnvqehFbh07MMa7n3YJnw==}
|
resolution: {integrity: sha512-MHjT95QuipcPrpLM+8JMSzFx6eHp5Bm+4XeFDJlwsvVBjmKNiIAvasGK2fxz2WbGRlnvqehFbh07MMa7n3YJnw==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||||
|
|
@ -668,6 +691,10 @@ packages:
|
||||||
resolution: {integrity: sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==}
|
resolution: {integrity: sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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':
|
'@jridgewell/gen-mapping@0.3.13':
|
||||||
resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==}
|
resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==}
|
||||||
|
|
||||||
|
|
@ -862,6 +889,9 @@ packages:
|
||||||
'@sinclair/typebox@0.27.8':
|
'@sinclair/typebox@0.27.8':
|
||||||
resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==}
|
resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==}
|
||||||
|
|
||||||
|
'@sinclair/typebox@0.34.48':
|
||||||
|
resolution: {integrity: sha512-kKJTNuK3AQOrgjjotVxMrCn1sUJwM76wMszfq1kdU4uYVJjvEWuFQ6HgvLt4Xz3fSmZlTOxJ/Ie13KnIcWQXFA==}
|
||||||
|
|
||||||
'@sinonjs/commons@3.0.1':
|
'@sinonjs/commons@3.0.1':
|
||||||
resolution: {integrity: sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==}
|
resolution: {integrity: sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==}
|
||||||
|
|
||||||
|
|
@ -1115,6 +1145,9 @@ packages:
|
||||||
'@types/istanbul-reports@3.0.4':
|
'@types/istanbul-reports@3.0.4':
|
||||||
resolution: {integrity: sha512-pk2B1NWalF9toCRu6gjBzR69syFjP4Od8WRAX+0mmf9lAjCRicLOWc+ZrxZHx/0XRjotgkF9t6iaMJ+aXcOdZQ==}
|
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':
|
'@types/json-schema@7.0.15':
|
||||||
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
|
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
|
||||||
|
|
||||||
|
|
@ -1433,6 +1466,10 @@ packages:
|
||||||
resolution: {integrity: sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==}
|
resolution: {integrity: sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|
||||||
|
ci-info@4.4.0:
|
||||||
|
resolution: {integrity: sha512-77PSwercCZU2Fc4sX94eF8k8Pxte6JAwL4/ICZLFjJLqegs7kCuAsqqj/70NQF6TvDpgFjkubQB2FW2ZZddvQg==}
|
||||||
|
engines: {node: '>=8'}
|
||||||
|
|
||||||
cjs-module-lexer@1.4.3:
|
cjs-module-lexer@1.4.3:
|
||||||
resolution: {integrity: sha512-9z8TZaGM1pfswYeXrUpzPrkx8UnWYdhJclsiYMm6x/w5+nN+8Tf/LnAgfLGQCm59qAOxU8WwHEq2vNwF6i4j+Q==}
|
resolution: {integrity: sha512-9z8TZaGM1pfswYeXrUpzPrkx8UnWYdhJclsiYMm6x/w5+nN+8Tf/LnAgfLGQCm59qAOxU8WwHEq2vNwF6i4j+Q==}
|
||||||
|
|
||||||
|
|
@ -1729,6 +1766,10 @@ packages:
|
||||||
resolution: {integrity: sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==}
|
resolution: {integrity: sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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:
|
express-rate-limit@7.5.1:
|
||||||
resolution: {integrity: sha512-7iN8iPMDzOMHPUYllBEsQdWVB6fPDMPqwjBaFrgr4Jgr/+okjvzAy+UHlYYL/Vs0OsOrMkwS6PJDkFlJwoxUnw==}
|
resolution: {integrity: sha512-7iN8iPMDzOMHPUYllBEsQdWVB6fPDMPqwjBaFrgr4Jgr/+okjvzAy+UHlYYL/Vs0OsOrMkwS6PJDkFlJwoxUnw==}
|
||||||
engines: {node: '>= 16'}
|
engines: {node: '>= 16'}
|
||||||
|
|
@ -2118,6 +2159,10 @@ packages:
|
||||||
resolution: {integrity: sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==}
|
resolution: {integrity: sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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:
|
jest-docblock@29.7.0:
|
||||||
resolution: {integrity: sha512-q617Auw3A612guyaFgsbFeYpNP5t2aoUNLwBUbc/0kD1R4t9ixDbyFTHd1nok4epoVFpr7PmeWHrhvuV3XaJ4g==}
|
resolution: {integrity: sha512-q617Auw3A612guyaFgsbFeYpNP5t2aoUNLwBUbc/0kD1R4t9ixDbyFTHd1nok4epoVFpr7PmeWHrhvuV3XaJ4g==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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==}
|
resolution: {integrity: sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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:
|
jest-message-util@29.7.0:
|
||||||
resolution: {integrity: sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w==}
|
resolution: {integrity: sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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:
|
jest-mock@29.7.0:
|
||||||
resolution: {integrity: sha512-ITOMZn+UkYS4ZFh83xYAOzWStloNzJFO2s8DWrE4lhtGD+AorgnbkiKERe4wQVBydIGPx059g6riW5Btp6Llnw==}
|
resolution: {integrity: sha512-ITOMZn+UkYS4ZFh83xYAOzWStloNzJFO2s8DWrE4lhtGD+AorgnbkiKERe4wQVBydIGPx059g6riW5Btp6Llnw==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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:
|
jest-pnp-resolver@1.2.3:
|
||||||
resolution: {integrity: sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==}
|
resolution: {integrity: sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|
@ -2167,6 +2224,10 @@ packages:
|
||||||
resolution: {integrity: sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==}
|
resolution: {integrity: sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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:
|
jest-resolve-dependencies@29.7.0:
|
||||||
resolution: {integrity: sha512-un0zD/6qxJ+S0et7WxeI3H5XSe9lTBBR7bOHCHXkKR6luG5mwDDlIzVQ0V5cZCuoTgEdcdwzTghYkTWfubi+nA==}
|
resolution: {integrity: sha512-un0zD/6qxJ+S0et7WxeI3H5XSe9lTBBR7bOHCHXkKR6luG5mwDDlIzVQ0V5cZCuoTgEdcdwzTghYkTWfubi+nA==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||||
|
|
@ -2191,6 +2252,10 @@ packages:
|
||||||
resolution: {integrity: sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==}
|
resolution: {integrity: sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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:
|
jest-validate@29.7.0:
|
||||||
resolution: {integrity: sha512-ZB7wHqaRGVw/9hST/OuFUReG7M8vKeq0/J2egIGLdvjHCmYqGARhzXmtgi+gVeZ5uXFF219aOc3Ls2yLg27tkw==}
|
resolution: {integrity: sha512-ZB7wHqaRGVw/9hST/OuFUReG7M8vKeq0/J2egIGLdvjHCmYqGARhzXmtgi+gVeZ5uXFF219aOc3Ls2yLg27tkw==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
||||||
|
|
@ -2584,6 +2649,10 @@ packages:
|
||||||
resolution: {integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==}
|
resolution: {integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==}
|
||||||
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
|
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:
|
prisma@5.22.0:
|
||||||
resolution: {integrity: sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A==}
|
resolution: {integrity: sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A==}
|
||||||
engines: {node: '>=16.13'}
|
engines: {node: '>=16.13'}
|
||||||
|
|
@ -4027,6 +4096,8 @@ snapshots:
|
||||||
- supports-color
|
- supports-color
|
||||||
- ts-node
|
- ts-node
|
||||||
|
|
||||||
|
'@jest/diff-sequences@30.0.1': {}
|
||||||
|
|
||||||
'@jest/environment@29.7.0':
|
'@jest/environment@29.7.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jest/fake-timers': 29.7.0
|
'@jest/fake-timers': 29.7.0
|
||||||
|
|
@ -4038,6 +4109,10 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
jest-get-type: 29.6.3
|
jest-get-type: 29.6.3
|
||||||
|
|
||||||
|
'@jest/expect-utils@30.2.0':
|
||||||
|
dependencies:
|
||||||
|
'@jest/get-type': 30.1.0
|
||||||
|
|
||||||
'@jest/expect@29.7.0':
|
'@jest/expect@29.7.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
expect: 29.7.0
|
expect: 29.7.0
|
||||||
|
|
@ -4054,6 +4129,8 @@ snapshots:
|
||||||
jest-mock: 29.7.0
|
jest-mock: 29.7.0
|
||||||
jest-util: 29.7.0
|
jest-util: 29.7.0
|
||||||
|
|
||||||
|
'@jest/get-type@30.1.0': {}
|
||||||
|
|
||||||
'@jest/globals@29.7.0':
|
'@jest/globals@29.7.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jest/environment': 29.7.0
|
'@jest/environment': 29.7.0
|
||||||
|
|
@ -4063,6 +4140,11 @@ snapshots:
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
|
'@jest/pattern@30.0.1':
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 22.19.5
|
||||||
|
jest-regex-util: 30.0.1
|
||||||
|
|
||||||
'@jest/reporters@29.7.0':
|
'@jest/reporters@29.7.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@bcoe/v8-coverage': 0.2.3
|
'@bcoe/v8-coverage': 0.2.3
|
||||||
|
|
@ -4096,6 +4178,10 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@sinclair/typebox': 0.27.8
|
'@sinclair/typebox': 0.27.8
|
||||||
|
|
||||||
|
'@jest/schemas@30.0.5':
|
||||||
|
dependencies:
|
||||||
|
'@sinclair/typebox': 0.34.48
|
||||||
|
|
||||||
'@jest/source-map@29.6.3':
|
'@jest/source-map@29.6.3':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jridgewell/trace-mapping': 0.3.31
|
'@jridgewell/trace-mapping': 0.3.31
|
||||||
|
|
@ -4145,6 +4231,16 @@ snapshots:
|
||||||
'@types/yargs': 17.0.35
|
'@types/yargs': 17.0.35
|
||||||
chalk: 4.1.2
|
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':
|
'@jridgewell/gen-mapping@0.3.13':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jridgewell/sourcemap-codec': 1.5.5
|
'@jridgewell/sourcemap-codec': 1.5.5
|
||||||
|
|
@ -4316,6 +4412,8 @@ snapshots:
|
||||||
|
|
||||||
'@sinclair/typebox@0.27.8': {}
|
'@sinclair/typebox@0.27.8': {}
|
||||||
|
|
||||||
|
'@sinclair/typebox@0.34.48': {}
|
||||||
|
|
||||||
'@sinonjs/commons@3.0.1':
|
'@sinonjs/commons@3.0.1':
|
||||||
dependencies:
|
dependencies:
|
||||||
type-detect: 4.0.8
|
type-detect: 4.0.8
|
||||||
|
|
@ -4721,6 +4819,11 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/istanbul-lib-report': 3.0.3
|
'@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/json-schema@7.0.15': {}
|
||||||
|
|
||||||
'@types/jsonwebtoken@9.0.10':
|
'@types/jsonwebtoken@9.0.10':
|
||||||
|
|
@ -5116,6 +5219,8 @@ snapshots:
|
||||||
|
|
||||||
ci-info@3.9.0: {}
|
ci-info@3.9.0: {}
|
||||||
|
|
||||||
|
ci-info@4.4.0: {}
|
||||||
|
|
||||||
cjs-module-lexer@1.4.3: {}
|
cjs-module-lexer@1.4.3: {}
|
||||||
|
|
||||||
cliui@8.0.1:
|
cliui@8.0.1:
|
||||||
|
|
@ -5398,6 +5503,15 @@ snapshots:
|
||||||
jest-message-util: 29.7.0
|
jest-message-util: 29.7.0
|
||||||
jest-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):
|
express-rate-limit@7.5.1(express@4.22.1):
|
||||||
dependencies:
|
dependencies:
|
||||||
express: 4.22.1
|
express: 4.22.1
|
||||||
|
|
@ -5872,6 +5986,13 @@ snapshots:
|
||||||
jest-get-type: 29.6.3
|
jest-get-type: 29.6.3
|
||||||
pretty-format: 29.7.0
|
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:
|
jest-docblock@29.7.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
detect-newline: 3.1.0
|
detect-newline: 3.1.0
|
||||||
|
|
@ -5923,6 +6044,13 @@ snapshots:
|
||||||
jest-get-type: 29.6.3
|
jest-get-type: 29.6.3
|
||||||
pretty-format: 29.7.0
|
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:
|
jest-message-util@29.7.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/code-frame': 7.27.1
|
'@babel/code-frame': 7.27.1
|
||||||
|
|
@ -5935,18 +6063,38 @@ snapshots:
|
||||||
slash: 3.0.0
|
slash: 3.0.0
|
||||||
stack-utils: 2.0.6
|
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:
|
jest-mock@29.7.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jest/types': 29.6.3
|
'@jest/types': 29.6.3
|
||||||
'@types/node': 22.19.5
|
'@types/node': 22.19.5
|
||||||
jest-util: 29.7.0
|
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):
|
jest-pnp-resolver@1.2.3(jest-resolve@29.7.0):
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
jest-resolve: 29.7.0
|
jest-resolve: 29.7.0
|
||||||
|
|
||||||
jest-regex-util@29.6.3: {}
|
jest-regex-util@29.6.3: {}
|
||||||
|
|
||||||
|
jest-regex-util@30.0.1: {}
|
||||||
|
|
||||||
jest-resolve-dependencies@29.7.0:
|
jest-resolve-dependencies@29.7.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
jest-regex-util: 29.6.3
|
jest-regex-util: 29.6.3
|
||||||
|
|
@ -6053,6 +6201,15 @@ snapshots:
|
||||||
graceful-fs: 4.2.11
|
graceful-fs: 4.2.11
|
||||||
picomatch: 2.3.1
|
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:
|
jest-validate@29.7.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@jest/types': 29.6.3
|
'@jest/types': 29.6.3
|
||||||
|
|
@ -6444,6 +6601,12 @@ snapshots:
|
||||||
ansi-styles: 5.2.0
|
ansi-styles: 5.2.0
|
||||||
react-is: 18.3.1
|
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:
|
prisma@5.22.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@prisma/engines': 5.22.0
|
'@prisma/engines': 5.22.0
|
||||||
|
|
@ -6797,7 +6960,7 @@ snapshots:
|
||||||
|
|
||||||
ts-deepmerge@7.0.3: {}
|
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:
|
dependencies:
|
||||||
bs-logger: 0.2.6
|
bs-logger: 0.2.6
|
||||||
fast-json-stable-stringify: 2.1.0
|
fast-json-stable-stringify: 2.1.0
|
||||||
|
|
@ -6813,9 +6976,9 @@ snapshots:
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@babel/core': 7.28.5
|
'@babel/core': 7.28.5
|
||||||
'@jest/transform': 29.7.0
|
'@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)
|
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:
|
tsconfig-paths@4.2.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { Body, Get, Path, Post, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa';
|
import { Body, Get, Path, Post, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa';
|
||||||
import { ValidationError } from '../middleware/errorHandler';
|
import { ValidationError } from '../middleware/errorHandler';
|
||||||
import { AdminCourseApprovalService } from '../services/AdminCourseApproval.service';
|
import { AdminCourseApprovalService } from '../services/AdminCourseApproval.service';
|
||||||
|
import { RejectCourseValidator } from '../validators/AdminCourseApproval.validator';
|
||||||
import {
|
import {
|
||||||
ListPendingCoursesResponse,
|
ListPendingCoursesResponse,
|
||||||
GetCourseDetailForAdminResponse,
|
GetCourseDetailForAdminResponse,
|
||||||
ApproveCourseBody,
|
|
||||||
ApproveCourseResponse,
|
ApproveCourseResponse,
|
||||||
RejectCourseBody,
|
RejectCourseBody,
|
||||||
RejectCourseResponse,
|
RejectCourseResponse,
|
||||||
|
|
@ -24,9 +24,7 @@ export class AdminCourseApprovalController {
|
||||||
@Response('401', 'Unauthorized')
|
@Response('401', 'Unauthorized')
|
||||||
@Response('403', 'Forbidden - Admin only')
|
@Response('403', 'Forbidden - Admin only')
|
||||||
public async listPendingCourses(@Request() request: any): Promise<ListPendingCoursesResponse> {
|
public async listPendingCourses(@Request() request: any): Promise<ListPendingCoursesResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await AdminCourseApprovalService.listPendingCourses(request.user.id);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await AdminCourseApprovalService.listPendingCourses(token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,9 +39,7 @@ export class AdminCourseApprovalController {
|
||||||
@Response('403', 'Forbidden - Admin only')
|
@Response('403', 'Forbidden - Admin only')
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async getCourseDetail(@Request() request: any, @Path() courseId: number): Promise<GetCourseDetailForAdminResponse> {
|
public async getCourseDetail(@Request() request: any, @Path() courseId: number): Promise<GetCourseDetailForAdminResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await AdminCourseApprovalService.getCourseDetail(request.user.id, courseId);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await AdminCourseApprovalService.getCourseDetail(token, courseId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -60,12 +56,9 @@ export class AdminCourseApprovalController {
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async approveCourse(
|
public async approveCourse(
|
||||||
@Request() request: any,
|
@Request() request: any,
|
||||||
@Path() courseId: number,
|
@Path() courseId: number
|
||||||
@Body() body?: ApproveCourseBody
|
|
||||||
): Promise<ApproveCourseResponse> {
|
): Promise<ApproveCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await AdminCourseApprovalService.approveCourse(request.user.id, courseId, undefined);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await AdminCourseApprovalService.approveCourse(token, courseId, body?.comment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -85,8 +78,10 @@ export class AdminCourseApprovalController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Body() body: RejectCourseBody
|
@Body() body: RejectCourseBody
|
||||||
): Promise<RejectCourseResponse> {
|
): Promise<RejectCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
// Validate body
|
||||||
if (!token) throw new ValidationError('No token provided');
|
const { error } = RejectCourseValidator.validate(body);
|
||||||
return await AdminCourseApprovalService.rejectCourse(token, courseId, body.comment);
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
|
return await AdminCourseApprovalService.rejectCourse(request.user.id, courseId, body.comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,6 @@ export class AuditController {
|
||||||
@Query() page?: number,
|
@Query() page?: number,
|
||||||
@Query() limit?: number
|
@Query() limit?: number
|
||||||
): Promise<ListAuditLogsResponse> {
|
): Promise<ListAuditLogsResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await auditService.getLogs({
|
return await auditService.getLogs({
|
||||||
userId,
|
userId,
|
||||||
action,
|
action,
|
||||||
|
|
@ -72,11 +67,6 @@ export class AuditController {
|
||||||
@Request() request: any,
|
@Request() request: any,
|
||||||
@Path() logId: number
|
@Path() logId: number
|
||||||
): Promise<AuditLogResponse> {
|
): Promise<AuditLogResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
|
|
||||||
const log = await auditService.getLogById(logId);
|
const log = await auditService.getLogById(logId);
|
||||||
if (!log) {
|
if (!log) {
|
||||||
throw new ValidationError('Audit log not found');
|
throw new ValidationError('Audit log not found');
|
||||||
|
|
@ -94,11 +84,6 @@ export class AuditController {
|
||||||
@Response('401', 'Unauthorized')
|
@Response('401', 'Unauthorized')
|
||||||
@Response('403', 'Forbidden - Admin only')
|
@Response('403', 'Forbidden - Admin only')
|
||||||
public async getAuditStats(@Request() request: any): Promise<AuditLogStats> {
|
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();
|
return await auditService.getStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,11 +103,6 @@ export class AuditController {
|
||||||
@Path() entityType: string,
|
@Path() entityType: string,
|
||||||
@Path() entityId: number
|
@Path() entityId: number
|
||||||
): Promise<AuditLogResponse[]> {
|
): Promise<AuditLogResponse[]> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await auditService.getEntityHistory(entityType, entityId);
|
return await auditService.getEntityHistory(entityType, entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,11 +122,6 @@ export class AuditController {
|
||||||
@Path() userId: number,
|
@Path() userId: number,
|
||||||
@Query() limit?: number
|
@Query() limit?: number
|
||||||
): Promise<AuditLogResponse[]> {
|
): Promise<AuditLogResponse[]> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await auditService.getUserActivity(userId, limit || 50);
|
return await auditService.getUserActivity(userId, limit || 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,13 +139,8 @@ export class AuditController {
|
||||||
@Request() request: any,
|
@Request() request: any,
|
||||||
@Query() days: number = 90
|
@Query() days: number = 90
|
||||||
): Promise<{ deleted: number; message: string }> {
|
): Promise<{ deleted: number; message: string }> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
if (days < 6) {
|
||||||
if (!token) {
|
throw new ValidationError('Cannot delete logs newer than 6 days');
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (days < 30) {
|
|
||||||
throw new ValidationError('Cannot delete logs newer than 30 days');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleted = await auditService.deleteOldLogs(days);
|
const deleted = await auditService.deleteOldLogs(days);
|
||||||
|
|
|
||||||
|
|
@ -33,32 +33,6 @@ export class AuthController {
|
||||||
data: {
|
data: {
|
||||||
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||||
refreshToken: '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> {
|
public async login(@Body() body: LoginRequest): Promise<LoginResponse> {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Delete, Contro
|
||||||
import { ValidationError } from '../middleware/errorHandler';
|
import { ValidationError } from '../middleware/errorHandler';
|
||||||
import { CategoryService } from '../services/categories.service';
|
import { CategoryService } from '../services/categories.service';
|
||||||
import { createCategory, createCategoryResponse, deleteCategoryResponse, updateCategory, updateCategoryResponse, ListCategoriesResponse } from '../types/categories.type';
|
import { createCategory, createCategoryResponse, deleteCategoryResponse, updateCategory, updateCategoryResponse, ListCategoriesResponse } from '../types/categories.type';
|
||||||
|
import { CreateCategoryValidator, UpdateCategoryValidator } from '../validators/categories.validator';
|
||||||
|
|
||||||
@Route('api/categories')
|
@Route('api/categories')
|
||||||
@Tags('Categories')
|
@Tags('Categories')
|
||||||
|
|
@ -26,8 +27,11 @@ export class CategoriesAdminController {
|
||||||
@SuccessResponse('200', 'Category created successfully')
|
@SuccessResponse('200', 'Category created successfully')
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
public async createCategory(@Request() request: any, @Body() body: createCategory): Promise<createCategoryResponse> {
|
public async createCategory(@Request() request: any, @Body() body: createCategory): Promise<createCategoryResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '') || '';
|
// Validate body
|
||||||
return await this.categoryService.createCategory(token, body);
|
const { error } = CreateCategoryValidator.validate(body);
|
||||||
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
|
return await this.categoryService.createCategory(request.user.id, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('{id}')
|
@Put('{id}')
|
||||||
|
|
@ -35,8 +39,11 @@ export class CategoriesAdminController {
|
||||||
@SuccessResponse('200', 'Category updated successfully')
|
@SuccessResponse('200', 'Category updated successfully')
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
public async updateCategory(@Request() request: any, @Body() body: updateCategory): Promise<updateCategoryResponse> {
|
public async updateCategory(@Request() request: any, @Body() body: updateCategory): Promise<updateCategoryResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '') || '';
|
// Validate body
|
||||||
return await this.categoryService.updateCategory(token, body.id, body);
|
const { error } = UpdateCategoryValidator.validate(body);
|
||||||
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
|
return await this.categoryService.updateCategory(request.user.id, body.id, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('{id}')
|
@Delete('{id}')
|
||||||
|
|
@ -44,7 +51,6 @@ export class CategoriesAdminController {
|
||||||
@SuccessResponse('200', 'Category deleted successfully')
|
@SuccessResponse('200', 'Category deleted successfully')
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
public async deleteCategory(@Request() request: any, @Path() id: number): Promise<deleteCategoryResponse> {
|
public async deleteCategory(@Request() request: any, @Path() id: number): Promise<deleteCategoryResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '') || '';
|
return await this.categoryService.deleteCategory(request.user.id, id);
|
||||||
return await this.categoryService.deleteCategory(token,id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { Get, Post, Route, Tags, SuccessResponse, Response, Security, Path, Request } from 'tsoa';
|
import { Get, Post, Route, Tags, SuccessResponse, Response, Security, Path, Request } from 'tsoa';
|
||||||
import { ValidationError } from '../middleware/errorHandler';
|
|
||||||
import { CertificateService } from '../services/certificate.service';
|
import { CertificateService } from '../services/certificate.service';
|
||||||
import {
|
import {
|
||||||
GenerateCertificateResponse,
|
GenerateCertificateResponse,
|
||||||
|
|
@ -21,9 +20,7 @@ export class CertificateController {
|
||||||
@SuccessResponse('200', 'Certificates retrieved successfully')
|
@SuccessResponse('200', 'Certificates retrieved successfully')
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
public async listMyCertificates(@Request() request: any): Promise<ListMyCertificatesResponse> {
|
public async listMyCertificates(@Request() request: any): Promise<ListMyCertificatesResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.certificateService.listMyCertificates({ userId: request.user.id });
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await this.certificateService.listMyCertificates({ token });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,9 +34,7 @@ export class CertificateController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Certificate not found')
|
@Response('404', 'Certificate not found')
|
||||||
public async getCertificate(@Request() request: any, @Path() courseId: number): Promise<GetCertificateResponse> {
|
public async getCertificate(@Request() request: any, @Path() courseId: number): Promise<GetCertificateResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.certificateService.getCertificate({ userId: request.user.id, course_id: courseId });
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await this.certificateService.getCertificate({ token, course_id: courseId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,8 +49,6 @@ export class CertificateController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Enrollment not found')
|
@Response('404', 'Enrollment not found')
|
||||||
public async generateCertificate(@Request() request: any, @Path() courseId: number): Promise<GenerateCertificateResponse> {
|
public async generateCertificate(@Request() request: any, @Path() courseId: number): Promise<GenerateCertificateResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.certificateService.generateCertificate({ userId: request.user.id, course_id: courseId });
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await this.certificateService.generateCertificate({ token, course_id: courseId });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,18 @@ import {
|
||||||
UpdateQuizResponse,
|
UpdateQuizResponse,
|
||||||
UpdateQuizBody,
|
UpdateQuizBody,
|
||||||
} from '../types/ChaptersLesson.typs';
|
} from '../types/ChaptersLesson.typs';
|
||||||
|
import {
|
||||||
|
CreateChapterValidator,
|
||||||
|
UpdateChapterValidator,
|
||||||
|
ReorderChapterValidator,
|
||||||
|
CreateLessonValidator,
|
||||||
|
UpdateLessonValidator,
|
||||||
|
ReorderLessonsValidator,
|
||||||
|
AddQuestionValidator,
|
||||||
|
UpdateQuestionValidator,
|
||||||
|
ReorderQuestionValidator,
|
||||||
|
UpdateQuizValidator
|
||||||
|
} from '../validators/ChaptersLesson.validator';
|
||||||
|
|
||||||
const chaptersLessonService = new ChaptersLessonService();
|
const chaptersLessonService = new ChaptersLessonService();
|
||||||
|
|
||||||
|
|
@ -53,10 +65,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Body() body: CreateChapterBody
|
@Body() body: CreateChapterBody
|
||||||
): Promise<CreateChapterResponse> {
|
): Promise<CreateChapterResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = CreateChapterValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.createChapter({
|
return await chaptersLessonService.createChapter({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
title: body.title,
|
title: body.title,
|
||||||
description: body.description,
|
description: body.description,
|
||||||
|
|
@ -80,10 +93,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() chapterId: number,
|
@Path() chapterId: number,
|
||||||
@Body() body: UpdateChapterBody
|
@Body() body: UpdateChapterBody
|
||||||
): Promise<UpdateChapterResponse> {
|
): Promise<UpdateChapterResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = UpdateChapterValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.updateChapter({
|
return await chaptersLessonService.updateChapter({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
chapter_id: chapterId,
|
chapter_id: chapterId,
|
||||||
...body,
|
...body,
|
||||||
|
|
@ -105,9 +119,7 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Path() chapterId: number
|
@Path() chapterId: number
|
||||||
): Promise<DeleteChapterResponse> {
|
): Promise<DeleteChapterResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await chaptersLessonService.deleteChapter({ userId: request.user.id, course_id: courseId, chapter_id: chapterId });
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await chaptersLessonService.deleteChapter({ token, course_id: courseId, chapter_id: chapterId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -123,10 +135,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() chapterId: number,
|
@Path() chapterId: number,
|
||||||
@Body() body: ReorderChapterBody
|
@Body() body: ReorderChapterBody
|
||||||
): Promise<ReorderChapterResponse> {
|
): Promise<ReorderChapterResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = ReorderChapterValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.reorderChapter({
|
return await chaptersLessonService.reorderChapter({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
chapter_id: chapterId,
|
chapter_id: chapterId,
|
||||||
sort_order: body.sort_order,
|
sort_order: body.sort_order,
|
||||||
|
|
@ -150,9 +163,7 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() chapterId: number,
|
@Path() chapterId: number,
|
||||||
@Path() lessonId: number
|
@Path() lessonId: number
|
||||||
): Promise<GetLessonResponse> {
|
): Promise<GetLessonResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await chaptersLessonService.getLesson({ userId: request.user.id, course_id: courseId, chapter_id: chapterId, lesson_id: lessonId });
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await chaptersLessonService.getLesson({ token, course_id: courseId, chapter_id: chapterId, lesson_id: lessonId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -168,10 +179,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() chapterId: number,
|
@Path() chapterId: number,
|
||||||
@Body() body: CreateLessonBody
|
@Body() body: CreateLessonBody
|
||||||
): Promise<CreateLessonResponse> {
|
): Promise<CreateLessonResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = CreateLessonValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.createLesson({
|
return await chaptersLessonService.createLesson({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
chapter_id: chapterId,
|
chapter_id: chapterId,
|
||||||
title: body.title,
|
title: body.title,
|
||||||
|
|
@ -195,10 +207,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@Body() body: UpdateLessonBody
|
@Body() body: UpdateLessonBody
|
||||||
): Promise<UpdateLessonResponse> {
|
): Promise<UpdateLessonResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = UpdateLessonValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.updateLesson({
|
return await chaptersLessonService.updateLesson({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
chapter_id: chapterId,
|
chapter_id: chapterId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
|
|
@ -226,9 +239,7 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() chapterId: number,
|
@Path() chapterId: number,
|
||||||
@Path() lessonId: number
|
@Path() lessonId: number
|
||||||
): Promise<DeleteLessonResponse> {
|
): Promise<DeleteLessonResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await chaptersLessonService.deleteLesson({ userId: request.user.id, course_id: courseId, chapter_id: chapterId, lesson_id: lessonId });
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await chaptersLessonService.deleteLesson({ token, course_id: courseId, chapter_id: chapterId, lesson_id: lessonId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -244,10 +255,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() chapterId: number,
|
@Path() chapterId: number,
|
||||||
@Body() body: ReorderLessonsBody
|
@Body() body: ReorderLessonsBody
|
||||||
): Promise<ReorderLessonsResponse> {
|
): Promise<ReorderLessonsResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = ReorderLessonsValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.reorderLessons({
|
return await chaptersLessonService.reorderLessons({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
chapter_id: chapterId,
|
chapter_id: chapterId,
|
||||||
lesson_id: body.lesson_id,
|
lesson_id: body.lesson_id,
|
||||||
|
|
@ -273,10 +285,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@Body() body: AddQuestionBody
|
@Body() body: AddQuestionBody
|
||||||
): Promise<AddQuestionResponse> {
|
): Promise<AddQuestionResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = AddQuestionValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.addQuestion({
|
return await chaptersLessonService.addQuestion({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
...body,
|
...body,
|
||||||
|
|
@ -298,10 +311,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() questionId: number,
|
@Path() questionId: number,
|
||||||
@Body() body: UpdateQuestionBody
|
@Body() body: UpdateQuestionBody
|
||||||
): Promise<UpdateQuestionResponse> {
|
): Promise<UpdateQuestionResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = UpdateQuestionValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.updateQuestion({
|
return await chaptersLessonService.updateQuestion({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
question_id: questionId,
|
question_id: questionId,
|
||||||
|
|
@ -320,10 +334,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() questionId: number,
|
@Path() questionId: number,
|
||||||
@Body() body: ReorderQuestionBody
|
@Body() body: ReorderQuestionBody
|
||||||
): Promise<ReorderQuestionResponse> {
|
): Promise<ReorderQuestionResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = ReorderQuestionValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.reorderQuestion({
|
return await chaptersLessonService.reorderQuestion({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
question_id: questionId,
|
question_id: questionId,
|
||||||
|
|
@ -345,10 +360,8 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@Path() questionId: number
|
@Path() questionId: number
|
||||||
): Promise<DeleteQuestionResponse> {
|
): Promise<DeleteQuestionResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await chaptersLessonService.deleteQuestion({
|
return await chaptersLessonService.deleteQuestion({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
question_id: questionId,
|
question_id: questionId,
|
||||||
|
|
@ -369,10 +382,11 @@ export class ChaptersLessonInstructorController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@Body() body: UpdateQuizBody
|
@Body() body: UpdateQuizBody
|
||||||
): Promise<UpdateQuizResponse> {
|
): Promise<UpdateQuizResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = UpdateQuizValidator.validate(body);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await chaptersLessonService.updateQuiz({
|
return await chaptersLessonService.updateQuiz({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
...body,
|
...body,
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,29 @@ import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Security, Put,
|
||||||
import { ValidationError } from '../middleware/errorHandler';
|
import { ValidationError } from '../middleware/errorHandler';
|
||||||
import { CoursesInstructorService } from '../services/CoursesInstructor.service';
|
import { CoursesInstructorService } from '../services/CoursesInstructor.service';
|
||||||
import {
|
import {
|
||||||
createCourses,
|
|
||||||
createCourseResponse,
|
createCourseResponse,
|
||||||
GetMyCourseResponse,
|
|
||||||
ListMyCourseResponse,
|
ListMyCourseResponse,
|
||||||
addinstructorCourseResponse,
|
GetMyCourseResponse,
|
||||||
removeinstructorCourseResponse,
|
|
||||||
setprimaryCourseInstructorResponse,
|
|
||||||
UpdateMyCourse,
|
UpdateMyCourse,
|
||||||
UpdateMyCourseResponse,
|
UpdateMyCourseResponse,
|
||||||
DeleteMyCourseResponse,
|
DeleteMyCourseResponse,
|
||||||
submitCourseResponse,
|
submitCourseResponse,
|
||||||
listinstructorCourseResponse,
|
listinstructorCourseResponse,
|
||||||
GetCourseApprovalsResponse,
|
addinstructorCourseResponse,
|
||||||
SearchInstructorResponse,
|
removeinstructorCourseResponse,
|
||||||
|
setprimaryCourseInstructorResponse,
|
||||||
GetEnrolledStudentsResponse,
|
GetEnrolledStudentsResponse,
|
||||||
|
GetEnrolledStudentDetailResponse,
|
||||||
GetQuizScoresResponse,
|
GetQuizScoresResponse,
|
||||||
GetQuizAttemptDetailResponse,
|
GetQuizAttemptDetailResponse,
|
||||||
GetEnrolledStudentDetailResponse,
|
GetCourseApprovalsResponse,
|
||||||
|
SearchInstructorResponse,
|
||||||
GetCourseApprovalHistoryResponse,
|
GetCourseApprovalHistoryResponse,
|
||||||
setCourseDraftResponse,
|
setCourseDraftResponse,
|
||||||
|
CloneCourseResponse,
|
||||||
|
GetAllMyStudentsResponse,
|
||||||
} from '../types/CoursesInstructor.types';
|
} from '../types/CoursesInstructor.types';
|
||||||
import { CreateCourseValidator } from "../validators/CoursesInstructor.validator";
|
import { CreateCourseValidator, UpdateCourseValidator, CloneCourseValidator } from "../validators/CoursesInstructor.validator";
|
||||||
|
|
||||||
import jwt from 'jsonwebtoken';
|
|
||||||
import { config } from '../config';
|
|
||||||
|
|
||||||
@Route('api/instructors/courses')
|
@Route('api/instructors/courses')
|
||||||
@Tags('CoursesInstructor')
|
@Tags('CoursesInstructor')
|
||||||
|
|
@ -41,12 +39,11 @@ export class CoursesInstructorController {
|
||||||
@SuccessResponse('200', 'Courses retrieved successfully')
|
@SuccessResponse('200', 'Courses retrieved successfully')
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Courses not found')
|
@Response('404', 'Courses not found')
|
||||||
public async listMyCourses(@Request() request: any): Promise<ListMyCourseResponse> {
|
public async listMyCourses(
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
@Request() request: any,
|
||||||
if (!token) {
|
@Query() status?: 'DRAFT' | 'PENDING' | 'APPROVED' | 'REJECTED' | 'ARCHIVED'
|
||||||
throw new ValidationError('No token provided');
|
): Promise<ListMyCourseResponse> {
|
||||||
}
|
return await CoursesInstructorService.listMyCourses({ userId: request.user.id, status });
|
||||||
return await CoursesInstructorService.listMyCourses(token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -64,9 +61,23 @@ export class CoursesInstructorController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Query() query: string
|
@Query() query: string
|
||||||
): Promise<SearchInstructorResponse> {
|
): Promise<SearchInstructorResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.searchInstructors({ userId: request.user.id, query, course_id: courseId });
|
||||||
if (!token) throw new ValidationError('No token provided');
|
}
|
||||||
return await CoursesInstructorService.searchInstructors({ token, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -80,11 +91,7 @@ export class CoursesInstructorController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async getMyCourse(@Request() request: any, @Path() courseId: number): Promise<GetMyCourseResponse> {
|
public async getMyCourse(@Request() request: any, @Path() courseId: number): Promise<GetMyCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.getmyCourse({ userId: request.user.id, course_id: courseId });
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await CoursesInstructorService.getmyCourse({ token, course_id: courseId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -98,11 +105,10 @@ export class CoursesInstructorController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async updateCourse(@Request() request: any, @Path() courseId: number, @Body() body: UpdateMyCourse): Promise<UpdateMyCourseResponse> {
|
public async updateCourse(@Request() request: any, @Path() courseId: number, @Body() body: UpdateMyCourse): Promise<UpdateMyCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
const { error } = UpdateCourseValidator.validate(body.data);
|
||||||
if (!token) {
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
return await CoursesInstructorService.updateCourse(request.user.id, courseId, body.data);
|
||||||
return await CoursesInstructorService.updateCourse(token, courseId, body.data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -121,10 +127,6 @@ export class CoursesInstructorController {
|
||||||
@FormField() data: string,
|
@FormField() data: string,
|
||||||
@UploadedFile() thumbnail?: Express.Multer.File
|
@UploadedFile() thumbnail?: Express.Multer.File
|
||||||
): Promise<createCourseResponse> {
|
): 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 parsed = JSON.parse(data);
|
||||||
const { error, value } = CreateCourseValidator.validate(parsed);
|
const { error, value } = CreateCourseValidator.validate(parsed);
|
||||||
if (error) throw new ValidationError(error.details[0].message);
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
@ -132,7 +134,7 @@ export class CoursesInstructorController {
|
||||||
// Validate thumbnail file type if provided
|
// Validate thumbnail file type if provided
|
||||||
if (thumbnail && !thumbnail.mimetype?.startsWith('image/')) throw new ValidationError('Only image files are allowed for thumbnail');
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -151,11 +153,9 @@ export class CoursesInstructorController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@UploadedFile() file: Express.Multer.File
|
@UploadedFile() file: Express.Multer.File
|
||||||
): Promise<{ code: number; message: string; data: { course_id: number; thumbnail_url: string } }> {
|
): 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');
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -169,11 +169,36 @@ export class CoursesInstructorController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async deleteCourse(@Request() request: any, @Path() courseId: number): Promise<DeleteMyCourseResponse> {
|
public async deleteCourse(@Request() request: any, @Path() courseId: number): Promise<DeleteMyCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.deleteCourse(request.user.id, courseId);
|
||||||
if (!token) throw new ValidationError('No token provided')
|
|
||||||
return await CoursesInstructorService.deleteCourse(token, courseId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* คัดลอกคอร์ส (Clone Course)
|
||||||
|
* Clone an existing course to a new one with copied chapters, lessons, quizzes, and attachments
|
||||||
|
* @param courseId - รหัสคอร์สต้นฉบับ / Source Course ID
|
||||||
|
* @param body - ชื่อคอร์สใหม่ / New course title
|
||||||
|
*/
|
||||||
|
@Post('{courseId}/clone')
|
||||||
|
@Security('jwt', ['instructor'])
|
||||||
|
@SuccessResponse('201', 'Course cloned successfully')
|
||||||
|
@Response('401', 'Invalid or expired token')
|
||||||
|
@Response('403', 'Not an instructor of this course')
|
||||||
|
@Response('404', 'Course not found')
|
||||||
|
public async cloneCourse(
|
||||||
|
@Request() request: any,
|
||||||
|
@Path() courseId: number,
|
||||||
|
@Body() body: { title: { th: string; en: string } }
|
||||||
|
): Promise<CloneCourseResponse> {
|
||||||
|
const { error } = CloneCourseValidator.validate(body);
|
||||||
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
|
const result = await CoursesInstructorService.cloneCourse({
|
||||||
|
userId: request.user.id,
|
||||||
|
course_id: courseId,
|
||||||
|
title: body.title
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* ส่งคอร์สเพื่อขออนุมัติจากแอดมิน
|
* ส่งคอร์สเพื่อขออนุมัติจากแอดมิน
|
||||||
* Submit course for admin review and approval
|
* Submit course for admin review and approval
|
||||||
|
|
@ -185,9 +210,7 @@ export class CoursesInstructorController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async submitCourse(@Request() request: any, @Path() courseId: number): Promise<submitCourseResponse> {
|
public async submitCourse(@Request() request: any, @Path() courseId: number): Promise<submitCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.sendCourseForReview({ userId: request.user.id, course_id: courseId });
|
||||||
if (!token) throw new ValidationError('No token provided')
|
|
||||||
return await CoursesInstructorService.sendCourseForReview({ token, course_id: courseId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -201,9 +224,7 @@ export class CoursesInstructorController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async setCourseDraft(@Request() request: any, @Path() courseId: number): Promise<setCourseDraftResponse> {
|
public async setCourseDraft(@Request() request: any, @Path() courseId: number): Promise<setCourseDraftResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.setCourseDraft({ userId: request.user.id, course_id: courseId });
|
||||||
if (!token) throw new ValidationError('No token provided')
|
|
||||||
return await CoursesInstructorService.setCourseDraft({ token, course_id: courseId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -218,9 +239,7 @@ export class CoursesInstructorController {
|
||||||
@Response('403', 'You are not an instructor of this course')
|
@Response('403', 'You are not an instructor of this course')
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async getCourseApprovals(@Request() request: any, @Path() courseId: number): Promise<GetCourseApprovalsResponse> {
|
public async getCourseApprovals(@Request() request: any, @Path() courseId: number): Promise<GetCourseApprovalsResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.getCourseApprovals(request.user.id, courseId);
|
||||||
if (!token) throw new ValidationError('No token provided')
|
|
||||||
return await CoursesInstructorService.getCourseApprovals(token, courseId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -234,9 +253,7 @@ export class CoursesInstructorController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Instructors not found')
|
@Response('404', 'Instructors not found')
|
||||||
public async listInstructorCourses(@Request() request: any, @Path() courseId: number): Promise<listinstructorCourseResponse> {
|
public async listInstructorCourses(@Request() request: any, @Path() courseId: number): Promise<listinstructorCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.listInstructorsOfCourse({ userId: request.user.id, course_id: courseId });
|
||||||
if (!token) throw new ValidationError('No token provided')
|
|
||||||
return await CoursesInstructorService.listInstructorsOfCourse({ token, course_id: courseId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -251,9 +268,7 @@ export class CoursesInstructorController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Instructor not found')
|
@Response('404', 'Instructor not found')
|
||||||
public async addInstructor(@Request() request: any, @Path() courseId: number, @Path() emailOrUsername: string): Promise<addinstructorCourseResponse> {
|
public async addInstructor(@Request() request: any, @Path() courseId: number, @Path() emailOrUsername: string): Promise<addinstructorCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.addInstructorToCourse({ userId: request.user.id, course_id: courseId, email_or_username: emailOrUsername });
|
||||||
if (!token) throw new ValidationError('No token provided')
|
|
||||||
return await CoursesInstructorService.addInstructorToCourse({ token, course_id: courseId, email_or_username: emailOrUsername });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -268,9 +283,7 @@ export class CoursesInstructorController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Instructor not found')
|
@Response('404', 'Instructor not found')
|
||||||
public async removeInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<removeinstructorCourseResponse> {
|
public async removeInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<removeinstructorCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.removeInstructorFromCourse({ userId: request.user.id, course_id: courseId, user_id: userId });
|
||||||
if (!token) throw new ValidationError('No token provided')
|
|
||||||
return await CoursesInstructorService.removeInstructorFromCourse({ token, course_id: courseId, user_id: userId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -285,9 +298,7 @@ export class CoursesInstructorController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('404', 'Primary instructor not found')
|
@Response('404', 'Primary instructor not found')
|
||||||
public async setPrimaryInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<setprimaryCourseInstructorResponse> {
|
public async setPrimaryInstructor(@Request() request: any, @Path() courseId: number, @Path() userId: number): Promise<setprimaryCourseInstructorResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.setPrimaryInstructor({ userId: request.user.id, course_id: courseId, user_id: userId });
|
||||||
if (!token) throw new ValidationError('No token provided')
|
|
||||||
return await CoursesInstructorService.setPrimaryInstructor({ token, course_id: courseId, user_id: userId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -312,10 +323,8 @@ export class CoursesInstructorController {
|
||||||
@Query() search?: string,
|
@Query() search?: string,
|
||||||
@Query() status?: 'ENROLLED' | 'COMPLETED'
|
@Query() status?: 'ENROLLED' | 'COMPLETED'
|
||||||
): Promise<GetEnrolledStudentsResponse> {
|
): Promise<GetEnrolledStudentsResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await CoursesInstructorService.getEnrolledStudents({
|
return await CoursesInstructorService.getEnrolledStudents({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
page,
|
page,
|
||||||
limit,
|
limit,
|
||||||
|
|
@ -341,10 +350,8 @@ export class CoursesInstructorController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Path() studentId: number
|
@Path() studentId: number
|
||||||
): Promise<GetEnrolledStudentDetailResponse> {
|
): Promise<GetEnrolledStudentDetailResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await CoursesInstructorService.getEnrolledStudentDetail({
|
return await CoursesInstructorService.getEnrolledStudentDetail({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
student_id: studentId,
|
student_id: studentId,
|
||||||
});
|
});
|
||||||
|
|
@ -375,10 +382,8 @@ export class CoursesInstructorController {
|
||||||
@Query() search?: string,
|
@Query() search?: string,
|
||||||
@Query() isPassed?: boolean
|
@Query() isPassed?: boolean
|
||||||
): Promise<GetQuizScoresResponse> {
|
): Promise<GetQuizScoresResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await CoursesInstructorService.getQuizScores({
|
return await CoursesInstructorService.getQuizScores({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
page,
|
page,
|
||||||
|
|
@ -407,10 +412,8 @@ export class CoursesInstructorController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@Path() studentId: number
|
@Path() studentId: number
|
||||||
): Promise<GetQuizAttemptDetailResponse> {
|
): Promise<GetQuizAttemptDetailResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await CoursesInstructorService.getQuizAttemptDetail({
|
return await CoursesInstructorService.getQuizAttemptDetail({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
student_id: studentId,
|
student_id: studentId,
|
||||||
|
|
@ -432,8 +435,6 @@ export class CoursesInstructorController {
|
||||||
@Request() request: any,
|
@Request() request: any,
|
||||||
@Path() courseId: number
|
@Path() courseId: number
|
||||||
): Promise<GetCourseApprovalHistoryResponse> {
|
): Promise<GetCourseApprovalHistoryResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await CoursesInstructorService.getCourseApprovalHistory(request.user.id, courseId);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await CoursesInstructorService.getCourseApprovalHistory(token, courseId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,7 @@ import {
|
||||||
GetQuizAttemptsResponse,
|
GetQuizAttemptsResponse,
|
||||||
} from '../types/CoursesStudent.types';
|
} from '../types/CoursesStudent.types';
|
||||||
import { EnrollmentStatus } from '@prisma/client';
|
import { EnrollmentStatus } from '@prisma/client';
|
||||||
|
import { SaveVideoProgressValidator, SubmitQuizValidator } from '../validators/CoursesStudent.validator';
|
||||||
|
|
||||||
@Route('api/students')
|
@Route('api/students')
|
||||||
@Tags('CoursesStudent')
|
@Tags('CoursesStudent')
|
||||||
|
|
@ -35,11 +36,7 @@ export class CoursesStudentController {
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
@Response('409', 'Already enrolled in this course')
|
@Response('409', 'Already enrolled in this course')
|
||||||
public async enrollCourse(@Request() request: any, @Path() courseId: number): Promise<EnrollCourseResponse> {
|
public async enrollCourse(@Request() request: any, @Path() courseId: number): Promise<EnrollCourseResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.service.enrollCourse({ userId: request.user.id, course_id: courseId });
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await this.service.enrollCourse({ token, course_id: courseId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -59,11 +56,7 @@ export class CoursesStudentController {
|
||||||
@Query() limit?: number,
|
@Query() limit?: number,
|
||||||
@Query() status?: EnrollmentStatus
|
@Query() status?: EnrollmentStatus
|
||||||
): Promise<ListEnrolledCoursesResponse> {
|
): Promise<ListEnrolledCoursesResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.service.GetEnrolledCourses({ userId: request.user.id, page, limit, status });
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await this.service.GetEnrolledCourses({ token, page, limit, status });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -78,11 +71,7 @@ export class CoursesStudentController {
|
||||||
@Response('403', 'Not enrolled in this course')
|
@Response('403', 'Not enrolled in this course')
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async getCourseLearning(@Request() request: any, @Path() courseId: number): Promise<GetCourseLearningResponse> {
|
public async getCourseLearning(@Request() request: any, @Path() courseId: number): Promise<GetCourseLearningResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.service.getCourseLearning({ userId: request.user.id, course_id: courseId });
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await this.service.getCourseLearning({ token, course_id: courseId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -102,11 +91,7 @@ export class CoursesStudentController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Path() lessonId: number
|
@Path() lessonId: number
|
||||||
): Promise<GetLessonContentResponse> {
|
): Promise<GetLessonContentResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.service.getlessonContent({ userId: request.user.id, course_id: courseId, lesson_id: lessonId });
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await this.service.getlessonContent({ token, course_id: courseId, lesson_id: lessonId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -125,11 +110,7 @@ export class CoursesStudentController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Path() lessonId: number
|
@Path() lessonId: number
|
||||||
): Promise<CheckLessonAccessResponse> {
|
): Promise<CheckLessonAccessResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.service.checkAccessLesson({ userId: request.user.id, course_id: courseId, lesson_id: lessonId });
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await this.service.checkAccessLesson({ token, course_id: courseId, lesson_id: lessonId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -148,12 +129,12 @@ export class CoursesStudentController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@Body() body: SaveVideoProgressBody
|
@Body() body: SaveVideoProgressBody
|
||||||
): Promise<SaveVideoProgressResponse> {
|
): Promise<SaveVideoProgressResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) {
|
const { error } = SaveVideoProgressValidator.validate(body);
|
||||||
throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
}
|
|
||||||
return await this.service.saveVideoProgress({
|
return await this.service.saveVideoProgress({
|
||||||
token,
|
userId: request.user.id,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
video_progress_seconds: body.video_progress_seconds,
|
video_progress_seconds: body.video_progress_seconds,
|
||||||
video_duration_seconds: body.video_duration_seconds,
|
video_duration_seconds: body.video_duration_seconds,
|
||||||
|
|
@ -175,11 +156,7 @@ export class CoursesStudentController {
|
||||||
@Request() request: any,
|
@Request() request: any,
|
||||||
@Path() lessonId: number
|
@Path() lessonId: number
|
||||||
): Promise<GetVideoProgressResponse> {
|
): Promise<GetVideoProgressResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.service.getVideoProgress({ userId: request.user.id, lesson_id: lessonId });
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await this.service.getVideoProgress({ token, lesson_id: lessonId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -199,11 +176,7 @@ export class CoursesStudentController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Path() lessonId: number
|
@Path() lessonId: number
|
||||||
): Promise<CompleteLessonResponse> {
|
): Promise<CompleteLessonResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.service.completeLesson({ userId: request.user.id, lesson_id: lessonId });
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await this.service.completeLesson({ token, lesson_id: lessonId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -224,12 +197,12 @@ export class CoursesStudentController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@Body() body: SubmitQuizBody
|
@Body() body: SubmitQuizBody
|
||||||
): Promise<SubmitQuizResponse> {
|
): Promise<SubmitQuizResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) {
|
const { error } = SubmitQuizValidator.validate(body);
|
||||||
throw new ValidationError('No token provided');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
}
|
|
||||||
return await this.service.submitQuiz({
|
return await this.service.submitQuiz({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
answers: body.answers,
|
answers: body.answers,
|
||||||
|
|
@ -253,12 +226,8 @@ export class CoursesStudentController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Path() lessonId: number
|
@Path() lessonId: number
|
||||||
): Promise<GetQuizAttemptsResponse> {
|
): Promise<GetQuizAttemptsResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await this.service.getQuizAttempts({
|
return await this.service.getQuizAttempts({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import {
|
||||||
YouTubeVideoResponse,
|
YouTubeVideoResponse,
|
||||||
SetYouTubeVideoBody,
|
SetYouTubeVideoBody,
|
||||||
} from '../types/ChaptersLesson.typs';
|
} from '../types/ChaptersLesson.typs';
|
||||||
|
import { SetYouTubeVideoValidator } from '../validators/Lessons.validator';
|
||||||
|
|
||||||
const chaptersLessonService = new ChaptersLessonService();
|
const chaptersLessonService = new ChaptersLessonService();
|
||||||
|
|
||||||
|
|
@ -41,8 +42,6 @@ export class LessonsController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@UploadedFile() video: Express.Multer.File
|
@UploadedFile() video: Express.Multer.File
|
||||||
): Promise<VideoOperationResponse> {
|
): Promise<VideoOperationResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
|
|
||||||
if (!video) {
|
if (!video) {
|
||||||
throw new ValidationError('Video file is required');
|
throw new ValidationError('Video file is required');
|
||||||
|
|
@ -56,7 +55,7 @@ export class LessonsController {
|
||||||
};
|
};
|
||||||
|
|
||||||
return await chaptersLessonService.uploadVideo({
|
return await chaptersLessonService.uploadVideo({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
video: videoInfo,
|
video: videoInfo,
|
||||||
|
|
@ -86,8 +85,6 @@ export class LessonsController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@UploadedFile() video: Express.Multer.File
|
@UploadedFile() video: Express.Multer.File
|
||||||
): Promise<VideoOperationResponse> {
|
): Promise<VideoOperationResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
|
|
||||||
if (!video) {
|
if (!video) {
|
||||||
throw new ValidationError('Video file is required');
|
throw new ValidationError('Video file is required');
|
||||||
|
|
@ -101,7 +98,7 @@ export class LessonsController {
|
||||||
};
|
};
|
||||||
|
|
||||||
return await chaptersLessonService.updateVideo({
|
return await chaptersLessonService.updateVideo({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
video: videoInfo,
|
video: videoInfo,
|
||||||
|
|
@ -131,8 +128,6 @@ export class LessonsController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@UploadedFile() attachment: Express.Multer.File
|
@UploadedFile() attachment: Express.Multer.File
|
||||||
): Promise<AttachmentOperationResponse> {
|
): Promise<AttachmentOperationResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
|
|
||||||
if (!attachment) {
|
if (!attachment) {
|
||||||
throw new ValidationError('Attachment file is required');
|
throw new ValidationError('Attachment file is required');
|
||||||
|
|
@ -146,7 +141,7 @@ export class LessonsController {
|
||||||
};
|
};
|
||||||
|
|
||||||
return await chaptersLessonService.uploadAttachment({
|
return await chaptersLessonService.uploadAttachment({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
attachment: attachmentInfo,
|
attachment: attachmentInfo,
|
||||||
|
|
@ -176,11 +171,9 @@ export class LessonsController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@Path() attachmentId: number
|
@Path() attachmentId: number
|
||||||
): Promise<DeleteAttachmentResponse> {
|
): Promise<DeleteAttachmentResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
|
|
||||||
return await chaptersLessonService.deleteAttachment({
|
return await chaptersLessonService.deleteAttachment({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
attachment_id: attachmentId,
|
attachment_id: attachmentId,
|
||||||
|
|
@ -210,18 +203,12 @@ export class LessonsController {
|
||||||
@Path() lessonId: number,
|
@Path() lessonId: number,
|
||||||
@Body() body: SetYouTubeVideoBody
|
@Body() body: SetYouTubeVideoBody
|
||||||
): Promise<YouTubeVideoResponse> {
|
): Promise<YouTubeVideoResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
|
|
||||||
if (!body.youtube_video_id) {
|
const { error } = SetYouTubeVideoValidator.validate(body);
|
||||||
throw new ValidationError('YouTube video ID is required');
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
}
|
|
||||||
if (!body.video_title) {
|
|
||||||
throw new ValidationError('Video title is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await chaptersLessonService.setYouTubeVideo({
|
return await chaptersLessonService.setYouTubeVideo({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
lesson_id: lessonId,
|
lesson_id: lessonId,
|
||||||
youtube_video_id: body.youtube_video_id,
|
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 { Get, Path, Put, Query, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa';
|
||||||
import { ValidationError } from '../middleware/errorHandler';
|
|
||||||
import { RecommendedCoursesService } from '../services/RecommendedCourses.service';
|
import { RecommendedCoursesService } from '../services/RecommendedCourses.service';
|
||||||
import {
|
import {
|
||||||
ListApprovedCoursesResponse,
|
ListApprovedCoursesResponse,
|
||||||
|
|
@ -20,10 +19,12 @@ export class RecommendedCoursesController {
|
||||||
@SuccessResponse('200', 'Approved courses retrieved successfully')
|
@SuccessResponse('200', 'Approved courses retrieved successfully')
|
||||||
@Response('401', 'Unauthorized')
|
@Response('401', 'Unauthorized')
|
||||||
@Response('403', 'Forbidden - Admin only')
|
@Response('403', 'Forbidden - Admin only')
|
||||||
public async listApprovedCourses(@Request() request: any): Promise<ListApprovedCoursesResponse> {
|
public async listApprovedCourses(
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
@Request() request: any,
|
||||||
if (!token) throw new ValidationError('No token provided');
|
@Query() search?: string,
|
||||||
return await RecommendedCoursesService.listApprovedCourses(token);
|
@Query() categoryId?: number
|
||||||
|
): Promise<ListApprovedCoursesResponse> {
|
||||||
|
return await RecommendedCoursesService.listApprovedCourses(request.user.id, { search, categoryId });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,9 +40,7 @@ export class RecommendedCoursesController {
|
||||||
@Response('403', 'Forbidden - Admin only')
|
@Response('403', 'Forbidden - Admin only')
|
||||||
@Response('404', 'Course not found')
|
@Response('404', 'Course not found')
|
||||||
public async getCourseById(@Request() request: any, @Path() courseId: number): Promise<GetCourseByIdResponse> {
|
public async getCourseById(@Request() request: any, @Path() courseId: number): Promise<GetCourseByIdResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await RecommendedCoursesService.getCourseById(request.user.id, courseId);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await RecommendedCoursesService.getCourseById(token, courseId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -61,8 +60,6 @@ export class RecommendedCoursesController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Query() is_recommended: boolean
|
@Query() is_recommended: boolean
|
||||||
): Promise<ToggleRecommendedResponse> {
|
): Promise<ToggleRecommendedResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await RecommendedCoursesService.toggleRecommended(request.user.id, courseId, is_recommended);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await RecommendedCoursesService.toggleRecommended(token, courseId, is_recommended);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,15 @@
|
||||||
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 { ValidationError } from '../middleware/errorHandler';
|
||||||
import { UserService } from '../services/user.service';
|
import { UserService } from '../services/user.service';
|
||||||
import {
|
import {
|
||||||
UserResponse,
|
UserResponse,
|
||||||
ProfileResponse,
|
|
||||||
ProfileUpdate,
|
ProfileUpdate,
|
||||||
ProfileUpdateResponse,
|
ProfileUpdateResponse,
|
||||||
ChangePasswordRequest,
|
|
||||||
ChangePasswordResponse,
|
ChangePasswordResponse,
|
||||||
updateAvatarResponse,
|
updateAvatarResponse,
|
||||||
SendVerifyEmailResponse,
|
SendVerifyEmailResponse,
|
||||||
VerifyEmailResponse
|
VerifyEmailResponse,
|
||||||
|
rolesResponse
|
||||||
} from '../types/user.types';
|
} from '../types/user.types';
|
||||||
import { ChangePassword } from '../types/auth.types';
|
import { ChangePassword } from '../types/auth.types';
|
||||||
import { profileUpdateSchema, changePasswordSchema } from "../validators/user.validator";
|
import { profileUpdateSchema, changePasswordSchema } from "../validators/user.validator";
|
||||||
|
|
@ -22,8 +21,6 @@ export class UserController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current user profile
|
* Get current user profile
|
||||||
* @summary Retrieve authenticated user's profile information
|
|
||||||
* @param request Express request object with JWT token in Authorization header
|
|
||||||
*/
|
*/
|
||||||
@Get('me')
|
@Get('me')
|
||||||
@SuccessResponse('200', 'User found')
|
@SuccessResponse('200', 'User found')
|
||||||
|
|
@ -31,12 +28,7 @@ export class UserController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Security('jwt')
|
@Security('jwt')
|
||||||
public async getMe(@Request() request: any): Promise<UserResponse> {
|
public async getMe(@Request() request: any): Promise<UserResponse> {
|
||||||
// Extract token from Authorization header
|
return await this.userService.getUserProfile(request.user.id);
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) {
|
|
||||||
throw new ValidationError('No token provided');
|
|
||||||
}
|
|
||||||
return await this.userService.getUserProfile(token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('me')
|
@Put('me')
|
||||||
|
|
@ -46,22 +38,20 @@ export class UserController {
|
||||||
@Response('400', 'Validation error')
|
@Response('400', 'Validation error')
|
||||||
public async updateProfile(@Request() request: any, @Body() body: ProfileUpdate): Promise<ProfileUpdateResponse> {
|
public async updateProfile(@Request() request: any, @Body() body: ProfileUpdate): Promise<ProfileUpdateResponse> {
|
||||||
const { error } = profileUpdateSchema.validate(body);
|
const { error } = profileUpdateSchema.validate(body);
|
||||||
if (error) {
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
throw new ValidationError(error.details[0].message);
|
return await this.userService.updateProfile(request.user.id, body);
|
||||||
}
|
}
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) {
|
@Get('roles')
|
||||||
throw new ValidationError('No token provided');
|
@Security('jwt')
|
||||||
}
|
@SuccessResponse('200', 'Roles retrieved successfully')
|
||||||
return await this.userService.updateProfile(token, body);
|
@Response('401', 'Invalid or expired token')
|
||||||
|
public async getRoles(): Promise<rolesResponse> {
|
||||||
|
return await this.userService.getRoles();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change password
|
* 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')
|
@Post('change-password')
|
||||||
@Security('jwt')
|
@Security('jwt')
|
||||||
|
|
@ -70,22 +60,12 @@ export class UserController {
|
||||||
@Response('400', 'Validation error')
|
@Response('400', 'Validation error')
|
||||||
public async changePassword(@Request() request: any, @Body() body: ChangePassword): Promise<ChangePasswordResponse> {
|
public async changePassword(@Request() request: any, @Body() body: ChangePassword): Promise<ChangePasswordResponse> {
|
||||||
const { error } = changePasswordSchema.validate(body);
|
const { error } = changePasswordSchema.validate(body);
|
||||||
if (error) {
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
throw new ValidationError(error.details[0].message);
|
return await this.userService.changePassword(request.user.id, body.oldPassword, body.newPassword);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload user avatar picture
|
* Upload user avatar picture
|
||||||
* @param request Express request object with JWT token in Authorization header
|
|
||||||
* @param file Avatar image file
|
|
||||||
*/
|
*/
|
||||||
@Post('upload-avatar')
|
@Post('upload-avatar')
|
||||||
@Security('jwt')
|
@Security('jwt')
|
||||||
|
|
@ -96,9 +76,6 @@ export class UserController {
|
||||||
@Request() request: any,
|
@Request() request: any,
|
||||||
@UploadedFile() file: Express.Multer.File
|
@UploadedFile() file: Express.Multer.File
|
||||||
): Promise<updateAvatarResponse> {
|
): Promise<updateAvatarResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
|
|
||||||
// Validate file type (images only)
|
// Validate file type (images only)
|
||||||
if (!file.mimetype?.startsWith('image/')) throw new ValidationError('Only image files are allowed');
|
if (!file.mimetype?.startsWith('image/')) throw new ValidationError('Only image files are allowed');
|
||||||
|
|
||||||
|
|
@ -106,13 +83,11 @@ export class UserController {
|
||||||
const maxSize = 5 * 1024 * 1024; // 5MB
|
const maxSize = 5 * 1024 * 1024; // 5MB
|
||||||
if (file.size > maxSize) throw new ValidationError('File size must be less than 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
|
* 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')
|
@Post('send-verify-email')
|
||||||
@Security('jwt')
|
@Security('jwt')
|
||||||
|
|
@ -120,9 +95,7 @@ export class UserController {
|
||||||
@Response('401', 'Invalid or expired token')
|
@Response('401', 'Invalid or expired token')
|
||||||
@Response('400', 'Email already verified')
|
@Response('400', 'Email already verified')
|
||||||
public async sendVerifyEmail(@Request() request: any): Promise<SendVerifyEmailResponse> {
|
public async sendVerifyEmail(@Request() request: any): Promise<SendVerifyEmailResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
return await this.userService.sendVerifyEmail(request.user.id);
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await this.userService.sendVerifyEmail(token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { Body, Delete, Get, Path, Post, Put, Query, Request, Response, Route, Security, SuccessResponse, Tags, UploadedFile, UploadedFiles, FormField } from 'tsoa';
|
import { Body, Delete, Get, Path, Post, Put, Query, Request, Response, Route, Security, SuccessResponse, Tags, UploadedFile, UploadedFiles, FormField } from 'tsoa';
|
||||||
import { ValidationError } from '../middleware/errorHandler';
|
import { ValidationError } from '../middleware/errorHandler';
|
||||||
import { AnnouncementsService } from '../services/announcements.service';
|
import { AnnouncementsService } from '../services/announcements.service';
|
||||||
|
import { CreateAnnouncementValidator, UpdateAnnouncementValidator } from '../validators/announcements.validator';
|
||||||
import {
|
import {
|
||||||
ListAnnouncementResponse,
|
ListAnnouncementResponse,
|
||||||
CreateAnnouncementResponse,
|
CreateAnnouncementResponse,
|
||||||
|
|
@ -36,10 +37,8 @@ export class AnnouncementsController {
|
||||||
@Query() page?: number,
|
@Query() page?: number,
|
||||||
@Query() limit?: number
|
@Query() limit?: number
|
||||||
): Promise<ListAnnouncementResponse> {
|
): Promise<ListAnnouncementResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await announcementsService.listAnnouncement({
|
return await announcementsService.listAnnouncement({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
page,
|
page,
|
||||||
limit,
|
limit,
|
||||||
|
|
@ -62,14 +61,15 @@ export class AnnouncementsController {
|
||||||
@FormField() data: string,
|
@FormField() data: string,
|
||||||
@UploadedFiles() files?: Express.Multer.File[]
|
@UploadedFiles() files?: Express.Multer.File[]
|
||||||
): Promise<CreateAnnouncementResponse> {
|
): Promise<CreateAnnouncementResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
|
|
||||||
// Parse JSON data field
|
// Parse JSON data field
|
||||||
const parsed = JSON.parse(data) as CreateAnnouncementBody;
|
const parsed = JSON.parse(data) as CreateAnnouncementBody;
|
||||||
|
|
||||||
|
// Validate parsed data
|
||||||
|
const { error } = CreateAnnouncementValidator.validate(parsed);
|
||||||
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await announcementsService.createAnnouncement({
|
return await announcementsService.createAnnouncement({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
title: parsed.title,
|
title: parsed.title,
|
||||||
content: parsed.content,
|
content: parsed.content,
|
||||||
|
|
@ -98,10 +98,12 @@ export class AnnouncementsController {
|
||||||
@Path() announcementId: number,
|
@Path() announcementId: number,
|
||||||
@Body() body: UpdateAnnouncementBody
|
@Body() body: UpdateAnnouncementBody
|
||||||
): Promise<UpdateAnnouncementResponse> {
|
): Promise<UpdateAnnouncementResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
// Validate body
|
||||||
if (!token) throw new ValidationError('No token provided');
|
const { error } = UpdateAnnouncementValidator.validate(body);
|
||||||
|
if (error) throw new ValidationError(error.details[0].message);
|
||||||
|
|
||||||
return await announcementsService.updateAnnouncement({
|
return await announcementsService.updateAnnouncement({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
announcement_id: announcementId,
|
announcement_id: announcementId,
|
||||||
title: body.title,
|
title: body.title,
|
||||||
|
|
@ -129,10 +131,8 @@ export class AnnouncementsController {
|
||||||
@Path() courseId: number,
|
@Path() courseId: number,
|
||||||
@Path() announcementId: number
|
@Path() announcementId: number
|
||||||
): Promise<DeleteAnnouncementResponse> {
|
): Promise<DeleteAnnouncementResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await announcementsService.deleteAnnouncement({
|
return await announcementsService.deleteAnnouncement({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
announcement_id: announcementId,
|
announcement_id: announcementId,
|
||||||
});
|
});
|
||||||
|
|
@ -156,10 +156,8 @@ export class AnnouncementsController {
|
||||||
@Path() announcementId: number,
|
@Path() announcementId: number,
|
||||||
@UploadedFile() file: Express.Multer.File
|
@UploadedFile() file: Express.Multer.File
|
||||||
): Promise<UploadAnnouncementAttachmentResponse> {
|
): Promise<UploadAnnouncementAttachmentResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await announcementsService.uploadAttachment({
|
return await announcementsService.uploadAttachment({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
announcement_id: announcementId,
|
announcement_id: announcementId,
|
||||||
file: file as any,
|
file: file as any,
|
||||||
|
|
@ -185,10 +183,8 @@ export class AnnouncementsController {
|
||||||
@Path() announcementId: number,
|
@Path() announcementId: number,
|
||||||
@Path() attachmentId: number
|
@Path() attachmentId: number
|
||||||
): Promise<DeleteAnnouncementAttachmentResponse> {
|
): Promise<DeleteAnnouncementAttachmentResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await announcementsService.deleteAttachment({
|
return await announcementsService.deleteAttachment({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
announcement_id: announcementId,
|
announcement_id: announcementId,
|
||||||
attachment_id: attachmentId,
|
attachment_id: attachmentId,
|
||||||
|
|
@ -218,10 +214,8 @@ export class AnnouncementsStudentController {
|
||||||
@Query() page?: number,
|
@Query() page?: number,
|
||||||
@Query() limit?: number
|
@Query() limit?: number
|
||||||
): Promise<ListAnnouncementResponse> {
|
): Promise<ListAnnouncementResponse> {
|
||||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
|
||||||
if (!token) throw new ValidationError('No token provided');
|
|
||||||
return await announcementsService.listAnnouncement({
|
return await announcementsService.listAnnouncement({
|
||||||
token,
|
userId: request.user.id,
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
page,
|
page,
|
||||||
limit,
|
limit,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import { prisma } from '../config/database';
|
import { prisma } from '../config/database';
|
||||||
import { config } from '../config';
|
|
||||||
import { logger } from '../config/logger';
|
import { logger } from '../config/logger';
|
||||||
import { UnauthorizedError, ValidationError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
import { ValidationError, NotFoundError } from '../middleware/errorHandler';
|
||||||
import jwt from 'jsonwebtoken';
|
|
||||||
import { getPresignedUrl } from '../config/minio';
|
import { getPresignedUrl } from '../config/minio';
|
||||||
import {
|
import {
|
||||||
ListPendingCoursesResponse,
|
ListPendingCoursesResponse,
|
||||||
|
|
@ -18,7 +16,7 @@ export class AdminCourseApprovalService {
|
||||||
/**
|
/**
|
||||||
* Get all pending courses for admin review
|
* Get all pending courses for admin review
|
||||||
*/
|
*/
|
||||||
static async listPendingCourses(token: string): Promise<ListPendingCoursesResponse> {
|
static async listPendingCourses(userId: number): Promise<ListPendingCoursesResponse> {
|
||||||
try {
|
try {
|
||||||
const courses = await prisma.course.findMany({
|
const courses = await prisma.course.findMany({
|
||||||
where: { status: 'PENDING' },
|
where: { status: 'PENDING' },
|
||||||
|
|
@ -96,9 +94,8 @@ export class AdminCourseApprovalService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to list pending courses', { error });
|
logger.error('Failed to list pending courses', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -113,7 +110,7 @@ export class AdminCourseApprovalService {
|
||||||
/**
|
/**
|
||||||
* Get course details for admin review
|
* 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 {
|
try {
|
||||||
const course = await prisma.course.findUnique({
|
const course = await prisma.course.findUnique({
|
||||||
where: { id: courseId },
|
where: { id: courseId },
|
||||||
|
|
@ -133,7 +130,11 @@ export class AdminCourseApprovalService {
|
||||||
},
|
},
|
||||||
chapters: {
|
chapters: {
|
||||||
orderBy: { sort_order: 'asc' },
|
orderBy: { sort_order: 'asc' },
|
||||||
include: {
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
sort_order: true,
|
||||||
|
is_published: true,
|
||||||
lessons: {
|
lessons: {
|
||||||
orderBy: { sort_order: 'asc' },
|
orderBy: { sort_order: 'asc' },
|
||||||
select: {
|
select: {
|
||||||
|
|
@ -224,9 +225,8 @@ export class AdminCourseApprovalService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to get course detail', { error });
|
logger.error('Failed to get course detail', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -241,9 +241,8 @@ export class AdminCourseApprovalService {
|
||||||
/**
|
/**
|
||||||
* Approve a course
|
* 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 {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
const course = await prisma.course.findUnique({ where: { id: courseId } });
|
const course = await prisma.course.findUnique({ where: { id: courseId } });
|
||||||
if (!course) {
|
if (!course) {
|
||||||
|
|
@ -260,7 +259,7 @@ export class AdminCourseApprovalService {
|
||||||
where: { id: courseId },
|
where: { id: courseId },
|
||||||
data: {
|
data: {
|
||||||
status: 'APPROVED',
|
status: 'APPROVED',
|
||||||
approved_by: decoded.id,
|
approved_by: userId,
|
||||||
approved_at: new Date()
|
approved_at: new Date()
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
@ -269,7 +268,7 @@ export class AdminCourseApprovalService {
|
||||||
data: {
|
data: {
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
submitted_by: course.created_by,
|
submitted_by: course.created_by,
|
||||||
reviewed_by: decoded.id,
|
reviewed_by: userId,
|
||||||
action: 'APPROVED',
|
action: 'APPROVED',
|
||||||
previous_status: course.status,
|
previous_status: course.status,
|
||||||
new_status: 'APPROVED',
|
new_status: 'APPROVED',
|
||||||
|
|
@ -280,7 +279,7 @@ export class AdminCourseApprovalService {
|
||||||
|
|
||||||
// Audit log - APPROVE_COURSE
|
// Audit log - APPROVE_COURSE
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.APPROVE_COURSE,
|
action: AuditAction.APPROVE_COURSE,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -295,9 +294,8 @@ export class AdminCourseApprovalService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to approve course', { error });
|
logger.error('Failed to approve course', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -313,9 +311,8 @@ export class AdminCourseApprovalService {
|
||||||
/**
|
/**
|
||||||
* Reject a course
|
* 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 {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
const course = await prisma.course.findUnique({ where: { id: courseId } });
|
const course = await prisma.course.findUnique({ where: { id: courseId } });
|
||||||
if (!course) {
|
if (!course) {
|
||||||
|
|
@ -346,7 +343,7 @@ export class AdminCourseApprovalService {
|
||||||
data: {
|
data: {
|
||||||
course_id: courseId,
|
course_id: courseId,
|
||||||
submitted_by: course.created_by,
|
submitted_by: course.created_by,
|
||||||
reviewed_by: decoded.id,
|
reviewed_by: userId,
|
||||||
action: 'REJECTED',
|
action: 'REJECTED',
|
||||||
previous_status: course.status,
|
previous_status: course.status,
|
||||||
new_status: 'REJECTED',
|
new_status: 'REJECTED',
|
||||||
|
|
@ -357,7 +354,7 @@ export class AdminCourseApprovalService {
|
||||||
|
|
||||||
// Audit log - REJECT_COURSE
|
// Audit log - REJECT_COURSE
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.REJECT_COURSE,
|
action: AuditAction.REJECT_COURSE,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -372,9 +369,8 @@ export class AdminCourseApprovalService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to reject course', { error });
|
logger.error('Failed to reject course', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
|
||||||
|
|
@ -59,14 +59,11 @@ import { AuditAction } from '@prisma/client';
|
||||||
* ตรวจสอบสิทธิ์เข้าถึง Course (สำหรับทั้ง Instructor และ Student)
|
* ตรวจสอบสิทธิ์เข้าถึง Course (สำหรับทั้ง Instructor และ Student)
|
||||||
* Returns: { hasAccess: boolean, role: 'INSTRUCTOR' | 'STUDENT' | null, userId: number }
|
* 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;
|
hasAccess: boolean;
|
||||||
role: 'INSTRUCTOR' | 'STUDENT' | null;
|
role: 'INSTRUCTOR' | 'STUDENT' | null;
|
||||||
userId: number;
|
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 } });
|
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new UnauthorizedError('Invalid token');
|
throw new UnauthorizedError('Invalid token');
|
||||||
|
|
@ -98,9 +95,8 @@ async function validateCourseAccess(token: string, course_id: number): Promise<{
|
||||||
export class ChaptersLessonService {
|
export class ChaptersLessonService {
|
||||||
async listChapters(request: ChaptersRequest): Promise<ListChaptersResponse> {
|
async listChapters(request: ChaptersRequest): Promise<ListChaptersResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id } = request;
|
const { userId, course_id } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new UnauthorizedError('Invalid token');
|
throw new UnauthorizedError('Invalid token');
|
||||||
}
|
}
|
||||||
|
|
@ -117,14 +113,13 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
async createChapter(request: CreateChapterInput): Promise<CreateChapterResponse> {
|
async createChapter(request: CreateChapterInput): Promise<CreateChapterResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, title, description, sort_order } = request;
|
const { userId, course_id, title, description, sort_order } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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) {
|
if (!user) {
|
||||||
throw new UnauthorizedError('Invalid token');
|
throw new UnauthorizedError('Invalid token');
|
||||||
}
|
}
|
||||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||||
if (!courseInstructor) {
|
if (!courseInstructor) {
|
||||||
throw new ForbiddenError('You are not permitted to create chapter');
|
throw new ForbiddenError('You are not permitted to create chapter');
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +127,7 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
// Audit log - CREATE Chapter
|
// Audit log - CREATE Chapter
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decodedToken.id,
|
userId: userId,
|
||||||
action: AuditAction.CREATE,
|
action: AuditAction.CREATE,
|
||||||
entityType: 'Chapter',
|
entityType: 'Chapter',
|
||||||
entityId: chapter.id,
|
entityId: chapter.id,
|
||||||
|
|
@ -142,9 +137,8 @@ export class ChaptersLessonService {
|
||||||
return { code: 200, message: 'Chapter created successfully', data: chapter as ChapterData };
|
return { code: 200, message: 'Chapter created successfully', data: chapter as ChapterData };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error creating chapter: ${error}`);
|
logger.error(`Error creating chapter: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Chapter',
|
entityType: 'Chapter',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -159,14 +153,13 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
async updateChapter(request: UpdateChapterInput): Promise<UpdateChapterResponse> {
|
async updateChapter(request: UpdateChapterInput): Promise<UpdateChapterResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, chapter_id, title, description, sort_order } = request;
|
const { userId, course_id, chapter_id, title, description, sort_order } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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) {
|
if (!user) {
|
||||||
throw new UnauthorizedError('Invalid token');
|
throw new UnauthorizedError('Invalid token');
|
||||||
}
|
}
|
||||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||||
if (!courseInstructor) {
|
if (!courseInstructor) {
|
||||||
throw new ForbiddenError('You are not permitted to update chapter');
|
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 };
|
return { code: 200, message: 'Chapter updated successfully', data: chapter as ChapterData };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error updating chapter: ${error}`);
|
logger.error(`Error updating chapter: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Chapter',
|
entityType: 'Chapter',
|
||||||
entityId: request.chapter_id,
|
entityId: request.chapter_id,
|
||||||
|
|
@ -191,14 +183,13 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
async deleteChapter(request: DeleteChapterRequest): Promise<DeleteChapterResponse> {
|
async deleteChapter(request: DeleteChapterRequest): Promise<DeleteChapterResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, chapter_id } = request;
|
const { userId, course_id, chapter_id } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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) {
|
if (!user) {
|
||||||
throw new UnauthorizedError('Invalid token');
|
throw new UnauthorizedError('Invalid token');
|
||||||
}
|
}
|
||||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||||
if (!courseInstructor) {
|
if (!courseInstructor) {
|
||||||
throw new ForbiddenError('You are not permitted to delete chapter');
|
throw new ForbiddenError('You are not permitted to delete chapter');
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +197,7 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
// Audit log - DELETE Chapter
|
// Audit log - DELETE Chapter
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decodedToken.id,
|
userId: userId,
|
||||||
action: AuditAction.DELETE,
|
action: AuditAction.DELETE,
|
||||||
entityType: 'Chapter',
|
entityType: 'Chapter',
|
||||||
entityId: chapter_id,
|
entityId: chapter_id,
|
||||||
|
|
@ -219,9 +210,8 @@ export class ChaptersLessonService {
|
||||||
return { code: 200, message: 'Chapter deleted successfully' };
|
return { code: 200, message: 'Chapter deleted successfully' };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error deleting chapter: ${error}`);
|
logger.error(`Error deleting chapter: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Chapter',
|
entityType: 'Chapter',
|
||||||
entityId: request.chapter_id,
|
entityId: request.chapter_id,
|
||||||
|
|
@ -236,14 +226,13 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
async reorderChapter(request: ReorderChapterRequest): Promise<ReorderChapterResponse> {
|
async reorderChapter(request: ReorderChapterRequest): Promise<ReorderChapterResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, chapter_id, sort_order: newSortOrder } = request;
|
const { userId, course_id, chapter_id, sort_order: newSortOrder } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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) {
|
if (!user) {
|
||||||
throw new UnauthorizedError('Invalid token');
|
throw new UnauthorizedError('Invalid token');
|
||||||
}
|
}
|
||||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||||
if (!courseInstructor) {
|
if (!courseInstructor) {
|
||||||
throw new ForbiddenError('You are not permitted to reorder chapter');
|
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[] };
|
return { code: 200, message: 'Chapter reordered successfully', data: chapters as ChapterData[] };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error reordering chapter: ${error}`);
|
logger.error(`Error reordering chapter: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Chapter',
|
entityType: 'Chapter',
|
||||||
entityId: request.chapter_id,
|
entityId: request.chapter_id,
|
||||||
|
|
@ -335,14 +323,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async createLesson(request: CreateLessonInput): Promise<CreateLessonResponse> {
|
async createLesson(request: CreateLessonInput): Promise<CreateLessonResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, chapter_id, title, content, type, sort_order } = request;
|
const { userId, course_id, chapter_id, title, content, type, sort_order } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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) {
|
if (!user) {
|
||||||
throw new UnauthorizedError('Invalid token');
|
throw new UnauthorizedError('Invalid token');
|
||||||
}
|
}
|
||||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||||
if (!courseInstructor) {
|
if (!courseInstructor) {
|
||||||
throw new ForbiddenError('You are not permitted to create lesson');
|
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 QUIZ type, create empty Quiz shell
|
||||||
if (type === 'QUIZ') {
|
if (type === 'QUIZ') {
|
||||||
const userId = decodedToken.id;
|
|
||||||
|
|
||||||
await prisma.quiz.create({
|
await prisma.quiz.create({
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -376,7 +362,7 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
// Audit log - CREATE Lesson (QUIZ)
|
// Audit log - CREATE Lesson (QUIZ)
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decodedToken.id,
|
userId: userId,
|
||||||
action: AuditAction.CREATE,
|
action: AuditAction.CREATE,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: lesson.id,
|
entityId: lesson.id,
|
||||||
|
|
@ -388,7 +374,7 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
// Audit log - CREATE Lesson
|
// Audit log - CREATE Lesson
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decodedToken.id,
|
userId: userId,
|
||||||
action: AuditAction.CREATE,
|
action: AuditAction.CREATE,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: lesson.id,
|
entityId: lesson.id,
|
||||||
|
|
@ -398,9 +384,8 @@ export class ChaptersLessonService {
|
||||||
return { code: 200, message: 'Lesson created successfully', data: lesson as LessonData };
|
return { code: 200, message: 'Lesson created successfully', data: lesson as LessonData };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error creating lesson: ${error}`);
|
logger.error(`Error creating lesson: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -419,10 +404,10 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async getLesson(request: GetLessonRequest): Promise<GetLessonResponse> {
|
async getLesson(request: GetLessonRequest): Promise<GetLessonResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id } = request;
|
const { userId, course_id, lesson_id } = request;
|
||||||
|
|
||||||
// Check access for both instructor and enrolled student
|
// 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) {
|
if (!access.hasAccess) {
|
||||||
throw new ForbiddenError('You do not have access to this course');
|
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 };
|
return { code: 200, message: 'Lesson fetched successfully', data: lessonData as LessonData };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error fetching lesson: ${error}`);
|
logger.error(`Error fetching lesson: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: request.lesson_id,
|
entityId: request.lesson_id,
|
||||||
|
|
@ -566,14 +550,13 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
async updateLesson(request: UpdateLessonRequest): Promise<UpdateLessonResponse> {
|
async updateLesson(request: UpdateLessonRequest): Promise<UpdateLessonResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, data } = request;
|
const { userId, course_id, lesson_id, data } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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) {
|
if (!user) {
|
||||||
throw new UnauthorizedError('Invalid token');
|
throw new UnauthorizedError('Invalid token');
|
||||||
}
|
}
|
||||||
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
const courseInstructor = await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||||
if (!courseInstructor) {
|
if (!courseInstructor) {
|
||||||
throw new ForbiddenError('You are not permitted to update lesson');
|
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 };
|
return { code: 200, message: 'Lesson updated successfully', data: lesson as LessonData };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error updating lesson: ${error}`);
|
logger.error(`Error updating lesson: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: request.lesson_id,
|
entityId: request.lesson_id,
|
||||||
|
|
@ -602,14 +584,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async reorderLessons(request: ReorderLessonsRequest): Promise<ReorderLessonsResponse> {
|
async reorderLessons(request: ReorderLessonsRequest): Promise<ReorderLessonsResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, chapter_id, lesson_id, sort_order: newSortOrder } = request;
|
const { userId, course_id, chapter_id, lesson_id, sort_order: newSortOrder } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to reorder lessons');
|
||||||
|
|
||||||
// Verify chapter exists and belongs to the course
|
// 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[] };
|
return { code: 200, message: 'Lessons reordered successfully', data: lessons as LessonData[] };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error reordering lessons: ${error}`);
|
logger.error(`Error reordering lessons: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: request.lesson_id,
|
entityId: request.lesson_id,
|
||||||
|
|
@ -704,14 +684,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async deleteLesson(request: DeleteLessonRequest): Promise<DeleteLessonResponse> {
|
async deleteLesson(request: DeleteLessonRequest): Promise<DeleteLessonResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id } = request;
|
const { userId, course_id, lesson_id } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to delete this lesson');
|
||||||
|
|
||||||
// Fetch lesson with all related data
|
// Fetch lesson with all related data
|
||||||
|
|
@ -751,7 +730,7 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
// Audit log - DELETE Lesson
|
// Audit log - DELETE Lesson
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decodedToken.id,
|
userId: userId,
|
||||||
action: AuditAction.DELETE,
|
action: AuditAction.DELETE,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: lesson_id,
|
entityId: lesson_id,
|
||||||
|
|
@ -764,9 +743,8 @@ export class ChaptersLessonService {
|
||||||
return { code: 200, message: 'Lesson deleted successfully' };
|
return { code: 200, message: 'Lesson deleted successfully' };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error deleting lesson: ${error}`);
|
logger.error(`Error deleting lesson: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: request.lesson_id,
|
entityId: request.lesson_id,
|
||||||
|
|
@ -789,14 +767,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async uploadVideo(request: UploadVideoInput): Promise<VideoOperationResponse> {
|
async uploadVideo(request: UploadVideoInput): Promise<VideoOperationResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, video } = request;
|
const { userId, course_id, lesson_id, video } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists and is VIDEO type
|
// Verify lesson exists and is VIDEO type
|
||||||
|
|
@ -833,7 +810,7 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
// Audit log - UPLOAD_FILE (Video)
|
// Audit log - UPLOAD_FILE (Video)
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decodedToken.id,
|
userId: userId,
|
||||||
action: AuditAction.UPLOAD_FILE,
|
action: AuditAction.UPLOAD_FILE,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: lesson_id,
|
entityId: lesson_id,
|
||||||
|
|
@ -853,9 +830,8 @@ export class ChaptersLessonService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error uploading video: ${error}`);
|
logger.error(`Error uploading video: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: request.lesson_id,
|
entityId: request.lesson_id,
|
||||||
|
|
@ -874,14 +850,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async updateVideo(request: UpdateVideoInput): Promise<VideoOperationResponse> {
|
async updateVideo(request: UpdateVideoInput): Promise<VideoOperationResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, video } = request;
|
const { userId, course_id, lesson_id, video } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists and is VIDEO type
|
// Verify lesson exists and is VIDEO type
|
||||||
|
|
@ -946,9 +921,8 @@ export class ChaptersLessonService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error updating video: ${error}`);
|
logger.error(`Error updating video: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: request.lesson_id,
|
entityId: request.lesson_id,
|
||||||
|
|
@ -967,14 +941,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async setYouTubeVideo(request: SetYouTubeVideoInput): Promise<YouTubeVideoResponse> {
|
async setYouTubeVideo(request: SetYouTubeVideoInput): Promise<YouTubeVideoResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, youtube_video_id, video_title } = request;
|
const { userId, course_id, lesson_id, youtube_video_id, video_title } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists and is VIDEO type
|
// Verify lesson exists and is VIDEO type
|
||||||
|
|
@ -1038,9 +1011,8 @@ export class ChaptersLessonService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error setting YouTube video: ${error}`);
|
logger.error(`Error setting YouTube video: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Lesson',
|
entityType: 'Lesson',
|
||||||
entityId: request.lesson_id,
|
entityId: request.lesson_id,
|
||||||
|
|
@ -1059,14 +1031,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async uploadAttachment(request: UploadAttachmentInput): Promise<AttachmentOperationResponse> {
|
async uploadAttachment(request: UploadAttachmentInput): Promise<AttachmentOperationResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, attachment } = request;
|
const { userId, course_id, lesson_id, attachment } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists
|
// Verify lesson exists
|
||||||
|
|
@ -1101,7 +1072,7 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
// Audit log - UPLOAD_FILE (Attachment)
|
// Audit log - UPLOAD_FILE (Attachment)
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decodedToken.id,
|
userId: userId,
|
||||||
action: AuditAction.UPLOAD_FILE,
|
action: AuditAction.UPLOAD_FILE,
|
||||||
entityType: 'LessonAttachment',
|
entityType: 'LessonAttachment',
|
||||||
entityId: newAttachment.id,
|
entityId: newAttachment.id,
|
||||||
|
|
@ -1125,9 +1096,8 @@ export class ChaptersLessonService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error uploading attachment: ${error}`);
|
logger.error(`Error uploading attachment: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'LessonAttachment',
|
entityType: 'LessonAttachment',
|
||||||
entityId: request.lesson_id,
|
entityId: request.lesson_id,
|
||||||
|
|
@ -1146,14 +1116,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async deleteAttachment(request: DeleteAttachmentInput): Promise<DeleteAttachmentResponse> {
|
async deleteAttachment(request: DeleteAttachmentInput): Promise<DeleteAttachmentResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, attachment_id } = request;
|
const { userId, course_id, lesson_id, attachment_id } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists
|
// Verify lesson exists
|
||||||
|
|
@ -1184,7 +1153,7 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
// Audit log - DELETE_FILE (Attachment)
|
// Audit log - DELETE_FILE (Attachment)
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decodedToken.id,
|
userId: userId,
|
||||||
action: AuditAction.DELETE_FILE,
|
action: AuditAction.DELETE_FILE,
|
||||||
entityType: 'LessonAttachment',
|
entityType: 'LessonAttachment',
|
||||||
entityId: attachment_id,
|
entityId: attachment_id,
|
||||||
|
|
@ -1194,9 +1163,8 @@ export class ChaptersLessonService {
|
||||||
return { code: 200, message: 'Attachment deleted successfully' };
|
return { code: 200, message: 'Attachment deleted successfully' };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error deleting attachment: ${error}`);
|
logger.error(`Error deleting attachment: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'LessonAttachment',
|
entityType: 'LessonAttachment',
|
||||||
entityId: request.attachment_id,
|
entityId: request.attachment_id,
|
||||||
|
|
@ -1216,14 +1184,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async addQuestion(request: AddQuestionInput): Promise<AddQuestionResponse> {
|
async addQuestion(request: AddQuestionInput): Promise<AddQuestionResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, question, explanation, question_type, sort_order, choices } = request;
|
const { userId, course_id, lesson_id, question, explanation, question_type, sort_order, choices } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists and is QUIZ type
|
// 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 };
|
return { code: 200, message: 'Question added successfully', data: completeQuestion as QuizQuestionData };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error adding question: ${error}`);
|
logger.error(`Error adding question: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Question',
|
entityType: 'Question',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -1303,14 +1269,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async updateQuestion(request: UpdateQuestionInput): Promise<UpdateQuestionResponse> {
|
async updateQuestion(request: UpdateQuestionInput): Promise<UpdateQuestionResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, question_id, question, explanation, question_type, sort_order, choices } = request;
|
const { userId, 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 };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists and is QUIZ type
|
// 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 };
|
return { code: 200, message: 'Question updated successfully', data: completeQuestion as QuizQuestionData };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error updating question: ${error}`);
|
logger.error(`Error updating question: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Question',
|
entityType: 'Question',
|
||||||
entityId: request.question_id,
|
entityId: request.question_id,
|
||||||
|
|
@ -1384,14 +1348,13 @@ export class ChaptersLessonService {
|
||||||
|
|
||||||
async reorderQuestion(request: ReorderQuestionInput): Promise<ReorderQuestionResponse> {
|
async reorderQuestion(request: ReorderQuestionInput): Promise<ReorderQuestionResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, question_id, sort_order } = request;
|
const { userId, course_id, lesson_id, question_id, sort_order } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists and is QUIZ type
|
// 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[] };
|
return { code: 200, message: 'Question reordered successfully', data: questions as QuizQuestionData[] };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error reordering question: ${error}`);
|
logger.error(`Error reordering question: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Question',
|
entityType: 'Question',
|
||||||
entityId: request.question_id,
|
entityId: request.question_id,
|
||||||
|
|
@ -1493,14 +1455,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async deleteQuestion(request: DeleteQuestionInput): Promise<DeleteQuestionResponse> {
|
async deleteQuestion(request: DeleteQuestionInput): Promise<DeleteQuestionResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, question_id } = request;
|
const { userId, course_id, lesson_id, question_id } = request;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists and is QUIZ type
|
// Verify lesson exists and is QUIZ type
|
||||||
|
|
@ -1530,9 +1491,8 @@ export class ChaptersLessonService {
|
||||||
return { code: 200, message: 'Question deleted successfully' };
|
return { code: 200, message: 'Question deleted successfully' };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error deleting question: ${error}`);
|
logger.error(`Error deleting question: ${error}`);
|
||||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decodedToken?.id || 0,
|
userId: request.userId || 0,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Question',
|
entityType: 'Question',
|
||||||
entityId: request.question_id,
|
entityId: request.question_id,
|
||||||
|
|
@ -1680,14 +1640,13 @@ export class ChaptersLessonService {
|
||||||
*/
|
*/
|
||||||
async updateQuiz(request: UpdateQuizInput): Promise<UpdateQuizResponse> {
|
async updateQuiz(request: UpdateQuizInput): Promise<UpdateQuizResponse> {
|
||||||
try {
|
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 { 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;
|
||||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
await CoursesInstructorService.validateCourseStatus(course_id);
|
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');
|
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');
|
if (!courseInstructor) throw new ForbiddenError('You are not permitted to modify this lesson');
|
||||||
|
|
||||||
// Verify lesson exists and is QUIZ type
|
// Verify lesson exists and is QUIZ type
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
import { prisma } from '../config/database';
|
import { prisma } from '../config/database';
|
||||||
import { Prisma } from '@prisma/client';
|
import { Prisma } from '@prisma/client';
|
||||||
import { config } from '../config';
|
|
||||||
import { logger } from '../config/logger';
|
import { logger } from '../config/logger';
|
||||||
import { UnauthorizedError, ValidationError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
import { ValidationError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
||||||
import jwt from 'jsonwebtoken';
|
|
||||||
import { uploadFile, deleteFile, getPresignedUrl } from '../config/minio';
|
import { uploadFile, deleteFile, getPresignedUrl } from '../config/minio';
|
||||||
import {
|
import {
|
||||||
CreateCourseInput,
|
CreateCourseInput,
|
||||||
UpdateCourseInput,
|
UpdateCourseInput,
|
||||||
createCourseResponse,
|
createCourseResponse,
|
||||||
GetMyCourseResponse,
|
GetMyCourseResponse,
|
||||||
|
ListMyCoursesInput,
|
||||||
ListMyCourseResponse,
|
ListMyCourseResponse,
|
||||||
addinstructorCourse,
|
addinstructorCourse,
|
||||||
addinstructorCourseResponse,
|
addinstructorCourseResponse,
|
||||||
|
|
@ -26,6 +25,7 @@ import {
|
||||||
SearchInstructorResponse,
|
SearchInstructorResponse,
|
||||||
GetEnrolledStudentsInput,
|
GetEnrolledStudentsInput,
|
||||||
GetEnrolledStudentsResponse,
|
GetEnrolledStudentsResponse,
|
||||||
|
EnrolledStudentData,
|
||||||
GetQuizScoresInput,
|
GetQuizScoresInput,
|
||||||
GetQuizScoresResponse,
|
GetQuizScoresResponse,
|
||||||
GetQuizAttemptDetailInput,
|
GetQuizAttemptDetailInput,
|
||||||
|
|
@ -33,8 +33,11 @@ import {
|
||||||
GetEnrolledStudentDetailInput,
|
GetEnrolledStudentDetailInput,
|
||||||
GetEnrolledStudentDetailResponse,
|
GetEnrolledStudentDetailResponse,
|
||||||
GetCourseApprovalHistoryResponse,
|
GetCourseApprovalHistoryResponse,
|
||||||
|
CloneCourseInput,
|
||||||
|
CloneCourseResponse,
|
||||||
setCourseDraft,
|
setCourseDraft,
|
||||||
setCourseDraftResponse,
|
setCourseDraftResponse,
|
||||||
|
GetAllMyStudentsResponse,
|
||||||
} from "../types/CoursesInstructor.types";
|
} from "../types/CoursesInstructor.types";
|
||||||
import { auditService } from './audit.service';
|
import { auditService } from './audit.service';
|
||||||
import { AuditAction } from '@prisma/client';
|
import { AuditAction } from '@prisma/client';
|
||||||
|
|
@ -116,12 +119,12 @@ export class CoursesInstructorService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async listMyCourses(token: string): Promise<ListMyCourseResponse> {
|
static async listMyCourses(input: ListMyCoursesInput): Promise<ListMyCourseResponse> {
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
|
||||||
const courseInstructors = await prisma.courseInstructor.findMany({
|
const courseInstructors = await prisma.courseInstructor.findMany({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id
|
user_id: input.userId,
|
||||||
|
course: input.status ? { status: input.status } : undefined
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
course: true
|
course: true
|
||||||
|
|
@ -153,18 +156,26 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to retrieve courses', { error });
|
logger.error('Failed to retrieve courses', { error });
|
||||||
|
await auditService.logSync({
|
||||||
|
userId: input.userId,
|
||||||
|
action: AuditAction.ERROR,
|
||||||
|
entityType: 'Course',
|
||||||
|
entityId: 0,
|
||||||
|
metadata: {
|
||||||
|
operation: 'list_my_courses',
|
||||||
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
}
|
||||||
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getmyCourse(getmyCourse: getmyCourse): Promise<GetMyCourseResponse> {
|
static async getmyCourse(getmyCourse: getmyCourse): Promise<GetMyCourseResponse> {
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(getmyCourse.token, config.jwt.secret) as { id: number; type: string };
|
|
||||||
|
|
||||||
// Check if user is instructor of this course
|
// Check if user is instructor of this course
|
||||||
const courseInstructor = await prisma.courseInstructor.findFirst({
|
const courseInstructor = await prisma.courseInstructor.findFirst({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: getmyCourse.userId,
|
||||||
course_id: getmyCourse.course_id
|
course_id: getmyCourse.course_id
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
|
|
@ -210,14 +221,13 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to retrieve course', { error });
|
logger.error('Failed to retrieve course', { error });
|
||||||
const decoded = jwt.decode(getmyCourse.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: getmyCourse.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: getmyCourse.course_id,
|
entityId: getmyCourse.course_id,
|
||||||
metadata: {
|
metadata: {
|
||||||
operation: 'get_course',
|
operation: 'get_my_course',
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -225,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 {
|
try {
|
||||||
await this.validateCourseInstructor(token, courseId);
|
await this.validateCourseInstructor(userId, courseId);
|
||||||
|
|
||||||
const course = await prisma.course.update({
|
const course = await prisma.course.update({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -243,9 +253,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to update course', { error });
|
logger.error('Failed to update course', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -258,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 {
|
try {
|
||||||
await this.validateCourseInstructor(token, courseId);
|
await this.validateCourseInstructor(userId, courseId);
|
||||||
|
|
||||||
// Get current course to check for existing thumbnail
|
// Get current course to check for existing thumbnail
|
||||||
const currentCourse = await prisma.course.findUnique({
|
const currentCourse = await prisma.course.findUnique({
|
||||||
|
|
@ -307,9 +316,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to upload thumbnail', { error });
|
logger.error('Failed to upload thumbnail', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -322,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 {
|
try {
|
||||||
const courseInstructorId = await this.validateCourseInstructor(token, courseId);
|
const courseInstructorId = await this.validateCourseInstructor(userId, courseId);
|
||||||
if (!courseInstructorId.is_primary) {
|
if (!courseInstructorId.is_primary) {
|
||||||
throw new ForbiddenError('You have no permission to delete this course');
|
throw new ForbiddenError('You have no permission to delete this course');
|
||||||
}
|
}
|
||||||
|
|
@ -350,9 +358,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to delete course', { error });
|
logger.error('Failed to delete course', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -367,11 +374,10 @@ export class CoursesInstructorService {
|
||||||
|
|
||||||
static async sendCourseForReview(sendCourseForReview: sendCourseForReview): Promise<submitCourseResponse> {
|
static async sendCourseForReview(sendCourseForReview: sendCourseForReview): Promise<submitCourseResponse> {
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(sendCourseForReview.token, config.jwt.secret) as { id: number; type: string };
|
|
||||||
await prisma.courseApproval.create({
|
await prisma.courseApproval.create({
|
||||||
data: {
|
data: {
|
||||||
course_id: sendCourseForReview.course_id,
|
course_id: sendCourseForReview.course_id,
|
||||||
submitted_by: decoded.id,
|
submitted_by: sendCourseForReview.userId,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await prisma.course.update({
|
await prisma.course.update({
|
||||||
|
|
@ -383,7 +389,7 @@ export class CoursesInstructorService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded.id,
|
userId: sendCourseForReview.userId,
|
||||||
action: AuditAction.UPDATE,
|
action: AuditAction.UPDATE,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: sendCourseForReview.course_id,
|
entityId: sendCourseForReview.course_id,
|
||||||
|
|
@ -397,9 +403,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to send course for review', { error });
|
logger.error('Failed to send course for review', { error });
|
||||||
const decoded = jwt.decode(sendCourseForReview.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: sendCourseForReview.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: sendCourseForReview.course_id,
|
entityId: sendCourseForReview.course_id,
|
||||||
|
|
@ -414,7 +419,7 @@ export class CoursesInstructorService {
|
||||||
|
|
||||||
static async setCourseDraft(setCourseDraft: setCourseDraft): Promise<setCourseDraftResponse> {
|
static async setCourseDraft(setCourseDraft: setCourseDraft): Promise<setCourseDraftResponse> {
|
||||||
try {
|
try {
|
||||||
await this.validateCourseInstructor(setCourseDraft.token, setCourseDraft.course_id);
|
await this.validateCourseInstructor(setCourseDraft.userId, setCourseDraft.course_id);
|
||||||
await prisma.course.update({
|
await prisma.course.update({
|
||||||
where: {
|
where: {
|
||||||
id: setCourseDraft.course_id,
|
id: setCourseDraft.course_id,
|
||||||
|
|
@ -430,9 +435,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to set course to draft', { error });
|
logger.error('Failed to set course to draft', { error });
|
||||||
const decoded = jwt.decode(setCourseDraft.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: setCourseDraft.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: setCourseDraft.course_id,
|
entityId: setCourseDraft.course_id,
|
||||||
|
|
@ -445,7 +449,7 @@ export class CoursesInstructorService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getCourseApprovals(token: string, courseId: number): Promise<{
|
static async getCourseApprovals(userId: number, courseId: number): Promise<{
|
||||||
code: number;
|
code: number;
|
||||||
message: string;
|
message: string;
|
||||||
data: any[];
|
data: any[];
|
||||||
|
|
@ -453,7 +457,7 @@ export class CoursesInstructorService {
|
||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
// Validate instructor access
|
// Validate instructor access
|
||||||
await this.validateCourseInstructor(token, courseId);
|
await this.validateCourseInstructor(userId, courseId);
|
||||||
|
|
||||||
const approvals = await prisma.courseApproval.findMany({
|
const approvals = await prisma.courseApproval.findMany({
|
||||||
where: { course_id: courseId },
|
where: { course_id: courseId },
|
||||||
|
|
@ -476,9 +480,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to retrieve course approvals', { error });
|
logger.error('Failed to retrieve course approvals', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -495,8 +498,6 @@ export class CoursesInstructorService {
|
||||||
|
|
||||||
static async searchInstructors(input: SearchInstructorInput): Promise<SearchInstructorResponse> {
|
static async searchInstructors(input: SearchInstructorInput): Promise<SearchInstructorResponse> {
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(input.token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Get existing instructors in the course
|
// Get existing instructors in the course
|
||||||
const existingInstructors = await prisma.courseInstructor.findMany({
|
const existingInstructors = await prisma.courseInstructor.findMany({
|
||||||
where: { course_id: input.course_id },
|
where: { course_id: input.course_id },
|
||||||
|
|
@ -513,7 +514,7 @@ export class CoursesInstructorService {
|
||||||
],
|
],
|
||||||
role: { code: 'INSTRUCTOR' },
|
role: { code: 'INSTRUCTOR' },
|
||||||
id: {
|
id: {
|
||||||
notIn: [decoded.id, ...existingInstructorIds],
|
notIn: [input.userId, ...existingInstructorIds],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
|
|
@ -548,9 +549,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to search instructors', { error });
|
logger.error('Failed to search instructors', { error });
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: input.course_id,
|
entityId: input.course_id,
|
||||||
|
|
@ -566,7 +566,7 @@ export class CoursesInstructorService {
|
||||||
static async addInstructorToCourse(addinstructorCourse: addinstructorCourse): Promise<addinstructorCourseResponse> {
|
static async addInstructorToCourse(addinstructorCourse: addinstructorCourse): Promise<addinstructorCourseResponse> {
|
||||||
try {
|
try {
|
||||||
// Validate user is instructor of this course
|
// 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
|
// Find user by email or username
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
|
|
@ -604,9 +604,8 @@ export class CoursesInstructorService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const decoded = jwt.decode(addinstructorCourse.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: addinstructorCourse.userId,
|
||||||
action: AuditAction.CREATE,
|
action: AuditAction.CREATE,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: addinstructorCourse.course_id,
|
entityId: addinstructorCourse.course_id,
|
||||||
|
|
@ -622,9 +621,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to add instructor to course', { error });
|
logger.error('Failed to add instructor to course', { error });
|
||||||
const decoded = jwt.decode(addinstructorCourse.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: addinstructorCourse.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: addinstructorCourse.course_id,
|
entityId: addinstructorCourse.course_id,
|
||||||
|
|
@ -639,7 +637,6 @@ export class CoursesInstructorService {
|
||||||
|
|
||||||
static async removeInstructorFromCourse(removeinstructorCourse: removeinstructorCourse): Promise<removeinstructorCourseResponse> {
|
static async removeInstructorFromCourse(removeinstructorCourse: removeinstructorCourse): Promise<removeinstructorCourseResponse> {
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(removeinstructorCourse.token, config.jwt.secret) as { id: number; type: string };
|
|
||||||
await prisma.courseInstructor.delete({
|
await prisma.courseInstructor.delete({
|
||||||
where: {
|
where: {
|
||||||
course_id_user_id: {
|
course_id_user_id: {
|
||||||
|
|
@ -650,7 +647,7 @@ export class CoursesInstructorService {
|
||||||
});
|
});
|
||||||
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: removeinstructorCourse.userId,
|
||||||
action: AuditAction.DELETE,
|
action: AuditAction.DELETE,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: removeinstructorCourse.course_id,
|
entityId: removeinstructorCourse.course_id,
|
||||||
|
|
@ -667,9 +664,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to remove instructor from course', { error });
|
logger.error('Failed to remove instructor from course', { error });
|
||||||
const decoded = jwt.decode(removeinstructorCourse.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: removeinstructorCourse.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: removeinstructorCourse.course_id,
|
entityId: removeinstructorCourse.course_id,
|
||||||
|
|
@ -684,7 +680,6 @@ export class CoursesInstructorService {
|
||||||
|
|
||||||
static async listInstructorsOfCourse(listinstructorCourse: listinstructorCourse): Promise<listinstructorCourseResponse> {
|
static async listInstructorsOfCourse(listinstructorCourse: listinstructorCourse): Promise<listinstructorCourseResponse> {
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(listinstructorCourse.token, config.jwt.secret) as { id: number; type: string };
|
|
||||||
const courseInstructors = await prisma.courseInstructor.findMany({
|
const courseInstructors = await prisma.courseInstructor.findMany({
|
||||||
where: {
|
where: {
|
||||||
course_id: listinstructorCourse.course_id,
|
course_id: listinstructorCourse.course_id,
|
||||||
|
|
@ -728,9 +723,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to retrieve instructors of course', { error });
|
logger.error('Failed to retrieve instructors of course', { error });
|
||||||
const decoded = jwt.decode(listinstructorCourse.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: listinstructorCourse.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: listinstructorCourse.course_id,
|
entityId: listinstructorCourse.course_id,
|
||||||
|
|
@ -739,14 +733,12 @@ export class CoursesInstructorService {
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setPrimaryInstructor(setprimaryCourseInstructor: setprimaryCourseInstructor): Promise<setprimaryCourseInstructorResponse> {
|
static async setPrimaryInstructor(setprimaryCourseInstructor: setprimaryCourseInstructor): Promise<setprimaryCourseInstructorResponse> {
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(setprimaryCourseInstructor.token, config.jwt.secret) as { id: number; type: string };
|
|
||||||
await prisma.courseInstructor.update({
|
await prisma.courseInstructor.update({
|
||||||
where: {
|
where: {
|
||||||
course_id_user_id: {
|
course_id_user_id: {
|
||||||
|
|
@ -760,7 +752,7 @@ export class CoursesInstructorService {
|
||||||
});
|
});
|
||||||
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: setprimaryCourseInstructor.userId,
|
||||||
action: AuditAction.UPDATE,
|
action: AuditAction.UPDATE,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: setprimaryCourseInstructor.course_id,
|
entityId: setprimaryCourseInstructor.course_id,
|
||||||
|
|
@ -777,9 +769,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to set primary instructor', { error });
|
logger.error('Failed to set primary instructor', { error });
|
||||||
const decoded = jwt.decode(setprimaryCourseInstructor.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: setprimaryCourseInstructor.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: setprimaryCourseInstructor.course_id,
|
entityId: setprimaryCourseInstructor.course_id,
|
||||||
|
|
@ -792,11 +783,10 @@ export class CoursesInstructorService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async validateCourseInstructor(token: string, courseId: number): Promise<{ user_id: number; is_primary: boolean }> {
|
static async validateCourseInstructor(userId: number, courseId: number): Promise<{ user_id: number; is_primary: boolean }> {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
|
||||||
const courseInstructor = await prisma.courseInstructor.findFirst({
|
const courseInstructor = await prisma.courseInstructor.findFirst({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id: courseId
|
course_id: courseId
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -825,10 +815,10 @@ export class CoursesInstructorService {
|
||||||
*/
|
*/
|
||||||
static async getEnrolledStudents(input: GetEnrolledStudentsInput): Promise<GetEnrolledStudentsResponse> {
|
static async getEnrolledStudents(input: GetEnrolledStudentsInput): Promise<GetEnrolledStudentsResponse> {
|
||||||
try {
|
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
|
// Validate instructor
|
||||||
await this.validateCourseInstructor(token, course_id);
|
await this.validateCourseInstructor(userId, course_id);
|
||||||
|
|
||||||
// Build where clause
|
// Build where clause
|
||||||
const whereClause: any = { course_id };
|
const whereClause: any = { course_id };
|
||||||
|
|
@ -903,9 +893,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error getting enrolled students: ${error}`);
|
logger.error(`Error getting enrolled students: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: input.course_id,
|
entityId: input.course_id,
|
||||||
|
|
@ -924,11 +913,10 @@ export class CoursesInstructorService {
|
||||||
*/
|
*/
|
||||||
static async getQuizScores(input: GetQuizScoresInput): Promise<GetQuizScoresResponse> {
|
static async getQuizScores(input: GetQuizScoresInput): Promise<GetQuizScoresResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, page = 1, limit = 20, search, is_passed } = input;
|
const { userId, course_id, lesson_id, page = 1, limit = 20, search, is_passed } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Validate instructor
|
// Validate instructor
|
||||||
await this.validateCourseInstructor(token, course_id);
|
await this.validateCourseInstructor(userId, course_id);
|
||||||
|
|
||||||
// Get lesson and verify it's a QUIZ type
|
// Get lesson and verify it's a QUIZ type
|
||||||
const lesson = await prisma.lesson.findUnique({
|
const lesson = await prisma.lesson.findUnique({
|
||||||
|
|
@ -1081,9 +1069,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error getting quiz scores: ${error}`);
|
logger.error(`Error getting quiz scores: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: input.course_id,
|
entityId: input.course_id,
|
||||||
|
|
@ -1102,10 +1089,10 @@ export class CoursesInstructorService {
|
||||||
*/
|
*/
|
||||||
static async getQuizAttemptDetail(input: GetQuizAttemptDetailInput): Promise<GetQuizAttemptDetailResponse> {
|
static async getQuizAttemptDetail(input: GetQuizAttemptDetailInput): Promise<GetQuizAttemptDetailResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, student_id } = input;
|
const { userId, course_id, lesson_id, student_id } = input;
|
||||||
|
|
||||||
// Validate instructor
|
// Validate instructor
|
||||||
await this.validateCourseInstructor(token, course_id);
|
await this.validateCourseInstructor(userId, course_id);
|
||||||
|
|
||||||
// Get lesson and verify it's a QUIZ type
|
// Get lesson and verify it's a QUIZ type
|
||||||
const lesson = await prisma.lesson.findUnique({
|
const lesson = await prisma.lesson.findUnique({
|
||||||
|
|
@ -1205,9 +1192,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error getting quiz attempt detail: ${error}`);
|
logger.error(`Error getting quiz attempt detail: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: input.course_id,
|
entityId: input.course_id,
|
||||||
|
|
@ -1226,10 +1212,10 @@ export class CoursesInstructorService {
|
||||||
*/
|
*/
|
||||||
static async getEnrolledStudentDetail(input: GetEnrolledStudentDetailInput): Promise<GetEnrolledStudentDetailResponse> {
|
static async getEnrolledStudentDetail(input: GetEnrolledStudentDetailInput): Promise<GetEnrolledStudentDetailResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, student_id } = input;
|
const { userId, course_id, student_id } = input;
|
||||||
|
|
||||||
// Validate instructor
|
// Validate instructor
|
||||||
await this.validateCourseInstructor(token, course_id);
|
await this.validateCourseInstructor(userId, course_id);
|
||||||
|
|
||||||
// Get student info
|
// Get student info
|
||||||
const student = await prisma.user.findUnique({
|
const student = await prisma.user.findUnique({
|
||||||
|
|
@ -1353,9 +1339,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error getting enrolled student detail: ${error}`);
|
logger.error(`Error getting enrolled student detail: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: input.course_id,
|
entityId: input.course_id,
|
||||||
|
|
@ -1372,12 +1357,10 @@ export class CoursesInstructorService {
|
||||||
* ดึงประวัติการขออนุมัติคอร์ส
|
* ดึงประวัติการขออนุมัติคอร์ส
|
||||||
* Get course approval history for instructor to see rejection reasons
|
* 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 {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Validate instructor access
|
// Validate instructor access
|
||||||
await this.validateCourseInstructor(token, courseId);
|
await this.validateCourseInstructor(userId, courseId);
|
||||||
|
|
||||||
// Get course with approval history
|
// Get course with approval history
|
||||||
const course = await prisma.course.findUnique({
|
const course = await prisma.course.findUnique({
|
||||||
|
|
@ -1420,9 +1403,8 @@ export class CoursesInstructorService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error getting course approval history: ${error}`);
|
logger.error(`Error getting course approval history: ${error}`);
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -1434,4 +1416,267 @@ export class CoursesInstructorService {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone a course (including chapters, lessons, quizzes, attachments)
|
||||||
|
*/
|
||||||
|
static async cloneCourse(input: CloneCourseInput): Promise<CloneCourseResponse> {
|
||||||
|
try {
|
||||||
|
const { userId, course_id, title } = input;
|
||||||
|
|
||||||
|
// Validate instructor
|
||||||
|
const courseInstructor = await this.validateCourseInstructor(userId, course_id);
|
||||||
|
if (!courseInstructor) {
|
||||||
|
throw new ForbiddenError('You are not an instructor of this course');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch original course with all relations
|
||||||
|
const originalCourse = await prisma.course.findUnique({
|
||||||
|
where: { id: course_id },
|
||||||
|
include: {
|
||||||
|
chapters: {
|
||||||
|
orderBy: { sort_order: 'asc' },
|
||||||
|
include: {
|
||||||
|
lessons: {
|
||||||
|
orderBy: { sort_order: 'asc' },
|
||||||
|
include: {
|
||||||
|
attachments: true,
|
||||||
|
quiz: {
|
||||||
|
include: {
|
||||||
|
questions: {
|
||||||
|
include: {
|
||||||
|
choices: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!originalCourse) {
|
||||||
|
throw new NotFoundError('Course not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use transaction for atomic creation
|
||||||
|
const newCourse = await prisma.$transaction(async (tx) => {
|
||||||
|
// 1. Create new Course
|
||||||
|
const createdCourse = await tx.course.create({
|
||||||
|
data: {
|
||||||
|
title: title as Prisma.InputJsonValue,
|
||||||
|
slug: `${originalCourse.slug}-clone-${Date.now()}`, // Temporary slug
|
||||||
|
description: originalCourse.description ?? Prisma.JsonNull,
|
||||||
|
thumbnail_url: originalCourse.thumbnail_url,
|
||||||
|
category_id: originalCourse.category_id,
|
||||||
|
price: originalCourse.price,
|
||||||
|
is_free: originalCourse.is_free,
|
||||||
|
have_certificate: originalCourse.have_certificate,
|
||||||
|
status: 'DRAFT', // Reset status
|
||||||
|
created_by: userId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Add Instructor (Requester as primary)
|
||||||
|
await tx.courseInstructor.create({
|
||||||
|
data: {
|
||||||
|
course_id: createdCourse.id,
|
||||||
|
user_id: userId,
|
||||||
|
is_primary: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mapping for oldLessonId -> newLessonId for prerequisites
|
||||||
|
const lessonIdMap = new Map<number, number>();
|
||||||
|
const lessonsToUpdatePrerequisites: { newLessonId: number; oldPrerequisites: number[] }[] = [];
|
||||||
|
|
||||||
|
// 3. Clone Chapters and Lessons
|
||||||
|
for (const chapter of originalCourse.chapters) {
|
||||||
|
const newChapter = await tx.chapter.create({
|
||||||
|
data: {
|
||||||
|
course_id: createdCourse.id,
|
||||||
|
title: chapter.title as Prisma.InputJsonValue,
|
||||||
|
description: chapter.description ?? Prisma.JsonNull,
|
||||||
|
sort_order: chapter.sort_order,
|
||||||
|
is_published: chapter.is_published
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const lesson of chapter.lessons) {
|
||||||
|
const newLesson = await tx.lesson.create({
|
||||||
|
data: {
|
||||||
|
chapter_id: newChapter.id,
|
||||||
|
title: lesson.title as Prisma.InputJsonValue,
|
||||||
|
content: lesson.content ?? Prisma.JsonNull,
|
||||||
|
type: lesson.type,
|
||||||
|
sort_order: lesson.sort_order,
|
||||||
|
is_published: lesson.is_published,
|
||||||
|
duration_minutes: lesson.duration_minutes,
|
||||||
|
prerequisite_lesson_ids: Prisma.JsonNull // Will update later
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
lessonIdMap.set(lesson.id, newLesson.id);
|
||||||
|
|
||||||
|
// Store prerequisites for later update
|
||||||
|
if (Array.isArray(lesson.prerequisite_lesson_ids) && lesson.prerequisite_lesson_ids.length > 0) {
|
||||||
|
lessonsToUpdatePrerequisites.push({
|
||||||
|
newLessonId: newLesson.id,
|
||||||
|
oldPrerequisites: lesson.prerequisite_lesson_ids as number[]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone Attachments
|
||||||
|
if (lesson.attachments && lesson.attachments.length > 0) {
|
||||||
|
await tx.lessonAttachment.createMany({
|
||||||
|
data: lesson.attachments.map(att => ({
|
||||||
|
lesson_id: newLesson.id,
|
||||||
|
file_name: att.file_name,
|
||||||
|
file_path: att.file_path, // Reuse file path
|
||||||
|
file_size: att.file_size,
|
||||||
|
mime_type: att.mime_type,
|
||||||
|
sort_order: att.sort_order,
|
||||||
|
description: att.description ?? Prisma.JsonNull
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone Quiz
|
||||||
|
if (lesson.quiz) {
|
||||||
|
const newQuiz = await tx.quiz.create({
|
||||||
|
data: {
|
||||||
|
lesson_id: newLesson.id,
|
||||||
|
title: lesson.quiz.title as Prisma.InputJsonValue,
|
||||||
|
description: lesson.quiz.description ?? Prisma.JsonNull,
|
||||||
|
passing_score: lesson.quiz.passing_score,
|
||||||
|
allow_multiple_attempts: lesson.quiz.allow_multiple_attempts,
|
||||||
|
time_limit: lesson.quiz.time_limit,
|
||||||
|
shuffle_questions: lesson.quiz.shuffle_questions,
|
||||||
|
shuffle_choices: lesson.quiz.shuffle_choices,
|
||||||
|
show_answers_after_completion: lesson.quiz.show_answers_after_completion,
|
||||||
|
created_by: userId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const question of lesson.quiz.questions) {
|
||||||
|
await tx.question.create({
|
||||||
|
data: {
|
||||||
|
quiz_id: newQuiz.id,
|
||||||
|
question: question.question as Prisma.InputJsonValue,
|
||||||
|
explanation: question.explanation ?? Prisma.JsonNull,
|
||||||
|
question_type: question.question_type,
|
||||||
|
score: question.score,
|
||||||
|
sort_order: question.sort_order,
|
||||||
|
choices: {
|
||||||
|
create: question.choices.map(choice => ({
|
||||||
|
text: choice.text as Prisma.InputJsonValue,
|
||||||
|
is_correct: choice.is_correct,
|
||||||
|
sort_order: choice.sort_order
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Update Prerequisites
|
||||||
|
for (const item of lessonsToUpdatePrerequisites) {
|
||||||
|
const newPrerequisites = item.oldPrerequisites
|
||||||
|
.map(oldId => lessonIdMap.get(oldId))
|
||||||
|
.filter((id): id is number => id !== undefined);
|
||||||
|
|
||||||
|
if (newPrerequisites.length > 0) {
|
||||||
|
await tx.lesson.update({
|
||||||
|
where: { id: item.newLessonId },
|
||||||
|
data: {
|
||||||
|
prerequisite_lesson_ids: newPrerequisites
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return createdCourse;
|
||||||
|
});
|
||||||
|
|
||||||
|
await auditService.logSync({
|
||||||
|
userId: input.userId,
|
||||||
|
action: AuditAction.CREATE,
|
||||||
|
entityType: 'Course',
|
||||||
|
entityId: newCourse.id,
|
||||||
|
metadata: {
|
||||||
|
operation: 'clone_course',
|
||||||
|
original_course_id: course_id,
|
||||||
|
new_course_id: newCourse.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: 201,
|
||||||
|
message: 'Course cloned successfully',
|
||||||
|
data: {
|
||||||
|
id: newCourse.id,
|
||||||
|
title: newCourse.title as { th: string; en: string }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Error cloning course: ${error}`);
|
||||||
|
await auditService.logSync({
|
||||||
|
userId: input.userId,
|
||||||
|
action: AuditAction.ERROR,
|
||||||
|
entityType: 'Course',
|
||||||
|
entityId: input.course_id,
|
||||||
|
metadata: {
|
||||||
|
operation: 'clone_course',
|
||||||
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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> {
|
async enrollCourse(input: EnrollCourseInput): Promise<EnrollCourseResponse> {
|
||||||
try {
|
try {
|
||||||
const { course_id } = input;
|
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({
|
const course = await prisma.course.findUnique({
|
||||||
where: { id: course_id },
|
where: { id: course_id },
|
||||||
|
|
@ -146,7 +146,7 @@ export class CoursesStudentService {
|
||||||
const existingEnrollment = await prisma.enrollment.findUnique({
|
const existingEnrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -159,7 +159,7 @@ export class CoursesStudentService {
|
||||||
const enrollment = await prisma.enrollment.create({
|
const enrollment = await prisma.enrollment.create({
|
||||||
data: {
|
data: {
|
||||||
course_id,
|
course_id,
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
status: 'ENROLLED',
|
status: 'ENROLLED',
|
||||||
enrolled_at: new Date(),
|
enrolled_at: new Date(),
|
||||||
},
|
},
|
||||||
|
|
@ -167,11 +167,11 @@ export class CoursesStudentService {
|
||||||
|
|
||||||
// Audit log - ENROLL
|
// Audit log - ENROLL
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decoded.id,
|
userId: userId,
|
||||||
action: AuditAction.ENROLL,
|
action: AuditAction.ENROLL,
|
||||||
entityType: 'Enrollment',
|
entityType: 'Enrollment',
|
||||||
entityId: enrollment.id,
|
entityId: enrollment.id,
|
||||||
newValue: { course_id, user_id: decoded.id, status: 'ENROLLED' }
|
newValue: { course_id, user_id: userId, status: 'ENROLLED' }
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -187,9 +187,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error enrolling in course: ${error}`);
|
logger.error(`Error enrolling in course: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Enrollment',
|
entityType: 'Enrollment',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -206,13 +206,13 @@ export class CoursesStudentService {
|
||||||
|
|
||||||
async GetEnrolledCourses(input: ListEnrolledCoursesInput): Promise<ListEnrolledCoursesResponse> {
|
async GetEnrolledCourses(input: ListEnrolledCoursesInput): Promise<ListEnrolledCoursesResponse> {
|
||||||
try {
|
try {
|
||||||
const { token } = input;
|
// destructure input
|
||||||
const page = input.page ?? 1;
|
const page = input.page ?? 1;
|
||||||
const limit = input.limit ?? 20;
|
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({
|
const enrollments = await prisma.enrollment.findMany({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
course: {
|
course: {
|
||||||
|
|
@ -230,7 +230,7 @@ export class CoursesStudentService {
|
||||||
});
|
});
|
||||||
const total = await prisma.enrollment.count({
|
const total = await prisma.enrollment.count({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -274,9 +274,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Enrollment',
|
entityType: 'Enrollment',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -290,8 +290,8 @@ export class CoursesStudentService {
|
||||||
}
|
}
|
||||||
async getCourseLearning(input: GetCourseLearningInput): Promise<GetCourseLearningResponse> {
|
async getCourseLearning(input: GetCourseLearningInput): Promise<GetCourseLearningResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id } = input;
|
const { course_id } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
const userId = input.userId;
|
||||||
|
|
||||||
// Get course with chapters and lessons (basic info only)
|
// Get course with chapters and lessons (basic info only)
|
||||||
const course = await prisma.course.findUnique({
|
const course = await prisma.course.findUnique({
|
||||||
|
|
@ -330,7 +330,7 @@ export class CoursesStudentService {
|
||||||
const enrollment = await prisma.enrollment.findUnique({
|
const enrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -340,11 +340,24 @@ export class CoursesStudentService {
|
||||||
throw new ForbiddenError('You are not enrolled in this course');
|
throw new ForbiddenError('You are not enrolled in this course');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update last_accessed_at (fire-and-forget — ไม่ block response)
|
||||||
|
if (enrollment.status === 'ENROLLED') {
|
||||||
|
prisma.enrollment.update({
|
||||||
|
where: {
|
||||||
|
unique_enrollment: {
|
||||||
|
user_id: userId,
|
||||||
|
course_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: { last_accessed_at: new Date() },
|
||||||
|
}).catch(err => logger.warn(`Failed to update last_accessed_at: ${err}`));
|
||||||
|
}
|
||||||
|
|
||||||
// Get all lesson progress for this user and course
|
// Get all lesson progress for this user and course
|
||||||
const lessonIds = course.chapters.flatMap(ch => ch.lessons.map(l => l.id));
|
const lessonIds = course.chapters.flatMap(ch => ch.lessons.map(l => l.id));
|
||||||
const lessonProgress = await prisma.lessonProgress.findMany({
|
const lessonProgress = await prisma.lessonProgress.findMany({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
lesson_id: { in: lessonIds },
|
lesson_id: { in: lessonIds },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -440,9 +453,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Enrollment',
|
entityType: 'Enrollment',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -457,8 +470,8 @@ export class CoursesStudentService {
|
||||||
|
|
||||||
async getlessonContent(input: GetLessonContentInput): Promise<GetLessonContentResponse> {
|
async getlessonContent(input: GetLessonContentInput): Promise<GetLessonContentResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id } = input;
|
const { course_id, lesson_id } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
const userId = input.userId;
|
||||||
|
|
||||||
// Import MinIO functions
|
// Import MinIO functions
|
||||||
|
|
||||||
|
|
@ -466,7 +479,7 @@ export class CoursesStudentService {
|
||||||
const enrollment = await prisma.enrollment.findUnique({
|
const enrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -515,7 +528,7 @@ export class CoursesStudentService {
|
||||||
const lessonProgress = await prisma.lessonProgress.findUnique({
|
const lessonProgress = await prisma.lessonProgress.findUnique({
|
||||||
where: {
|
where: {
|
||||||
user_id_lesson_id: {
|
user_id_lesson_id: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
lesson_id,
|
lesson_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -626,7 +639,7 @@ export class CoursesStudentService {
|
||||||
// Get latest quiz attempt for this user
|
// Get latest quiz attempt for this user
|
||||||
latestQuizAttempt = await prisma.quizAttempt.findFirst({
|
latestQuizAttempt = await prisma.quizAttempt.findFirst({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
quiz_id: lesson.quiz.id,
|
quiz_id: lesson.quiz.id,
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
|
|
@ -713,9 +726,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Enrollment',
|
entityType: 'Enrollment',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -731,14 +744,14 @@ export class CoursesStudentService {
|
||||||
|
|
||||||
async checkAccessLesson(input: CheckLessonAccessInput): Promise<CheckLessonAccessResponse> {
|
async checkAccessLesson(input: CheckLessonAccessInput): Promise<CheckLessonAccessResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id } = input;
|
const { course_id, lesson_id } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
const userId = input.userId;
|
||||||
|
|
||||||
// Check enrollment
|
// Check enrollment
|
||||||
const enrollment = await prisma.enrollment.findUnique({
|
const enrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -832,7 +845,7 @@ export class CoursesStudentService {
|
||||||
// Get user's progress for prerequisite lessons
|
// Get user's progress for prerequisite lessons
|
||||||
const prerequisiteProgress = await prisma.lessonProgress.findMany({
|
const prerequisiteProgress = await prisma.lessonProgress.findMany({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
lesson_id: { in: prerequisiteIds },
|
lesson_id: { in: prerequisiteIds },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -866,7 +879,7 @@ export class CoursesStudentService {
|
||||||
// Check if user passed the quiz
|
// Check if user passed the quiz
|
||||||
const quizAttempt = await prisma.quizAttempt.findFirst({
|
const quizAttempt = await prisma.quizAttempt.findFirst({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
quiz_id: prereqLesson.quiz.id,
|
quiz_id: prereqLesson.quiz.id,
|
||||||
is_passed: true,
|
is_passed: true,
|
||||||
},
|
},
|
||||||
|
|
@ -912,9 +925,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Enrollment',
|
entityType: 'Enrollment',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -929,8 +942,8 @@ export class CoursesStudentService {
|
||||||
|
|
||||||
async getVideoProgress(input: GetVideoProgressInput): Promise<GetVideoProgressResponse> {
|
async getVideoProgress(input: GetVideoProgressInput): Promise<GetVideoProgressResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, lesson_id } = input;
|
const { lesson_id } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
const userId = input.userId;
|
||||||
|
|
||||||
// Get lesson to find course_id
|
// Get lesson to find course_id
|
||||||
const lesson = await prisma.lesson.findUnique({
|
const lesson = await prisma.lesson.findUnique({
|
||||||
|
|
@ -953,7 +966,7 @@ export class CoursesStudentService {
|
||||||
const enrollment = await prisma.enrollment.findUnique({
|
const enrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -967,7 +980,7 @@ export class CoursesStudentService {
|
||||||
const progress = await prisma.lessonProgress.findUnique({
|
const progress = await prisma.lessonProgress.findUnique({
|
||||||
where: {
|
where: {
|
||||||
user_id_lesson_id: {
|
user_id_lesson_id: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
lesson_id,
|
lesson_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -997,9 +1010,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Enrollment',
|
entityType: 'Enrollment',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -1014,8 +1027,8 @@ export class CoursesStudentService {
|
||||||
|
|
||||||
async saveVideoProgress(input: SaveVideoProgressInput): Promise<SaveVideoProgressResponse> {
|
async saveVideoProgress(input: SaveVideoProgressInput): Promise<SaveVideoProgressResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, lesson_id, video_progress_seconds, video_duration_seconds } = input;
|
const { lesson_id, video_progress_seconds, video_duration_seconds } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
const userId = input.userId;
|
||||||
|
|
||||||
// Get lesson to find course_id
|
// Get lesson to find course_id
|
||||||
const lesson = await prisma.lesson.findUnique({
|
const lesson = await prisma.lesson.findUnique({
|
||||||
|
|
@ -1038,7 +1051,7 @@ export class CoursesStudentService {
|
||||||
const enrollment = await prisma.enrollment.findUnique({
|
const enrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -1061,12 +1074,12 @@ export class CoursesStudentService {
|
||||||
const progress = await prisma.lessonProgress.upsert({
|
const progress = await prisma.lessonProgress.upsert({
|
||||||
where: {
|
where: {
|
||||||
user_id_lesson_id: {
|
user_id_lesson_id: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
lesson_id,
|
lesson_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
lesson_id,
|
lesson_id,
|
||||||
video_progress_seconds,
|
video_progress_seconds,
|
||||||
video_duration_seconds: video_duration_seconds ?? null,
|
video_duration_seconds: video_duration_seconds ?? null,
|
||||||
|
|
@ -1085,7 +1098,7 @@ export class CoursesStudentService {
|
||||||
// If video completed, mark lesson as complete and update enrollment progress
|
// If video completed, mark lesson as complete and update enrollment progress
|
||||||
let enrollmentProgress: { progress_percentage: number; is_course_completed: boolean } | undefined;
|
let enrollmentProgress: { progress_percentage: number; is_course_completed: boolean } | undefined;
|
||||||
if (isCompleted) {
|
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;
|
enrollmentProgress = result.enrollmentProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1105,9 +1118,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Enrollment',
|
entityType: 'Enrollment',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -1122,8 +1135,8 @@ export class CoursesStudentService {
|
||||||
|
|
||||||
async completeLesson(input: CompleteLessonInput): Promise<CompleteLessonResponse> {
|
async completeLesson(input: CompleteLessonInput): Promise<CompleteLessonResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, lesson_id } = input;
|
const { lesson_id } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
const userId = input.userId;
|
||||||
|
|
||||||
// Get lesson with chapter and course info
|
// Get lesson with chapter and course info
|
||||||
const lesson = await prisma.lesson.findUnique({
|
const lesson = await prisma.lesson.findUnique({
|
||||||
|
|
@ -1172,7 +1185,7 @@ export class CoursesStudentService {
|
||||||
const enrollment = await prisma.enrollment.findUnique({
|
const enrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -1183,7 +1196,7 @@ export class CoursesStudentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark lesson as complete and update enrollment progress
|
// 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;
|
const { progress_percentage: course_progress_percentage, is_course_completed } = enrollmentProgress;
|
||||||
|
|
||||||
// Find next lesson
|
// Find next lesson
|
||||||
|
|
@ -1212,7 +1225,7 @@ export class CoursesStudentService {
|
||||||
// Check if certificate already exists
|
// Check if certificate already exists
|
||||||
const existingCertificate = await prisma.certificate.findFirst({
|
const existingCertificate = await prisma.certificate.findFirst({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -1220,10 +1233,10 @@ export class CoursesStudentService {
|
||||||
if (!existingCertificate) {
|
if (!existingCertificate) {
|
||||||
await prisma.certificate.create({
|
await prisma.certificate.create({
|
||||||
data: {
|
data: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
enrollment_id: enrollment.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(),
|
issued_at: new Date(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -1248,9 +1261,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error completing lesson: ${error}`);
|
logger.error(`Error completing lesson: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'LessonProgress',
|
entityType: 'LessonProgress',
|
||||||
entityId: input.lesson_id,
|
entityId: input.lesson_id,
|
||||||
|
|
@ -1270,14 +1283,14 @@ export class CoursesStudentService {
|
||||||
*/
|
*/
|
||||||
async submitQuiz(input: SubmitQuizInput): Promise<SubmitQuizResponse> {
|
async submitQuiz(input: SubmitQuizInput): Promise<SubmitQuizResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id, answers } = input;
|
const { course_id, lesson_id, answers } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
const userId = input.userId;
|
||||||
|
|
||||||
// Check enrollment
|
// Check enrollment
|
||||||
const enrollment = await prisma.enrollment.findUnique({
|
const enrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -1318,7 +1331,7 @@ export class CoursesStudentService {
|
||||||
// Get previous attempt count
|
// Get previous attempt count
|
||||||
const previousAttempts = await prisma.quizAttempt.count({
|
const previousAttempts = await prisma.quizAttempt.count({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
quiz_id: quiz.id,
|
quiz_id: quiz.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -1371,7 +1384,7 @@ export class CoursesStudentService {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const quizAttempt = await prisma.quizAttempt.create({
|
const quizAttempt = await prisma.quizAttempt.create({
|
||||||
data: {
|
data: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
quiz_id: quiz.id,
|
quiz_id: quiz.id,
|
||||||
score: earnedScore,
|
score: earnedScore,
|
||||||
total_questions: quiz.questions.length,
|
total_questions: quiz.questions.length,
|
||||||
|
|
@ -1387,7 +1400,7 @@ export class CoursesStudentService {
|
||||||
// If passed, mark lesson as complete and update enrollment progress
|
// If passed, mark lesson as complete and update enrollment progress
|
||||||
let enrollmentProgress: { progress_percentage: number; is_course_completed: boolean } | undefined;
|
let enrollmentProgress: { progress_percentage: number; is_course_completed: boolean } | undefined;
|
||||||
if (isPassed) {
|
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;
|
enrollmentProgress = result.enrollmentProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1416,9 +1429,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error submitting quiz: ${error}`);
|
logger.error(`Error submitting quiz: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'QuizAttempt',
|
entityType: 'QuizAttempt',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -1439,14 +1452,14 @@ export class CoursesStudentService {
|
||||||
*/
|
*/
|
||||||
async getQuizAttempts(input: GetQuizAttemptsInput): Promise<GetQuizAttemptsResponse> {
|
async getQuizAttempts(input: GetQuizAttemptsInput): Promise<GetQuizAttemptsResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, lesson_id } = input;
|
const { course_id, lesson_id } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
const userId = input.userId;
|
||||||
|
|
||||||
// Check enrollment
|
// Check enrollment
|
||||||
const enrollment = await prisma.enrollment.findUnique({
|
const enrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -1481,7 +1494,7 @@ export class CoursesStudentService {
|
||||||
// Get all quiz attempts for this user
|
// Get all quiz attempts for this user
|
||||||
const attempts = await prisma.quizAttempt.findMany({
|
const attempts = await prisma.quizAttempt.findMany({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
quiz_id: lesson.quiz.id,
|
quiz_id: lesson.quiz.id,
|
||||||
},
|
},
|
||||||
orderBy: { attempt_number: 'desc' },
|
orderBy: { attempt_number: 'desc' },
|
||||||
|
|
@ -1526,10 +1539,9 @@ export class CoursesStudentService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
// userId from middleware
|
||||||
if (decoded?.id) {
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded.id,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'QuizAttempt',
|
entityType: 'QuizAttempt',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -1540,7 +1552,6 @@ export class CoursesStudentService {
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
import { prisma } from '../config/database';
|
import { prisma } from '../config/database';
|
||||||
import { config } from '../config';
|
|
||||||
import { logger } from '../config/logger';
|
import { logger } from '../config/logger';
|
||||||
import { NotFoundError, ValidationError } from '../middleware/errorHandler';
|
import { NotFoundError, ValidationError } from '../middleware/errorHandler';
|
||||||
import jwt from 'jsonwebtoken';
|
|
||||||
import { getPresignedUrl } from '../config/minio';
|
import { getPresignedUrl } from '../config/minio';
|
||||||
import {
|
import {
|
||||||
ListApprovedCoursesResponse,
|
ListApprovedCoursesResponse,
|
||||||
GetCourseByIdResponse,
|
GetCourseByIdResponse,
|
||||||
ToggleRecommendedResponse,
|
ToggleRecommendedResponse,
|
||||||
RecommendedCourseData
|
RecommendedCourseData,
|
||||||
|
RecommendedCourseDetailData
|
||||||
} from '../types/RecommendedCourses.types';
|
} from '../types/RecommendedCourses.types';
|
||||||
import { auditService } from './audit.service';
|
import { auditService } from './audit.service';
|
||||||
import { AuditAction } from '@prisma/client';
|
import { AuditAction } from '@prisma/client';
|
||||||
|
|
@ -18,10 +17,24 @@ export class RecommendedCoursesService {
|
||||||
/**
|
/**
|
||||||
* List all approved courses (for admin to manage recommendations)
|
* List all approved courses (for admin to manage recommendations)
|
||||||
*/
|
*/
|
||||||
static async listApprovedCourses(token: string): Promise<ListApprovedCoursesResponse> {
|
static async listApprovedCourses(
|
||||||
|
userId: number,
|
||||||
|
filters?: { search?: string; categoryId?: number }
|
||||||
|
): Promise<ListApprovedCoursesResponse> {
|
||||||
try {
|
try {
|
||||||
|
const { search, categoryId } = filters ?? {};
|
||||||
|
|
||||||
const courses = await prisma.course.findMany({
|
const courses = await prisma.course.findMany({
|
||||||
where: { status: 'APPROVED' },
|
where: {
|
||||||
|
status: 'APPROVED',
|
||||||
|
...(categoryId ? { category_id: categoryId } : {}),
|
||||||
|
...(search ? {
|
||||||
|
OR: [
|
||||||
|
{ title: { path: ['th'], string_contains: search } },
|
||||||
|
{ title: { path: ['en'], string_contains: search } }
|
||||||
|
]
|
||||||
|
} : {})
|
||||||
|
},
|
||||||
orderBy: [
|
orderBy: [
|
||||||
{ is_recommended: 'desc' },
|
{ is_recommended: 'desc' },
|
||||||
{ updated_at: 'desc' }
|
{ updated_at: 'desc' }
|
||||||
|
|
@ -40,9 +53,9 @@ export class RecommendedCoursesService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
chapters: {
|
_count: {
|
||||||
include: {
|
select: {
|
||||||
lessons: true
|
chapters: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,8 +94,7 @@ export class RecommendedCoursesService {
|
||||||
is_primary: i.is_primary,
|
is_primary: i.is_primary,
|
||||||
user: i.user
|
user: i.user
|
||||||
})),
|
})),
|
||||||
chapters_count: course.chapters.length,
|
chapters_count: course._count.chapters,
|
||||||
lessons_count: course.chapters.reduce((sum, ch) => sum + ch.lessons.length, 0)
|
|
||||||
} as RecommendedCourseData;
|
} as RecommendedCourseData;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
@ -94,10 +106,8 @@ export class RecommendedCoursesService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to list approved courses', { error });
|
logger.error('Failed to list approved courses', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
if (decoded?.id) {
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'RecommendedCourses',
|
entityType: 'RecommendedCourses',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -106,7 +116,6 @@ export class RecommendedCoursesService {
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +123,7 @@ export class RecommendedCoursesService {
|
||||||
/**
|
/**
|
||||||
* Get course by ID (for admin to view details)
|
* 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 {
|
try {
|
||||||
const course = await prisma.course.findUnique({
|
const course = await prisma.course.findUnique({
|
||||||
where: { id: courseId },
|
where: { id: courseId },
|
||||||
|
|
@ -158,7 +167,7 @@ export class RecommendedCoursesService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: RecommendedCourseData = {
|
const data: RecommendedCourseDetailData = {
|
||||||
id: course.id,
|
id: course.id,
|
||||||
title: course.title as { th: string; en: string },
|
title: course.title as { th: string; en: string },
|
||||||
slug: course.slug,
|
slug: course.slug,
|
||||||
|
|
@ -181,8 +190,15 @@ export class RecommendedCoursesService {
|
||||||
is_primary: i.is_primary,
|
is_primary: i.is_primary,
|
||||||
user: i.user
|
user: i.user
|
||||||
})),
|
})),
|
||||||
chapters_count: course.chapters.length,
|
chapters: course.chapters.map(ch => ({
|
||||||
lessons_count: course.chapters.reduce((sum, ch) => sum + ch.lessons.length, 0)
|
id: ch.id,
|
||||||
|
title: ch.title as { th: string; en: string },
|
||||||
|
sort_order: ch.sort_order,
|
||||||
|
lessons: ch.lessons.map(l => ({
|
||||||
|
id: l.id,
|
||||||
|
title: l.title as { th: string; en: string }
|
||||||
|
}))
|
||||||
|
}))
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -192,10 +208,8 @@ export class RecommendedCoursesService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to get course by ID', { 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({
|
await auditService.logSync({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'RecommendedCourses',
|
entityType: 'RecommendedCourses',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -204,7 +218,6 @@ export class RecommendedCoursesService {
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -213,12 +226,11 @@ export class RecommendedCoursesService {
|
||||||
* Toggle course recommendation status
|
* Toggle course recommendation status
|
||||||
*/
|
*/
|
||||||
static async toggleRecommended(
|
static async toggleRecommended(
|
||||||
token: string,
|
userId: number,
|
||||||
courseId: number,
|
courseId: number,
|
||||||
isRecommended: boolean
|
isRecommended: boolean
|
||||||
): Promise<ToggleRecommendedResponse> {
|
): Promise<ToggleRecommendedResponse> {
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
const course = await prisma.course.findUnique({ where: { id: courseId } });
|
const course = await prisma.course.findUnique({ where: { id: courseId } });
|
||||||
if (!course) {
|
if (!course) {
|
||||||
|
|
@ -236,7 +248,7 @@ export class RecommendedCoursesService {
|
||||||
|
|
||||||
// Audit log
|
// Audit log
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.UPDATE,
|
action: AuditAction.UPDATE,
|
||||||
entityType: 'Course',
|
entityType: 'Course',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
@ -255,9 +267,8 @@ export class RecommendedCoursesService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to toggle recommended status', { error });
|
logger.error('Failed to toggle recommended status', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'RecommendedCourses',
|
entityType: 'RecommendedCourses',
|
||||||
entityId: courseId,
|
entityId: courseId,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import { prisma } from '../config/database';
|
import { prisma } from '../config/database';
|
||||||
import { config } from '../config';
|
|
||||||
import { logger } from '../config/logger';
|
import { logger } from '../config/logger';
|
||||||
import { UnauthorizedError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
import { ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
||||||
import jwt from 'jsonwebtoken';
|
|
||||||
import {
|
import {
|
||||||
ListAnnouncementResponse,
|
ListAnnouncementResponse,
|
||||||
CreateAnnouncementInput,
|
CreateAnnouncementInput,
|
||||||
|
|
@ -31,27 +29,26 @@ export class AnnouncementsService {
|
||||||
*/
|
*/
|
||||||
async listAnnouncement(input: ListAnnouncementInput): Promise<ListAnnouncementResponse> {
|
async listAnnouncement(input: ListAnnouncementInput): Promise<ListAnnouncementResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, page = 1, limit = 10 } = input;
|
const { userId, course_id, page = 1, limit = 10 } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; type: string };
|
|
||||||
|
|
||||||
// Check user access - instructor, admin, or enrolled student
|
// Check user access - instructor, admin, or enrolled student
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { id: decoded.id },
|
where: { id: userId },
|
||||||
include: { role: true },
|
include: { role: true },
|
||||||
});
|
});
|
||||||
if (!user) throw new UnauthorizedError('Invalid token');
|
if (!user) throw new ForbiddenError('User not found');
|
||||||
|
|
||||||
// Admin can access all courses
|
// Admin can access all courses
|
||||||
const isAdmin = user.role.code === 'ADMIN';
|
const isAdmin = user.role.code === 'ADMIN';
|
||||||
|
|
||||||
// Check if instructor of this course
|
// Check if instructor of this course
|
||||||
const isInstructor = await prisma.courseInstructor.findFirst({
|
const isInstructor = await prisma.courseInstructor.findFirst({
|
||||||
where: { course_id, user_id: decoded.id },
|
where: { course_id, user_id: userId },
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if enrolled student
|
// Check if enrolled student
|
||||||
const isEnrolled = await prisma.enrollment.findFirst({
|
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');
|
if (!isAdmin && !isInstructor && !isEnrolled) throw new ForbiddenError('You do not have access to this course announcements');
|
||||||
|
|
@ -130,9 +127,8 @@ export class AnnouncementsService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error listing announcements: ${error}`);
|
logger.error(`Error listing announcements: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Announcement',
|
entityType: 'Announcement',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -150,11 +146,10 @@ export class AnnouncementsService {
|
||||||
*/
|
*/
|
||||||
async createAnnouncement(input: CreateAnnouncementInput): Promise<CreateAnnouncementResponse> {
|
async createAnnouncement(input: CreateAnnouncementInput): Promise<CreateAnnouncementResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, title, content, status, is_pinned, published_at, files } = input;
|
const { userId, course_id, title, content, status, is_pinned, published_at, files } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Validate instructor access
|
// 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
|
// Determine published_at: use provided value or default to now if status is PUBLISHED
|
||||||
let finalPublishedAt: Date | null = null;
|
let finalPublishedAt: Date | null = null;
|
||||||
|
|
@ -171,7 +166,7 @@ export class AnnouncementsService {
|
||||||
status: status as any,
|
status: status as any,
|
||||||
is_pinned,
|
is_pinned,
|
||||||
published_at: finalPublishedAt,
|
published_at: finalPublishedAt,
|
||||||
created_by: decoded.id,
|
created_by: userId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -236,9 +231,8 @@ export class AnnouncementsService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error creating announcement: ${error}`);
|
logger.error(`Error creating announcement: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Announcement',
|
entityType: 'Announcement',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -256,11 +250,10 @@ export class AnnouncementsService {
|
||||||
*/
|
*/
|
||||||
async updateAnnouncement(input: UpdateAnnouncementInput): Promise<UpdateAnnouncementResponse> {
|
async updateAnnouncement(input: UpdateAnnouncementInput): Promise<UpdateAnnouncementResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, announcement_id, title, content, status, is_pinned, published_at } = input;
|
const { userId, course_id, announcement_id, title, content, status, is_pinned, published_at } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Validate instructor access
|
// Validate instructor access
|
||||||
await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||||
|
|
||||||
// Check announcement exists and belongs to course
|
// Check announcement exists and belongs to course
|
||||||
const existing = await prisma.announcement.findFirst({
|
const existing = await prisma.announcement.findFirst({
|
||||||
|
|
@ -289,7 +282,7 @@ export class AnnouncementsService {
|
||||||
status: status as any,
|
status: status as any,
|
||||||
is_pinned,
|
is_pinned,
|
||||||
published_at: finalPublishedAt,
|
published_at: finalPublishedAt,
|
||||||
updated_by: decoded.id,
|
updated_by: userId,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
attachments: true,
|
attachments: true,
|
||||||
|
|
@ -320,9 +313,8 @@ export class AnnouncementsService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error updating announcement: ${error}`);
|
logger.error(`Error updating announcement: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Announcement',
|
entityType: 'Announcement',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -340,11 +332,10 @@ export class AnnouncementsService {
|
||||||
*/
|
*/
|
||||||
async deleteAnnouncement(input: DeleteAnnouncementInput): Promise<DeleteAnnouncementResponse> {
|
async deleteAnnouncement(input: DeleteAnnouncementInput): Promise<DeleteAnnouncementResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, announcement_id } = input;
|
const { userId, course_id, announcement_id } = input;
|
||||||
jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Validate instructor access
|
// Validate instructor access
|
||||||
await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||||
|
|
||||||
// Check announcement exists and belongs to course
|
// Check announcement exists and belongs to course
|
||||||
const existing = await prisma.announcement.findFirst({
|
const existing = await prisma.announcement.findFirst({
|
||||||
|
|
@ -376,9 +367,8 @@ export class AnnouncementsService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error deleting announcement: ${error}`);
|
logger.error(`Error deleting announcement: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Announcement',
|
entityType: 'Announcement',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -396,11 +386,10 @@ export class AnnouncementsService {
|
||||||
*/
|
*/
|
||||||
async uploadAttachment(input: UploadAnnouncementAttachmentInput): Promise<UploadAnnouncementAttachmentResponse> {
|
async uploadAttachment(input: UploadAnnouncementAttachmentInput): Promise<UploadAnnouncementAttachmentResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, announcement_id, file } = input;
|
const { userId, course_id, announcement_id, file } = input;
|
||||||
jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Validate instructor access
|
// Validate instructor access
|
||||||
await CoursesInstructorService.validateCourseInstructor(token, course_id);
|
await CoursesInstructorService.validateCourseInstructor(userId, course_id);
|
||||||
|
|
||||||
// Check announcement exists and belongs to course
|
// Check announcement exists and belongs to course
|
||||||
const existing = await prisma.announcement.findFirst({
|
const existing = await prisma.announcement.findFirst({
|
||||||
|
|
@ -451,9 +440,8 @@ export class AnnouncementsService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error uploading attachment: ${error}`);
|
logger.error(`Error uploading attachment: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Announcement',
|
entityType: 'Announcement',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -471,11 +459,10 @@ export class AnnouncementsService {
|
||||||
*/
|
*/
|
||||||
async deleteAttachment(input: DeleteAnnouncementAttachmentInput): Promise<DeleteAnnouncementAttachmentResponse> {
|
async deleteAttachment(input: DeleteAnnouncementAttachmentInput): Promise<DeleteAnnouncementAttachmentResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id, announcement_id, attachment_id } = input;
|
const { userId, course_id, announcement_id, attachment_id } = input;
|
||||||
jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Validate instructor access
|
// 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
|
// Check attachment exists and belongs to announcement in this course
|
||||||
const attachment = await prisma.announcementAttachment.findFirst({
|
const attachment = await prisma.announcementAttachment.findFirst({
|
||||||
|
|
@ -508,9 +495,8 @@ export class AnnouncementsService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error deleting attachment: ${error}`);
|
logger.error(`Error deleting attachment: ${error}`);
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Announcement',
|
entityType: 'Announcement',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ export class AuditService {
|
||||||
* Log พร้อม await (สำหรับ critical actions)
|
* Log พร้อม await (สำหรับ critical actions)
|
||||||
*/
|
*/
|
||||||
async logSync(params: CreateAuditLogParams): Promise<void> {
|
async logSync(params: CreateAuditLogParams): Promise<void> {
|
||||||
|
try {
|
||||||
await prisma.auditLog.create({
|
await prisma.auditLog.create({
|
||||||
data: {
|
data: {
|
||||||
user_id: params.userId,
|
user_id: params.userId,
|
||||||
|
|
@ -50,6 +51,9 @@ export class AuditService {
|
||||||
metadata: params.metadata,
|
metadata: params.metadata,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to create audit log (sync)', { error, params });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,6 @@ export class AuthService {
|
||||||
data: {
|
data: {
|
||||||
token,
|
token,
|
||||||
refreshToken,
|
refreshToken,
|
||||||
user: await this.formatUserResponse(user)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
import { prisma } from '../config/database';
|
import { prisma } from '../config/database';
|
||||||
import { Prisma } from '@prisma/client';
|
import { Prisma } from '@prisma/client';
|
||||||
import { config } from '../config';
|
|
||||||
import { logger } from '../config/logger';
|
import { logger } from '../config/logger';
|
||||||
import jwt from 'jsonwebtoken';
|
|
||||||
import { createCategory, createCategoryResponse, deleteCategoryResponse, updateCategory, updateCategoryResponse, ListCategoriesResponse, Category } from '../types/categories.type';
|
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 { auditService } from './audit.service';
|
||||||
import { AuditAction } from '@prisma/client';
|
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 {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
|
||||||
const newCategory = await prisma.category.create({
|
const newCategory = await prisma.category.create({
|
||||||
data: category
|
data: category
|
||||||
});
|
});
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.CREATE,
|
action: AuditAction.CREATE,
|
||||||
entityType: 'Category',
|
entityType: 'Category',
|
||||||
entityId: newCategory.id,
|
entityId: newCategory.id,
|
||||||
|
|
@ -47,13 +43,13 @@ export class CategoryService {
|
||||||
name: newCategory.name as { th: string; en: string },
|
name: newCategory.name as { th: string; en: string },
|
||||||
slug: newCategory.slug,
|
slug: newCategory.slug,
|
||||||
description: newCategory.description as { th: string; en: string },
|
description: newCategory.description as { th: string; en: string },
|
||||||
created_by: decoded.id,
|
created_by: userId,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to create category', { error });
|
logger.error('Failed to create category', { error });
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Category',
|
entityType: 'Category',
|
||||||
entityId: 0,
|
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 {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
|
||||||
const updatedCategory = await prisma.category.update({
|
const updatedCategory = await prisma.category.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: category
|
data: category
|
||||||
});
|
});
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.UPDATE,
|
action: AuditAction.UPDATE,
|
||||||
entityType: 'Category',
|
entityType: 'Category',
|
||||||
entityId: id,
|
entityId: id,
|
||||||
|
|
@ -88,13 +83,13 @@ export class CategoryService {
|
||||||
name: updatedCategory.name as { th: string; en: string },
|
name: updatedCategory.name as { th: string; en: string },
|
||||||
slug: updatedCategory.slug,
|
slug: updatedCategory.slug,
|
||||||
description: updatedCategory.description as { th: string; en: string },
|
description: updatedCategory.description as { th: string; en: string },
|
||||||
updated_by: decoded.id,
|
updated_by: userId,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to update category', { error });
|
logger.error('Failed to update category', { error });
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Category',
|
entityType: 'Category',
|
||||||
entityId: 0,
|
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 {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; username: string; email: string; roleCode: string };
|
|
||||||
const deletedCategory = await prisma.category.delete({
|
const deletedCategory = await prisma.category.delete({
|
||||||
where: { id }
|
where: { id }
|
||||||
});
|
});
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.DELETE,
|
action: AuditAction.DELETE,
|
||||||
entityType: 'Category',
|
entityType: 'Category',
|
||||||
entityId: id,
|
entityId: id,
|
||||||
|
|
@ -127,7 +121,7 @@ export class CategoryService {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to delete category', { error });
|
logger.error('Failed to delete category', { error });
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Category',
|
entityType: 'Category',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import { prisma } from '../config/database';
|
import { prisma } from '../config/database';
|
||||||
import { config } from '../config';
|
|
||||||
import { logger } from '../config/logger';
|
import { logger } from '../config/logger';
|
||||||
import { NotFoundError, ForbiddenError, ValidationError } from '../middleware/errorHandler';
|
import { NotFoundError, ForbiddenError, ValidationError } from '../middleware/errorHandler';
|
||||||
import jwt from 'jsonwebtoken';
|
|
||||||
import { PDFDocument, rgb } from 'pdf-lib';
|
import { PDFDocument, rgb } from 'pdf-lib';
|
||||||
import fontkit from '@pdf-lib/fontkit';
|
import fontkit from '@pdf-lib/fontkit';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
@ -29,14 +27,13 @@ export class CertificateService {
|
||||||
*/
|
*/
|
||||||
async generateCertificate(input: GenerateCertificateInput): Promise<GenerateCertificateResponse> {
|
async generateCertificate(input: GenerateCertificateInput): Promise<GenerateCertificateResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id } = input;
|
const { userId, course_id } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Check enrollment and completion
|
// Check enrollment and completion
|
||||||
const enrollment = await prisma.enrollment.findUnique({
|
const enrollment = await prisma.enrollment.findUnique({
|
||||||
where: {
|
where: {
|
||||||
unique_enrollment: {
|
unique_enrollment: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -65,7 +62,7 @@ export class CertificateService {
|
||||||
// Check if certificate already exists
|
// Check if certificate already exists
|
||||||
const existingCertificate = await prisma.certificate.findFirst({
|
const existingCertificate = await prisma.certificate.findFirst({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -103,13 +100,13 @@ export class CertificateService {
|
||||||
|
|
||||||
// Upload to MinIO
|
// Upload to MinIO
|
||||||
const timestamp = Date.now();
|
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');
|
await uploadFile(filePath, Buffer.from(pdfBytes), 'application/pdf');
|
||||||
|
|
||||||
// Save to database
|
// Save to database
|
||||||
const certificate = await prisma.certificate.create({
|
const certificate = await prisma.certificate.create({
|
||||||
data: {
|
data: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
enrollment_id: enrollment.id,
|
enrollment_id: enrollment.id,
|
||||||
file_path: filePath,
|
file_path: filePath,
|
||||||
|
|
@ -118,7 +115,7 @@ export class CertificateService {
|
||||||
});
|
});
|
||||||
|
|
||||||
auditService.log({
|
auditService.log({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.CREATE,
|
action: AuditAction.CREATE,
|
||||||
entityType: 'Certificate',
|
entityType: 'Certificate',
|
||||||
entityId: certificate.id,
|
entityId: certificate.id,
|
||||||
|
|
@ -139,9 +136,8 @@ export class CertificateService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to generate certificate', { error });
|
logger.error('Failed to generate certificate', { error });
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Certificate',
|
entityType: 'Certificate',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -160,12 +156,11 @@ export class CertificateService {
|
||||||
*/
|
*/
|
||||||
async getCertificate(input: GetCertificateInput): Promise<GetCertificateResponse> {
|
async getCertificate(input: GetCertificateInput): Promise<GetCertificateResponse> {
|
||||||
try {
|
try {
|
||||||
const { token, course_id } = input;
|
const { userId, course_id } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
const certificate = await prisma.certificate.findFirst({
|
const certificate = await prisma.certificate.findFirst({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
course_id,
|
course_id,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
|
|
@ -202,9 +197,8 @@ export class CertificateService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to get certificate', { error });
|
logger.error('Failed to get certificate', { error });
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Certificate',
|
entityType: 'Certificate',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
@ -223,12 +217,11 @@ export class CertificateService {
|
||||||
*/
|
*/
|
||||||
async listMyCertificates(input: ListMyCertificatesInput): Promise<ListMyCertificatesResponse> {
|
async listMyCertificates(input: ListMyCertificatesInput): Promise<ListMyCertificatesResponse> {
|
||||||
try {
|
try {
|
||||||
const { token } = input;
|
const { userId } = input;
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
const certificates = await prisma.certificate.findMany({
|
const certificates = await prisma.certificate.findMany({
|
||||||
where: {
|
where: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
enrollment: {
|
enrollment: {
|
||||||
|
|
@ -267,9 +260,8 @@ export class CertificateService {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to list certificates', { error });
|
logger.error('Failed to list certificates', { error });
|
||||||
const decoded = jwt.decode(input.token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id,
|
userId: input.userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'Certificate',
|
entityType: 'Certificate',
|
||||||
entityId: 0,
|
entityId: 0,
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,56 @@ export class CoursesService {
|
||||||
const course = await prisma.course.findFirst({
|
const course = await prisma.course.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
status: 'APPROVED' // Only show approved courses to students
|
status: 'APPROVED'
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
creator: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
email: true,
|
||||||
|
profile: {
|
||||||
|
select: {
|
||||||
|
first_name: true,
|
||||||
|
last_name: true,
|
||||||
|
avatar_url: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
instructors: {
|
||||||
|
include: {
|
||||||
|
user: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
email: true,
|
||||||
|
profile: {
|
||||||
|
select: {
|
||||||
|
first_name: true,
|
||||||
|
last_name: true,
|
||||||
|
avatar_url: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
category: {
|
||||||
|
select: { id: true, name: true }
|
||||||
|
},
|
||||||
|
chapters: {
|
||||||
|
orderBy: { sort_order: 'asc' },
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
sort_order: true,
|
||||||
|
lessons: {
|
||||||
|
orderBy: { sort_order: 'asc' },
|
||||||
|
select: { id: true, title: true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -124,12 +173,69 @@ export class CoursesService {
|
||||||
logger.warn(`Failed to generate presigned URL for thumbnail: ${err}`);
|
logger.warn(`Failed to generate presigned URL for thumbnail: ${err}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate presigned URL for creator avatar
|
||||||
|
let creator_avatar_url: string | null = null;
|
||||||
|
if (course.creator.profile?.avatar_url) {
|
||||||
|
try {
|
||||||
|
creator_avatar_url = await getPresignedUrl(course.creator.profile.avatar_url, 3600);
|
||||||
|
} catch (err) {
|
||||||
|
logger.warn(`Failed to generate presigned URL for creator avatar: ${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate presigned URLs for instructor avatars
|
||||||
|
const instructorsWithAvatar = await Promise.all(course.instructors.map(async (i) => {
|
||||||
|
let avatar_url: string | null = null;
|
||||||
|
if (i.user.profile?.avatar_url) {
|
||||||
|
try {
|
||||||
|
avatar_url = await getPresignedUrl(i.user.profile.avatar_url, 3600);
|
||||||
|
} catch (err) {
|
||||||
|
logger.warn(`Failed to generate presigned URL for instructor avatar: ${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
user_id: i.user_id,
|
||||||
|
is_primary: i.is_primary,
|
||||||
|
user: {
|
||||||
|
...i.user,
|
||||||
|
profile: i.user.profile ? {
|
||||||
|
...i.user.profile,
|
||||||
|
avatar_url
|
||||||
|
} : null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: 'Course fetched successfully',
|
message: 'Course fetched successfully',
|
||||||
data: {
|
data: {
|
||||||
...course,
|
...course,
|
||||||
|
title: course.title as { th: string; en: string },
|
||||||
|
description: course.description as { th: string; en: string },
|
||||||
thumbnail_url: thumbnail_presigned_url,
|
thumbnail_url: thumbnail_presigned_url,
|
||||||
|
creator: {
|
||||||
|
...course.creator,
|
||||||
|
profile: course.creator.profile ? {
|
||||||
|
...course.creator.profile,
|
||||||
|
avatar_url: creator_avatar_url
|
||||||
|
} : null
|
||||||
|
},
|
||||||
|
instructors: instructorsWithAvatar,
|
||||||
|
category: course.category ? {
|
||||||
|
id: course.category.id,
|
||||||
|
name: course.category.name as { th: string; en: string }
|
||||||
|
} : null,
|
||||||
|
chapters: course.chapters.map(ch => ({
|
||||||
|
id: ch.id,
|
||||||
|
title: ch.title as { th: string; en: string },
|
||||||
|
sort_order: ch.sort_order,
|
||||||
|
lessons: ch.lessons.map(l => ({
|
||||||
|
id: l.id,
|
||||||
|
title: l.title as { th: string; en: string }
|
||||||
|
}))
|
||||||
|
}))
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ import {
|
||||||
updateAvatarRequest,
|
updateAvatarRequest,
|
||||||
updateAvatarResponse,
|
updateAvatarResponse,
|
||||||
SendVerifyEmailResponse,
|
SendVerifyEmailResponse,
|
||||||
VerifyEmailResponse
|
VerifyEmailResponse,
|
||||||
|
rolesResponse
|
||||||
} from '../types/user.types';
|
} from '../types/user.types';
|
||||||
import nodemailer from 'nodemailer';
|
import nodemailer from 'nodemailer';
|
||||||
import { UnauthorizedError, ValidationError, ForbiddenError } from '../middleware/errorHandler';
|
import { UnauthorizedError, ValidationError, ForbiddenError } from '../middleware/errorHandler';
|
||||||
|
|
@ -23,15 +24,10 @@ import { auditService } from './audit.service';
|
||||||
import { AuditAction } from '@prisma/client';
|
import { AuditAction } from '@prisma/client';
|
||||||
|
|
||||||
export class UserService {
|
export class UserService {
|
||||||
async getUserProfile(token: string): Promise<UserResponse> {
|
async getUserProfile(userId: number): Promise<UserResponse> {
|
||||||
try {
|
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({
|
const user = await prisma.user.findUnique({
|
||||||
where: {
|
where: { id: userId },
|
||||||
id: decoded.id
|
|
||||||
},
|
|
||||||
include: {
|
include: {
|
||||||
profile: true,
|
profile: true,
|
||||||
role: true
|
role: true
|
||||||
|
|
@ -67,14 +63,6 @@ export class UserService {
|
||||||
} : undefined
|
} : undefined
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} 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);
|
logger.error('Error fetching user profile:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
@ -83,12 +71,9 @@ export class UserService {
|
||||||
/**
|
/**
|
||||||
* Change user password
|
* Change user password
|
||||||
*/
|
*/
|
||||||
async changePassword(token: string, oldPassword: string, newPassword: string): Promise<ChangePasswordResponse> {
|
async changePassword(userId: number, oldPassword: string, newPassword: string): Promise<ChangePasswordResponse> {
|
||||||
try {
|
try {
|
||||||
// Decode JWT token to get user ID
|
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||||
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 } });
|
|
||||||
if (!user) throw new UnauthorizedError('User not found');
|
if (!user) throw new UnauthorizedError('User not found');
|
||||||
|
|
||||||
// Check if account is deactivated
|
// Check if account is deactivated
|
||||||
|
|
@ -126,21 +111,12 @@ export class UserService {
|
||||||
message: 'Password changed successfully'
|
message: 'Password changed successfully'
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} 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 });
|
logger.error('Failed to change password', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'User',
|
entityType: 'User',
|
||||||
entityId: decoded?.id || 0,
|
entityId: userId,
|
||||||
metadata: {
|
metadata: {
|
||||||
operation: 'change_password',
|
operation: 'change_password',
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
|
@ -153,12 +129,9 @@ export class UserService {
|
||||||
/**
|
/**
|
||||||
* Update user profile
|
* Update user profile
|
||||||
*/
|
*/
|
||||||
async updateProfile(token: string, profile: ProfileUpdate): Promise<ProfileUpdateResponse> {
|
async updateProfile(userId: number, profile: ProfileUpdate): Promise<ProfileUpdateResponse> {
|
||||||
try {
|
try {
|
||||||
// Decode JWT token to get user ID
|
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||||
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 } });
|
|
||||||
if (!user) throw new UnauthorizedError('User not found');
|
if (!user) throw new UnauthorizedError('User not found');
|
||||||
|
|
||||||
// Check if account is deactivated
|
// Check if account is deactivated
|
||||||
|
|
@ -188,21 +161,12 @@ export class UserService {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} 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 });
|
logger.error('Failed to update profile', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.UPDATE,
|
action: AuditAction.UPDATE,
|
||||||
entityType: 'UserProfile',
|
entityType: 'UserProfile',
|
||||||
entityId: decoded?.id || 0,
|
entityId: userId,
|
||||||
metadata: {
|
metadata: {
|
||||||
operation: 'update_profile',
|
operation: 'update_profile',
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
|
@ -212,16 +176,29 @@ export class UserService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getRoles(): Promise<rolesResponse> {
|
||||||
|
try {
|
||||||
|
const roles = await prisma.role.findMany({
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
code: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return { roles };
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to get roles', { error });
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload avatar picture to MinIO
|
* 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 {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number };
|
|
||||||
|
|
||||||
// Check if user exists
|
// Check if user exists
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { id: decoded.id },
|
where: { id: userId },
|
||||||
include: { profile: true }
|
include: { profile: true }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -240,7 +217,7 @@ export class UserService {
|
||||||
const fileName = file.originalname || 'avatar';
|
const fileName = file.originalname || 'avatar';
|
||||||
const extension = fileName.split('.').pop() || 'jpg';
|
const extension = fileName.split('.').pop() || 'jpg';
|
||||||
const safeFilename = `${timestamp}-${uniqueId}.${extension}`;
|
const safeFilename = `${timestamp}-${uniqueId}.${extension}`;
|
||||||
const filePath = `avatars/${decoded.id}/${safeFilename}`;
|
const filePath = `avatars/${userId}/${safeFilename}`;
|
||||||
|
|
||||||
// Delete old avatar if exists
|
// Delete old avatar if exists
|
||||||
if (user.profile?.avatar_url) {
|
if (user.profile?.avatar_url) {
|
||||||
|
|
@ -260,13 +237,13 @@ export class UserService {
|
||||||
// Update or create profile - store only file path
|
// Update or create profile - store only file path
|
||||||
if (user.profile) {
|
if (user.profile) {
|
||||||
await prisma.userProfile.update({
|
await prisma.userProfile.update({
|
||||||
where: { user_id: decoded.id },
|
where: { user_id: userId },
|
||||||
data: { avatar_url: filePath }
|
data: { avatar_url: filePath }
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await prisma.userProfile.create({
|
await prisma.userProfile.create({
|
||||||
data: {
|
data: {
|
||||||
user_id: decoded.id,
|
user_id: userId,
|
||||||
avatar_url: filePath,
|
avatar_url: filePath,
|
||||||
first_name: '',
|
first_name: '',
|
||||||
last_name: ''
|
last_name: ''
|
||||||
|
|
@ -276,10 +253,10 @@ export class UserService {
|
||||||
|
|
||||||
// Audit log - UPLOAD_AVATAR
|
// Audit log - UPLOAD_AVATAR
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded.id,
|
userId,
|
||||||
action: AuditAction.UPLOAD_FILE,
|
action: AuditAction.UPLOAD_FILE,
|
||||||
entityType: 'User',
|
entityType: 'User',
|
||||||
entityId: decoded.id,
|
entityId: userId,
|
||||||
metadata: {
|
metadata: {
|
||||||
operation: 'upload_avatar',
|
operation: 'upload_avatar',
|
||||||
filePath
|
filePath
|
||||||
|
|
@ -293,26 +270,17 @@ export class UserService {
|
||||||
code: 200,
|
code: 200,
|
||||||
message: 'Avatar uploaded successfully',
|
message: 'Avatar uploaded successfully',
|
||||||
data: {
|
data: {
|
||||||
id: decoded.id,
|
id: userId,
|
||||||
avatar_url: presignedUrl
|
avatar_url: presignedUrl
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} 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 });
|
logger.error('Failed to upload avatar', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.UPLOAD_FILE,
|
action: AuditAction.UPLOAD_FILE,
|
||||||
entityType: 'UserProfile',
|
entityType: 'UserProfile',
|
||||||
entityId: decoded?.id || 0,
|
entityId: userId,
|
||||||
metadata: {
|
metadata: {
|
||||||
operation: 'upload_avatar',
|
operation: 'upload_avatar',
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
|
@ -365,12 +333,10 @@ export class UserService {
|
||||||
/**
|
/**
|
||||||
* Send verification email to user
|
* Send verification email to user
|
||||||
*/
|
*/
|
||||||
async sendVerifyEmail(token: string): Promise<SendVerifyEmailResponse> {
|
async sendVerifyEmail(userId: number): Promise<SendVerifyEmailResponse> {
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(token, config.jwt.secret) as { id: number; email: string; roleCode: string };
|
|
||||||
|
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { id: decoded.id },
|
where: { id: userId },
|
||||||
include: { role: true }
|
include: { role: true }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -428,15 +394,12 @@ export class UserService {
|
||||||
message: 'Verification email sent successfully'
|
message: 'Verification email sent successfully'
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} 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 });
|
logger.error('Failed to send verification email', { error });
|
||||||
const decoded = jwt.decode(token) as { id: number } | null;
|
|
||||||
await auditService.logSync({
|
await auditService.logSync({
|
||||||
userId: decoded?.id || 0,
|
userId,
|
||||||
action: AuditAction.ERROR,
|
action: AuditAction.ERROR,
|
||||||
entityType: 'UserProfile',
|
entityType: 'UserProfile',
|
||||||
entityId: decoded?.id || 0,
|
entityId: userId,
|
||||||
metadata: {
|
metadata: {
|
||||||
operation: 'send_verification_email',
|
operation: 'send_verification_email',
|
||||||
error: error instanceof Error ? error.message : String(error)
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
|
|
||||||
|
|
@ -117,10 +117,6 @@ export interface GetCourseDetailForAdminResponse {
|
||||||
data: CourseDetailForAdmin;
|
data: CourseDetailForAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApproveCourseBody {
|
|
||||||
comment?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ApproveCourseResponse {
|
export interface ApproveCourseResponse {
|
||||||
code: number;
|
code: number;
|
||||||
message: string;
|
message: string;
|
||||||
|
|
|
||||||
|
|
@ -98,18 +98,18 @@ export interface ChapterData {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface ChaptersRequest {
|
export interface ChaptersRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetChapterRequest {
|
export interface GetChapterRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateChapterInput {
|
export interface CreateChapterInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
title: MultiLanguageText;
|
title: MultiLanguageText;
|
||||||
description?: MultiLanguageText;
|
description?: MultiLanguageText;
|
||||||
|
|
@ -118,13 +118,13 @@ export interface CreateChapterInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateChapterRequest {
|
export interface CreateChapterRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
data: CreateChapterInput;
|
data: CreateChapterInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateChapterInput {
|
export interface UpdateChapterInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
title?: MultiLanguageText;
|
title?: MultiLanguageText;
|
||||||
|
|
@ -134,20 +134,20 @@ export interface UpdateChapterInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateChapterRequest {
|
export interface UpdateChapterRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
data: UpdateChapterInput;
|
data: UpdateChapterInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeleteChapterRequest {
|
export interface DeleteChapterRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReorderChapterRequest {
|
export interface ReorderChapterRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
sort_order: number;
|
sort_order: number;
|
||||||
|
|
@ -199,7 +199,7 @@ export interface ReorderChapterResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface GetLessonRequest {
|
export interface GetLessonRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
|
|
@ -216,7 +216,7 @@ export interface UploadedFileInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateLessonInput {
|
export interface CreateLessonInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
title: MultiLanguageText;
|
title: MultiLanguageText;
|
||||||
|
|
@ -293,7 +293,7 @@ export interface QuizChoiceData {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateLessonRequest {
|
export interface CreateLessonRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
data: CreateLessonInput;
|
data: CreateLessonInput;
|
||||||
|
|
@ -311,7 +311,7 @@ export interface UpdateLessonInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateLessonRequest {
|
export interface UpdateLessonRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
|
|
@ -319,14 +319,14 @@ export interface UpdateLessonRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeleteLessonRequest {
|
export interface DeleteLessonRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReorderLessonsRequest {
|
export interface ReorderLessonsRequest {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
chapter_id: number;
|
chapter_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
|
|
@ -365,7 +365,7 @@ export interface UpdateLessonResponse {
|
||||||
* Input for uploading video to a lesson
|
* Input for uploading video to a lesson
|
||||||
*/
|
*/
|
||||||
export interface UploadVideoInput {
|
export interface UploadVideoInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
video: UploadedFileInfo;
|
video: UploadedFileInfo;
|
||||||
|
|
@ -375,7 +375,7 @@ export interface UploadVideoInput {
|
||||||
* Input for updating (replacing) video in a lesson
|
* Input for updating (replacing) video in a lesson
|
||||||
*/
|
*/
|
||||||
export interface UpdateVideoInput {
|
export interface UpdateVideoInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
video: UploadedFileInfo;
|
video: UploadedFileInfo;
|
||||||
|
|
@ -385,7 +385,7 @@ export interface UpdateVideoInput {
|
||||||
* Input for setting YouTube video to a lesson
|
* Input for setting YouTube video to a lesson
|
||||||
*/
|
*/
|
||||||
export interface SetYouTubeVideoInput {
|
export interface SetYouTubeVideoInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
youtube_video_id: string;
|
youtube_video_id: string;
|
||||||
|
|
@ -411,7 +411,7 @@ export interface YouTubeVideoResponse {
|
||||||
* Input for uploading a single attachment to a lesson
|
* Input for uploading a single attachment to a lesson
|
||||||
*/
|
*/
|
||||||
export interface UploadAttachmentInput {
|
export interface UploadAttachmentInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
attachment: UploadedFileInfo;
|
attachment: UploadedFileInfo;
|
||||||
|
|
@ -421,7 +421,7 @@ export interface UploadAttachmentInput {
|
||||||
* Input for deleting an attachment from a lesson
|
* Input for deleting an attachment from a lesson
|
||||||
*/
|
*/
|
||||||
export interface DeleteAttachmentInput {
|
export interface DeleteAttachmentInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
attachment_id: number;
|
attachment_id: number;
|
||||||
|
|
@ -490,7 +490,7 @@ export interface LessonWithDetailsResponse {
|
||||||
* Input for adding quiz to an existing QUIZ lesson
|
* Input for adding quiz to an existing QUIZ lesson
|
||||||
*/
|
*/
|
||||||
export interface AddQuizToLessonInput {
|
export interface AddQuizToLessonInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
quiz_data: {
|
quiz_data: {
|
||||||
|
|
@ -509,7 +509,7 @@ export interface AddQuizToLessonInput {
|
||||||
* Input for adding a single question to a quiz lesson
|
* Input for adding a single question to a quiz lesson
|
||||||
*/
|
*/
|
||||||
export interface AddQuestionInput {
|
export interface AddQuestionInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
question: MultiLanguageText;
|
question: MultiLanguageText;
|
||||||
|
|
@ -532,7 +532,7 @@ export interface AddQuestionResponse {
|
||||||
* Input for updating a question
|
* Input for updating a question
|
||||||
*/
|
*/
|
||||||
export interface UpdateQuestionInput {
|
export interface UpdateQuestionInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
question_id: number;
|
question_id: number;
|
||||||
|
|
@ -556,14 +556,14 @@ export interface UpdateQuestionResponse {
|
||||||
* Input for deleting a question
|
* Input for deleting a question
|
||||||
*/
|
*/
|
||||||
export interface DeleteQuestionInput {
|
export interface DeleteQuestionInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
question_id: number;
|
question_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReorderQuestionInput {
|
export interface ReorderQuestionInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
question_id: number;
|
question_id: number;
|
||||||
|
|
@ -588,7 +588,7 @@ export interface DeleteQuestionResponse {
|
||||||
* Input for updating quiz settings
|
* Input for updating quiz settings
|
||||||
*/
|
*/
|
||||||
export interface UpdateQuizInput {
|
export interface UpdateQuizInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
title?: MultiLanguageText;
|
title?: MultiLanguageText;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@ export interface createCourseResponse {
|
||||||
data: Course;
|
data: Course;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ListMyCoursesInput {
|
||||||
|
userId: number;
|
||||||
|
status?: 'DRAFT' | 'PENDING' | 'APPROVED' | 'REJECTED' | 'ARCHIVED';
|
||||||
|
}
|
||||||
|
|
||||||
export interface ListMyCourseResponse {
|
export interface ListMyCourseResponse {
|
||||||
code: number;
|
code: number;
|
||||||
message: string;
|
message: string;
|
||||||
|
|
@ -37,7 +42,7 @@ export interface GetMyCourseResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface getmyCourse {
|
export interface getmyCourse {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,13 +94,13 @@ export interface listCourseinstructorResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface addinstructorCourse {
|
export interface addinstructorCourse {
|
||||||
token: string;
|
userId: number;
|
||||||
email_or_username: string;
|
email_or_username: string;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SearchInstructorInput {
|
export interface SearchInstructorInput {
|
||||||
token: string;
|
userId: number;
|
||||||
query: string;
|
query: string;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
@ -140,12 +145,12 @@ export interface listinstructorCourseResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface listinstructorCourse {
|
export interface listinstructorCourse {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface removeinstructorCourse {
|
export interface removeinstructorCourse {
|
||||||
token: string;
|
userId: number;
|
||||||
user_id: number;
|
user_id: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +161,7 @@ export interface removeinstructorCourseResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface setprimaryCourseInstructor {
|
export interface setprimaryCourseInstructor {
|
||||||
token: string;
|
userId: number;
|
||||||
user_id: number;
|
user_id: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
@ -167,12 +172,12 @@ export interface setprimaryCourseInstructorResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface sendCourseForReview {
|
export interface sendCourseForReview {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface setCourseDraft {
|
export interface setCourseDraft {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,7 +220,7 @@ export interface GetCourseApprovalsResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface GetEnrolledStudentsInput {
|
export interface GetEnrolledStudentsInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
|
|
@ -249,7 +254,7 @@ export interface GetEnrolledStudentsResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface GetQuizScoresInput {
|
export interface GetQuizScoresInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
page?: number;
|
page?: number;
|
||||||
|
|
@ -300,7 +305,7 @@ export interface GetQuizScoresResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface GetQuizAttemptDetailInput {
|
export interface GetQuizAttemptDetailInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
student_id: number;
|
student_id: number;
|
||||||
|
|
@ -348,7 +353,7 @@ export interface GetQuizAttemptDetailResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface GetEnrolledStudentDetailInput {
|
export interface GetEnrolledStudentDetailInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
student_id: number;
|
student_id: number;
|
||||||
}
|
}
|
||||||
|
|
@ -428,3 +433,29 @@ export interface GetCourseApprovalHistoryResponse {
|
||||||
approval_history: ApprovalHistoryItem[];
|
approval_history: ApprovalHistoryItem[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CloneCourseInput {
|
||||||
|
userId: number;
|
||||||
|
course_id: number;
|
||||||
|
title: MultiLanguageText;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CloneCourseResponse {
|
||||||
|
code: number;
|
||||||
|
message: string;
|
||||||
|
data: {
|
||||||
|
id: number;
|
||||||
|
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 {
|
export interface EnrollCourseInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ export interface EnrollCourseResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ListEnrolledCoursesInput {
|
export interface ListEnrolledCoursesInput {
|
||||||
token: string;
|
userId: number;
|
||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
status?: EnrollmentStatus;
|
status?: EnrollmentStatus;
|
||||||
|
|
@ -64,7 +64,7 @@ export interface ListEnrolledCoursesResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface GetCourseLearningInput {
|
export interface GetCourseLearningInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,7 +126,7 @@ export interface GetCourseLearningResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface GetLessonContentInput {
|
export interface GetLessonContentInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
}
|
}
|
||||||
|
|
@ -204,7 +204,7 @@ export interface GetLessonContentResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface CheckLessonAccessInput {
|
export interface CheckLessonAccessInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
}
|
}
|
||||||
|
|
@ -236,7 +236,7 @@ export interface CheckLessonAccessResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface SaveVideoProgressInput {
|
export interface SaveVideoProgressInput {
|
||||||
token: string;
|
userId: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
video_progress_seconds: number;
|
video_progress_seconds: number;
|
||||||
video_duration_seconds?: number;
|
video_duration_seconds?: number;
|
||||||
|
|
@ -258,7 +258,7 @@ export interface SaveVideoProgressResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetVideoProgressInput {
|
export interface GetVideoProgressInput {
|
||||||
token: string;
|
userId: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,7 +281,7 @@ export interface GetVideoProgressResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface MarkLessonCompleteInput {
|
export interface MarkLessonCompleteInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
}
|
}
|
||||||
|
|
@ -314,7 +314,7 @@ export interface EnrollCourseBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CompleteLessonInput {
|
export interface CompleteLessonInput {
|
||||||
token: string;
|
userId: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,7 +342,7 @@ export interface QuizAnswerInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SubmitQuizInput {
|
export interface SubmitQuizInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
answers: QuizAnswerInput[];
|
answers: QuizAnswerInput[];
|
||||||
|
|
@ -384,7 +384,7 @@ export interface SubmitQuizResponse {
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface GetQuizAttemptsInput {
|
export interface GetQuizAttemptsInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
lesson_id: number;
|
lesson_id: number;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
import { MultiLanguageText } from './index';
|
import { MultiLanguageText } from './index';
|
||||||
|
|
||||||
// ============================================
|
|
||||||
// Request Types
|
|
||||||
// ============================================
|
|
||||||
|
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// Response Types
|
// Response Types
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
|
/** ใช้ใน listApprovedCourses — มีแค่ chapters_count */
|
||||||
export interface RecommendedCourseData {
|
export interface RecommendedCourseData {
|
||||||
id: number;
|
id: number;
|
||||||
title: MultiLanguageText;
|
title: MultiLanguageText;
|
||||||
|
|
@ -41,7 +37,19 @@ export interface RecommendedCourseData {
|
||||||
};
|
};
|
||||||
}>;
|
}>;
|
||||||
chapters_count: number;
|
chapters_count: number;
|
||||||
lessons_count: number;
|
}
|
||||||
|
|
||||||
|
/** ใช้ใน getCourseById — มี chapters + lessons พร้อมชื่อ */
|
||||||
|
export interface RecommendedCourseDetailData extends Omit<RecommendedCourseData, 'chapters_count'> {
|
||||||
|
chapters: {
|
||||||
|
id: number;
|
||||||
|
title: MultiLanguageText;
|
||||||
|
sort_order: number;
|
||||||
|
lessons: {
|
||||||
|
id: number;
|
||||||
|
title: MultiLanguageText;
|
||||||
|
}[];
|
||||||
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ListApprovedCoursesResponse {
|
export interface ListApprovedCoursesResponse {
|
||||||
|
|
@ -54,7 +62,7 @@ export interface ListApprovedCoursesResponse {
|
||||||
export interface GetCourseByIdResponse {
|
export interface GetCourseByIdResponse {
|
||||||
code: number;
|
code: number;
|
||||||
message: string;
|
message: string;
|
||||||
data: RecommendedCourseData;
|
data: RecommendedCourseDetailData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ToggleRecommendedResponse {
|
export interface ToggleRecommendedResponse {
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,14 @@ export interface ListAnnouncementResponse{
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ListAnnouncementInput {
|
export interface ListAnnouncementInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateAnnouncementInput {
|
export interface CreateAnnouncementInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
title: MultiLanguageText;
|
title: MultiLanguageText;
|
||||||
content: MultiLanguageText;
|
content: MultiLanguageText;
|
||||||
|
|
@ -50,7 +50,7 @@ export interface CreateAnnouncementInput{
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UploadAnnouncementAttachmentInput {
|
export interface UploadAnnouncementAttachmentInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
announcement_id: number;
|
announcement_id: number;
|
||||||
file: File;
|
file: File;
|
||||||
|
|
@ -63,7 +63,7 @@ export interface UploadAnnouncementAttachmentResponse{
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeleteAnnouncementAttachmentInput {
|
export interface DeleteAnnouncementAttachmentInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
announcement_id: number;
|
announcement_id: number;
|
||||||
attachment_id: number;
|
attachment_id: number;
|
||||||
|
|
@ -81,7 +81,7 @@ export interface CreateAnnouncementResponse{
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateAnnouncementInput {
|
export interface UpdateAnnouncementInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
announcement_id: number;
|
announcement_id: number;
|
||||||
title: MultiLanguageText;
|
title: MultiLanguageText;
|
||||||
|
|
@ -99,7 +99,7 @@ export interface UpdateAnnouncementResponse{
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeleteAnnouncementInput {
|
export interface DeleteAnnouncementInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
announcement_id: number;
|
announcement_id: number;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ export interface LoginResponse {
|
||||||
data: {
|
data: {
|
||||||
token: string;
|
token: string;
|
||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
user: UserResponse;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
export interface GenerateCertificateInput {
|
export interface GenerateCertificateInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ export interface GenerateCertificateResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetCertificateInput {
|
export interface GetCertificateInput {
|
||||||
token: string;
|
userId: number;
|
||||||
course_id: number;
|
course_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ export interface GetCertificateResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ListMyCertificatesInput {
|
export interface ListMyCertificatesInput {
|
||||||
token: string;
|
userId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ListMyCertificatesResponse {
|
export interface ListMyCertificatesResponse {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { Course } from '@prisma/client';
|
import { Course } from '@prisma/client';
|
||||||
|
import { MultiLanguageText } from './index';
|
||||||
|
|
||||||
export interface ListCoursesInput {
|
export interface ListCoursesInput {
|
||||||
category_id?: number;
|
category_id?: number;
|
||||||
|
|
@ -18,8 +19,47 @@ export interface listCourseResponse {
|
||||||
totalPages: number;
|
totalPages: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CourseDetail extends Omit<Course, 'title' | 'description'> {
|
||||||
|
title: MultiLanguageText;
|
||||||
|
description: MultiLanguageText;
|
||||||
|
creator: {
|
||||||
|
id: number;
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
|
profile: {
|
||||||
|
first_name: string;
|
||||||
|
last_name: string;
|
||||||
|
avatar_url: string | null;
|
||||||
|
} | null;
|
||||||
|
};
|
||||||
|
instructors: {
|
||||||
|
user_id: number;
|
||||||
|
is_primary: boolean;
|
||||||
|
user: {
|
||||||
|
id: number;
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
|
profile: {
|
||||||
|
first_name: string;
|
||||||
|
last_name: string;
|
||||||
|
avatar_url: string | null;
|
||||||
|
} | null;
|
||||||
|
};
|
||||||
|
}[];
|
||||||
|
category: { id: number; name: MultiLanguageText } | null;
|
||||||
|
chapters: {
|
||||||
|
id: number;
|
||||||
|
title: MultiLanguageText;
|
||||||
|
sort_order: number;
|
||||||
|
lessons: {
|
||||||
|
id: number;
|
||||||
|
title: MultiLanguageText;
|
||||||
|
}[];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface getCourseResponse {
|
export interface getCourseResponse {
|
||||||
code: number;
|
code: number;
|
||||||
message: string;
|
message: string;
|
||||||
data: Course | null;
|
data: CourseDetail | null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,14 @@ export interface ProfileUpdateResponse {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface role {
|
||||||
|
id: number;
|
||||||
|
code: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface rolesResponse {
|
||||||
|
roles: role[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface ChangePasswordRequest {
|
export interface ChangePasswordRequest {
|
||||||
old_password: string;
|
old_password: string;
|
||||||
|
|
|
||||||
30
Backend/src/validators/AdminCourseApproval.validator.ts
Normal file
30
Backend/src/validators/AdminCourseApproval.validator.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import Joi from 'joi';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for approving a course
|
||||||
|
* Comment is optional
|
||||||
|
*/
|
||||||
|
export const ApproveCourseValidator = Joi.object({
|
||||||
|
comment: Joi.string()
|
||||||
|
.max(1000)
|
||||||
|
.optional()
|
||||||
|
.messages({
|
||||||
|
'string.max': 'Comment must not exceed 1000 characters'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for rejecting a course
|
||||||
|
* Comment is required when rejecting
|
||||||
|
*/
|
||||||
|
export const RejectCourseValidator = Joi.object({
|
||||||
|
comment: Joi.string()
|
||||||
|
.min(10)
|
||||||
|
.max(1000)
|
||||||
|
.required()
|
||||||
|
.messages({
|
||||||
|
'string.min': 'Comment must be at least 10 characters when rejecting a course',
|
||||||
|
'string.max': 'Comment must not exceed 1000 characters',
|
||||||
|
'any.required': 'Comment is required when rejecting a course'
|
||||||
|
})
|
||||||
|
});
|
||||||
186
Backend/src/validators/ChaptersLesson.validator.ts
Normal file
186
Backend/src/validators/ChaptersLesson.validator.ts
Normal file
|
|
@ -0,0 +1,186 @@
|
||||||
|
import Joi from 'joi';
|
||||||
|
|
||||||
|
// Multi-language validation schema
|
||||||
|
const multiLangSchema = Joi.object({
|
||||||
|
th: Joi.string().required().messages({
|
||||||
|
'any.required': 'Thai text is required'
|
||||||
|
}),
|
||||||
|
en: Joi.string().required().messages({
|
||||||
|
'any.required': 'English text is required'
|
||||||
|
})
|
||||||
|
}).required();
|
||||||
|
|
||||||
|
const multiLangOptionalSchema = Joi.object({
|
||||||
|
th: Joi.string().optional(),
|
||||||
|
en: Joi.string().optional()
|
||||||
|
}).optional();
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Chapter Validators
|
||||||
|
// ============================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for creating a chapter
|
||||||
|
*/
|
||||||
|
export const CreateChapterValidator = Joi.object({
|
||||||
|
title: multiLangSchema.messages({
|
||||||
|
'any.required': 'Title is required'
|
||||||
|
}),
|
||||||
|
description: multiLangOptionalSchema,
|
||||||
|
sort_order: Joi.number().integer().min(0).optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for updating a chapter
|
||||||
|
*/
|
||||||
|
export const UpdateChapterValidator = Joi.object({
|
||||||
|
title: multiLangOptionalSchema,
|
||||||
|
description: multiLangOptionalSchema,
|
||||||
|
sort_order: Joi.number().integer().min(0).optional(),
|
||||||
|
is_published: Joi.boolean().optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for reordering a chapter
|
||||||
|
*/
|
||||||
|
export const ReorderChapterValidator = Joi.object({
|
||||||
|
sort_order: Joi.number().integer().min(0).required().messages({
|
||||||
|
'any.required': 'Sort order is required',
|
||||||
|
'number.min': 'Sort order must be at least 0'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Lesson Validators
|
||||||
|
// ============================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for creating a lesson
|
||||||
|
*/
|
||||||
|
export const CreateLessonValidator = Joi.object({
|
||||||
|
title: multiLangSchema.messages({
|
||||||
|
'any.required': 'Title is required'
|
||||||
|
}),
|
||||||
|
content: multiLangOptionalSchema,
|
||||||
|
type: Joi.string().valid('VIDEO', 'QUIZ').required().messages({
|
||||||
|
'any.only': 'Type must be either VIDEO or QUIZ',
|
||||||
|
'any.required': 'Type is required'
|
||||||
|
}),
|
||||||
|
sort_order: Joi.number().integer().min(0).optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for updating a lesson
|
||||||
|
*/
|
||||||
|
export const UpdateLessonValidator = Joi.object({
|
||||||
|
title: multiLangOptionalSchema,
|
||||||
|
content: multiLangOptionalSchema,
|
||||||
|
duration_minutes: Joi.number().min(0).optional().messages({
|
||||||
|
'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()).allow(null).optional(),
|
||||||
|
is_published: Joi.boolean().optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for reordering lessons
|
||||||
|
*/
|
||||||
|
export const ReorderLessonsValidator = Joi.object({
|
||||||
|
lesson_id: Joi.number().integer().positive().required().messages({
|
||||||
|
'any.required': 'Lesson ID is required'
|
||||||
|
}),
|
||||||
|
sort_order: Joi.number().integer().min(0).required().messages({
|
||||||
|
'any.required': 'Sort order is required'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Quiz Question Validators
|
||||||
|
// ============================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for quiz choice
|
||||||
|
*/
|
||||||
|
const QuizChoiceValidator = Joi.object({
|
||||||
|
text: multiLangSchema.messages({
|
||||||
|
'any.required': 'Choice text is required'
|
||||||
|
}),
|
||||||
|
is_correct: Joi.boolean().required().messages({
|
||||||
|
'any.required': 'is_correct is required'
|
||||||
|
}),
|
||||||
|
sort_order: Joi.number().integer().min(0).optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for adding a question to a quiz
|
||||||
|
*/
|
||||||
|
export const AddQuestionValidator = Joi.object({
|
||||||
|
question: multiLangSchema.messages({
|
||||||
|
'any.required': 'Question is required'
|
||||||
|
}),
|
||||||
|
explanation: multiLangOptionalSchema,
|
||||||
|
question_type: Joi.string()
|
||||||
|
.valid('MULTIPLE_CHOICE', 'TRUE_FALSE', 'SHORT_ANSWER')
|
||||||
|
.required()
|
||||||
|
.messages({
|
||||||
|
'any.only': 'Question type must be MULTIPLE_CHOICE, TRUE_FALSE, or SHORT_ANSWER',
|
||||||
|
'any.required': 'Question type is required'
|
||||||
|
}),
|
||||||
|
sort_order: Joi.number().integer().min(0).optional(),
|
||||||
|
choices: Joi.array().items(QuizChoiceValidator).min(1).optional().messages({
|
||||||
|
'array.min': 'At least one choice is required for multiple choice questions'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for updating a question
|
||||||
|
*/
|
||||||
|
export const UpdateQuestionValidator = Joi.object({
|
||||||
|
question: multiLangOptionalSchema,
|
||||||
|
explanation: multiLangOptionalSchema,
|
||||||
|
question_type: Joi.string()
|
||||||
|
.valid('MULTIPLE_CHOICE', 'TRUE_FALSE', 'SHORT_ANSWER')
|
||||||
|
.optional()
|
||||||
|
.messages({
|
||||||
|
'any.only': 'Question type must be MULTIPLE_CHOICE, TRUE_FALSE, or SHORT_ANSWER'
|
||||||
|
}),
|
||||||
|
sort_order: Joi.number().integer().min(0).optional(),
|
||||||
|
choices: Joi.array().items(QuizChoiceValidator).min(1).optional().messages({
|
||||||
|
'array.min': 'At least one choice is required'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for reordering a question
|
||||||
|
*/
|
||||||
|
export const ReorderQuestionValidator = Joi.object({
|
||||||
|
sort_order: Joi.number().integer().min(0).required().messages({
|
||||||
|
'any.required': 'Sort order is required',
|
||||||
|
'number.min': 'Sort order must be at least 0'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Quiz Settings Validator
|
||||||
|
// ============================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for updating quiz settings
|
||||||
|
*/
|
||||||
|
export const UpdateQuizValidator = Joi.object({
|
||||||
|
title: multiLangOptionalSchema,
|
||||||
|
description: multiLangOptionalSchema,
|
||||||
|
passing_score: Joi.number().min(0).max(100).optional().messages({
|
||||||
|
'number.min': 'Passing score must be at least 0',
|
||||||
|
'number.max': 'Passing score must not exceed 100'
|
||||||
|
}),
|
||||||
|
time_limit: Joi.number().min(0).optional().messages({
|
||||||
|
'number.min': 'Time limit must be at least 0'
|
||||||
|
}),
|
||||||
|
shuffle_questions: Joi.boolean().optional(),
|
||||||
|
shuffle_choices: Joi.boolean().optional(),
|
||||||
|
show_answers_after_completion: Joi.boolean().optional(),
|
||||||
|
is_skippable: Joi.boolean().optional(),
|
||||||
|
allow_multiple_attempts: Joi.boolean().optional()
|
||||||
|
});
|
||||||
|
|
@ -20,3 +20,38 @@ export const CreateCourseValidator = Joi.object({
|
||||||
is_free: Joi.boolean().required(),
|
is_free: Joi.boolean().required(),
|
||||||
have_certificate: Joi.boolean().required(),
|
have_certificate: Joi.boolean().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for updating a course
|
||||||
|
*/
|
||||||
|
export const UpdateCourseValidator = Joi.object({
|
||||||
|
category_id: Joi.number().optional(),
|
||||||
|
title: Joi.object({
|
||||||
|
th: Joi.string().optional(),
|
||||||
|
en: Joi.string().optional(),
|
||||||
|
}).optional(),
|
||||||
|
slug: Joi.string().optional(),
|
||||||
|
description: Joi.object({
|
||||||
|
th: Joi.string().optional(),
|
||||||
|
en: Joi.string().optional(),
|
||||||
|
}).optional(),
|
||||||
|
price: Joi.number().optional(),
|
||||||
|
is_free: Joi.boolean().optional(),
|
||||||
|
have_certificate: Joi.boolean().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for cloning a course
|
||||||
|
*/
|
||||||
|
export const CloneCourseValidator = Joi.object({
|
||||||
|
title: Joi.object({
|
||||||
|
th: Joi.string().required().messages({
|
||||||
|
'any.required': 'Thai title is required'
|
||||||
|
}),
|
||||||
|
en: Joi.string().required().messages({
|
||||||
|
'any.required': 'English title is required'
|
||||||
|
})
|
||||||
|
}).required().messages({
|
||||||
|
'any.required': 'Title is required'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
|
||||||
38
Backend/src/validators/CoursesStudent.validator.ts
Normal file
38
Backend/src/validators/CoursesStudent.validator.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
import Joi from 'joi';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for saving video progress
|
||||||
|
*/
|
||||||
|
export const SaveVideoProgressValidator = Joi.object({
|
||||||
|
video_progress_seconds: Joi.number().min(0).required().messages({
|
||||||
|
'any.required': 'Video progress seconds is required',
|
||||||
|
'number.min': 'Video progress must be at least 0'
|
||||||
|
}),
|
||||||
|
video_duration_seconds: Joi.number().min(0).optional().messages({
|
||||||
|
'number.min': 'Video duration must be at least 0'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for quiz answer
|
||||||
|
*/
|
||||||
|
const QuizAnswerValidator = Joi.object({
|
||||||
|
question_id: Joi.number().integer().positive().required().messages({
|
||||||
|
'any.required': 'Question ID is required',
|
||||||
|
'number.positive': 'Question ID must be positive'
|
||||||
|
}),
|
||||||
|
choice_id: Joi.number().integer().positive().required().messages({
|
||||||
|
'any.required': 'Choice ID is required',
|
||||||
|
'number.positive': 'Choice ID must be positive'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for submitting quiz answers
|
||||||
|
*/
|
||||||
|
export const SubmitQuizValidator = Joi.object({
|
||||||
|
answers: Joi.array().items(QuizAnswerValidator).min(1).required().messages({
|
||||||
|
'any.required': 'Answers are required',
|
||||||
|
'array.min': 'At least one answer is required'
|
||||||
|
})
|
||||||
|
});
|
||||||
15
Backend/src/validators/Lessons.validator.ts
Normal file
15
Backend/src/validators/Lessons.validator.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import Joi from 'joi';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for setting YouTube video
|
||||||
|
*/
|
||||||
|
export const SetYouTubeVideoValidator = Joi.object({
|
||||||
|
youtube_video_id: Joi.string().required().messages({
|
||||||
|
'any.required': 'YouTube video ID is required',
|
||||||
|
'string.empty': 'YouTube video ID cannot be empty'
|
||||||
|
}),
|
||||||
|
video_title: Joi.string().required().messages({
|
||||||
|
'any.required': 'Video title is required',
|
||||||
|
'string.empty': 'Video title cannot be empty'
|
||||||
|
})
|
||||||
|
});
|
||||||
72
Backend/src/validators/announcements.validator.ts
Normal file
72
Backend/src/validators/announcements.validator.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
import Joi from 'joi';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for creating an announcement
|
||||||
|
*/
|
||||||
|
export const CreateAnnouncementValidator = Joi.object({
|
||||||
|
title: Joi.object({
|
||||||
|
th: Joi.string().required().messages({
|
||||||
|
'any.required': 'Thai title is required'
|
||||||
|
}),
|
||||||
|
en: Joi.string().required().messages({
|
||||||
|
'any.required': 'English title is required'
|
||||||
|
})
|
||||||
|
}).required().messages({
|
||||||
|
'any.required': 'Title is required'
|
||||||
|
}),
|
||||||
|
content: Joi.object({
|
||||||
|
th: Joi.string().required().messages({
|
||||||
|
'any.required': 'Thai content is required'
|
||||||
|
}),
|
||||||
|
en: Joi.string().required().messages({
|
||||||
|
'any.required': 'English content is required'
|
||||||
|
})
|
||||||
|
}).required().messages({
|
||||||
|
'any.required': 'Content is required'
|
||||||
|
}),
|
||||||
|
status: Joi.string()
|
||||||
|
.valid('DRAFT', 'PUBLISHED', 'ARCHIVED')
|
||||||
|
.required()
|
||||||
|
.messages({
|
||||||
|
'any.only': 'Status must be one of: DRAFT, PUBLISHED, ARCHIVED',
|
||||||
|
'any.required': 'Status is required'
|
||||||
|
}),
|
||||||
|
is_pinned: Joi.boolean()
|
||||||
|
.required()
|
||||||
|
.messages({
|
||||||
|
'any.required': 'is_pinned is required'
|
||||||
|
}),
|
||||||
|
published_at: Joi.string()
|
||||||
|
.isoDate()
|
||||||
|
.optional()
|
||||||
|
.messages({
|
||||||
|
'string.isoDate': 'published_at must be a valid ISO date string'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for updating an announcement
|
||||||
|
*/
|
||||||
|
export const UpdateAnnouncementValidator = Joi.object({
|
||||||
|
title: Joi.object({
|
||||||
|
th: Joi.string().optional(),
|
||||||
|
en: Joi.string().optional()
|
||||||
|
}).optional(),
|
||||||
|
content: Joi.object({
|
||||||
|
th: Joi.string().optional(),
|
||||||
|
en: Joi.string().optional()
|
||||||
|
}).optional(),
|
||||||
|
status: Joi.string()
|
||||||
|
.valid('DRAFT', 'PUBLISHED', 'ARCHIVED')
|
||||||
|
.optional()
|
||||||
|
.messages({
|
||||||
|
'any.only': 'Status must be one of: DRAFT, PUBLISHED, ARCHIVED'
|
||||||
|
}),
|
||||||
|
is_pinned: Joi.boolean().optional(),
|
||||||
|
published_at: Joi.string()
|
||||||
|
.isoDate()
|
||||||
|
.optional()
|
||||||
|
.messages({
|
||||||
|
'string.isoDate': 'published_at must be a valid ISO date string'
|
||||||
|
})
|
||||||
|
});
|
||||||
58
Backend/src/validators/categories.validator.ts
Normal file
58
Backend/src/validators/categories.validator.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
import Joi from 'joi';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for creating a category
|
||||||
|
*/
|
||||||
|
export const CreateCategoryValidator = Joi.object({
|
||||||
|
name: Joi.object({
|
||||||
|
th: Joi.string().required().messages({
|
||||||
|
'any.required': 'Thai name is required'
|
||||||
|
}),
|
||||||
|
en: Joi.string().required().messages({
|
||||||
|
'any.required': 'English name is required'
|
||||||
|
})
|
||||||
|
}).required().messages({
|
||||||
|
'any.required': 'Name is required'
|
||||||
|
}),
|
||||||
|
slug: Joi.string()
|
||||||
|
.pattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
|
||||||
|
.required()
|
||||||
|
.messages({
|
||||||
|
'string.pattern.base': 'Slug must be lowercase with hyphens (e.g., web-development)',
|
||||||
|
'any.required': 'Slug is required'
|
||||||
|
}),
|
||||||
|
description: Joi.object({
|
||||||
|
th: Joi.string().required().messages({
|
||||||
|
'any.required': 'Thai description is required'
|
||||||
|
}),
|
||||||
|
en: Joi.string().required().messages({
|
||||||
|
'any.required': 'English description is required'
|
||||||
|
})
|
||||||
|
}).required().messages({
|
||||||
|
'any.required': 'Description is required'
|
||||||
|
}),
|
||||||
|
created_by: Joi.number().optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validator for updating a category
|
||||||
|
*/
|
||||||
|
export const UpdateCategoryValidator = Joi.object({
|
||||||
|
id: Joi.number().required().messages({
|
||||||
|
'any.required': 'Category ID is required'
|
||||||
|
}),
|
||||||
|
name: Joi.object({
|
||||||
|
th: Joi.string().optional(),
|
||||||
|
en: Joi.string().optional()
|
||||||
|
}).optional(),
|
||||||
|
slug: Joi.string()
|
||||||
|
.pattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
|
||||||
|
.optional()
|
||||||
|
.messages({
|
||||||
|
'string.pattern.base': 'Slug must be lowercase with hyphens (e.g., web-development)'
|
||||||
|
}),
|
||||||
|
description: Joi.object({
|
||||||
|
th: Joi.string().optional(),
|
||||||
|
en: Joi.string().optional()
|
||||||
|
}).optional()
|
||||||
|
});
|
||||||
160
Backend/tests/k6/enroll-load-test.js
Normal file
160
Backend/tests/k6/enroll-load-test.js
Normal file
|
|
@ -0,0 +1,160 @@
|
||||||
|
// Backend/tests/k6/enroll-load-test.js
|
||||||
|
//
|
||||||
|
// จำลองนักเรียนหลายคน login แล้ว enroll คอร์สพร้อมกัน
|
||||||
|
//
|
||||||
|
// Flow:
|
||||||
|
// 1. Login
|
||||||
|
// 2. Enroll คอร์ส
|
||||||
|
// 3. ตรวจสอบ enrolled courses
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// k6 run -e APP_URL=http://192.168.1.137:4000 -e COURSE_ID=1 tests/k6/enroll-load-test.js
|
||||||
|
|
||||||
|
import http from 'k6/http';
|
||||||
|
import { check, sleep, group } from 'k6';
|
||||||
|
import { Rate, Trend, Counter } from 'k6/metrics';
|
||||||
|
import { SharedArray } from 'k6/data';
|
||||||
|
|
||||||
|
// ─── Custom Metrics ───────────────────────────────────────────────────────────
|
||||||
|
const errorRate = new Rate('errors');
|
||||||
|
const loginTime = new Trend('login_duration', true);
|
||||||
|
const enrollTime = new Trend('enroll_duration', true);
|
||||||
|
const enrolledCount = new Counter('successful_enrollments');
|
||||||
|
|
||||||
|
// ─── Load student credentials ─────────────────────────────────────────────────
|
||||||
|
const students = new SharedArray('students', function () {
|
||||||
|
return JSON.parse(open('./test-credentials.json')).students;
|
||||||
|
});
|
||||||
|
|
||||||
|
// ─── Config ───────────────────────────────────────────────────────────────────
|
||||||
|
const BASE_URL = __ENV.APP_URL || 'http://192.168.1.137:4000';
|
||||||
|
const COURSE_ID = __ENV.COURSE_ID || '1';
|
||||||
|
|
||||||
|
// ─── Test Options ─────────────────────────────────────────────────────────────
|
||||||
|
export const options = {
|
||||||
|
stages: [
|
||||||
|
{ duration: '20s', target: 10 }, // Ramp up
|
||||||
|
{ duration: '1m', target: 30 }, // Increase
|
||||||
|
{ duration: '30s', target: 50 }, // Peak: 50 คน enroll พร้อมกัน
|
||||||
|
{ duration: '30s', target: 0 }, // Ramp down
|
||||||
|
],
|
||||||
|
thresholds: {
|
||||||
|
'login_duration': ['p(95)<2000'], // Login < 2s
|
||||||
|
'enroll_duration': ['p(95)<1000'], // Enroll < 1s
|
||||||
|
'errors': ['rate<0.05'],
|
||||||
|
'http_req_failed': ['rate<0.05'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// ─── Helper ───────────────────────────────────────────────────────────────────
|
||||||
|
function jsonHeaders(token) {
|
||||||
|
const h = { 'Content-Type': 'application/json' };
|
||||||
|
if (token) h['Authorization'] = `Bearer ${token}`;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Main ─────────────────────────────────────────────────────────────────────
|
||||||
|
export default function () {
|
||||||
|
const student = students[__VU % students.length];
|
||||||
|
let token = null;
|
||||||
|
|
||||||
|
// ── Step 1: Login ──────────────────────────────────────────────────────────
|
||||||
|
group('1. Login', () => {
|
||||||
|
const res = http.post(
|
||||||
|
`${BASE_URL}/api/auth/login`,
|
||||||
|
JSON.stringify({ email: student.email, password: student.password }),
|
||||||
|
{ headers: jsonHeaders(null) }
|
||||||
|
);
|
||||||
|
|
||||||
|
loginTime.add(res.timings.duration);
|
||||||
|
errorRate.add(res.status !== 200);
|
||||||
|
|
||||||
|
check(res, {
|
||||||
|
'login: status 200': (r) => r.status === 200,
|
||||||
|
'login: has token': (r) => { try { return !!r.json('data.token'); } catch { return false; } },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.status === 200) {
|
||||||
|
try { token = res.json('data.token'); } catch {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
console.warn(`[VU ${__VU}] Login failed for ${student.email} — skipping`);
|
||||||
|
sleep(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(0.5);
|
||||||
|
|
||||||
|
// ── Step 2: Enroll ─────────────────────────────────────────────────────────
|
||||||
|
group('2. Enroll Course', () => {
|
||||||
|
const res = http.post(
|
||||||
|
`${BASE_URL}/api/students/courses/${COURSE_ID}/enroll`,
|
||||||
|
null,
|
||||||
|
{ headers: jsonHeaders(token) }
|
||||||
|
);
|
||||||
|
|
||||||
|
enrollTime.add(res.timings.duration);
|
||||||
|
|
||||||
|
// 200 = enrolled, 409 = already enrolled (ถือว่าโอเค)
|
||||||
|
const ok = res.status === 200 || res.status === 409;
|
||||||
|
errorRate.add(!ok);
|
||||||
|
|
||||||
|
if (res.status === 200) enrolledCount.add(1);
|
||||||
|
|
||||||
|
check(res, {
|
||||||
|
'enroll: 200 or 409': (r) => r.status === 200 || r.status === 409,
|
||||||
|
'enroll: fast response': (r) => r.timings.duration < 1000,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
sleep(0.5);
|
||||||
|
|
||||||
|
// ── Step 3: Verify — ดึงรายการคอร์สที่ลงทะเบียน ─────────────────────────
|
||||||
|
group('3. Get Enrolled Courses', () => {
|
||||||
|
const res = http.get(
|
||||||
|
`${BASE_URL}/api/students/courses`,
|
||||||
|
{ headers: jsonHeaders(token) }
|
||||||
|
);
|
||||||
|
|
||||||
|
errorRate.add(res.status !== 200);
|
||||||
|
|
||||||
|
check(res, {
|
||||||
|
'enrolled courses: status 200': (r) => r.status === 200,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Summary ──────────────────────────────────────────────────────────────────
|
||||||
|
export function handleSummary(data) {
|
||||||
|
const m = data.metrics;
|
||||||
|
const avg = (k) => m[k]?.values?.avg?.toFixed(0) ?? 'N/A';
|
||||||
|
const p95 = (k) => m[k]?.values?.['p(95)']?.toFixed(0) ?? 'N/A';
|
||||||
|
const rate = (k) => ((m[k]?.values?.rate ?? 0) * 100).toFixed(2);
|
||||||
|
const cnt = (k) => m[k]?.values?.count ?? 0;
|
||||||
|
|
||||||
|
return {
|
||||||
|
stdout: `
|
||||||
|
╔══════════════════════════════════════════════════════════╗
|
||||||
|
║ Course Enroll — Load Test ║
|
||||||
|
╠══════════════════════════════════════════════════════════╣
|
||||||
|
║ Course ID : ${String(COURSE_ID).padEnd(43)}║
|
||||||
|
╠══════════════════════════════════════════════════════════╣
|
||||||
|
║ RESPONSE TIMES (avg / p95) ║
|
||||||
|
║ Login : ${avg('login_duration')}ms / ${p95('login_duration')}ms
|
||||||
|
║ Enroll : ${avg('enroll_duration')}ms / ${p95('enroll_duration')}ms
|
||||||
|
╠══════════════════════════════════════════════════════════╣
|
||||||
|
║ COUNTS ║
|
||||||
|
║ Total Requests : ${String(cnt('http_reqs')).padEnd(33)}║
|
||||||
|
║ New Enrollments : ${String(cnt('successful_enrollments')).padEnd(33)}║
|
||||||
|
╠══════════════════════════════════════════════════════════╣
|
||||||
|
║ ERROR RATES ║
|
||||||
|
║ HTTP Failed : ${(rate('http_req_failed') + '%').padEnd(39)}║
|
||||||
|
║ Custom Errors : ${(rate('errors') + '%').padEnd(39)}║
|
||||||
|
╚══════════════════════════════════════════════════════════╝
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -31,7 +31,7 @@ export const options = {
|
||||||
thresholds: {
|
thresholds: {
|
||||||
http_req_duration: ['p(95)<2000'], // 95% of requests < 2s
|
http_req_duration: ['p(95)<2000'], // 95% of requests < 2s
|
||||||
errors: ['rate<0.1'], // Error rate < 10%
|
errors: ['rate<0.1'], // Error rate < 10%
|
||||||
login_duration: ['p(95)<2000'], // 95% of logins < 2s
|
login_duration: ['p(95)<2000'], // 95% pof logins < 2s
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
269
Backend/tests/k6/video-watching-load-test.js
Normal file
269
Backend/tests/k6/video-watching-load-test.js
Normal file
|
|
@ -0,0 +1,269 @@
|
||||||
|
// Backend/tests/k6/video-watching-load-test.js
|
||||||
|
//
|
||||||
|
// จำลองนักเรียนหลายคนดูวีดีโอพร้อมกัน (Concurrent Video Watching)
|
||||||
|
//
|
||||||
|
// Flow จริงที่ simulate:
|
||||||
|
// 1. Login ด้วย account ของ student แต่ละคน
|
||||||
|
// 2. Load หน้าเรียนคอร์ส (getCourseLearning)
|
||||||
|
// 3. เปิดบทเรียนวีดีโอ (getLessonContent)
|
||||||
|
// 4. Save progress ทุก 5 วินาที (จำลองการ watch)
|
||||||
|
// 5. เมื่อดูครบ (≥90%) → mark lesson complete
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// k6 run -e APP_URL=http://localhost:4000 -e COURSE_ID=1 -e LESSON_ID=1 tests/k6/video-watching-load-test.js
|
||||||
|
//
|
||||||
|
// ปรับจำนวน VUs และ duration ได้ด้วย:
|
||||||
|
// k6 run -e APP_URL=http://localhost:4000 -e COURSE_ID=1 -e LESSON_ID=1 --vus 30 --duration 2m tests/k6/video-watching-load-test.js
|
||||||
|
|
||||||
|
import http from 'k6/http';
|
||||||
|
import { check, sleep, group } from 'k6';
|
||||||
|
import { Rate, Trend, Counter } from 'k6/metrics';
|
||||||
|
import { SharedArray } from 'k6/data';
|
||||||
|
|
||||||
|
// ─── Custom Metrics ───────────────────────────────────────────────────────────
|
||||||
|
const errorRate = new Rate('errors');
|
||||||
|
const loginTime = new Trend('login_duration', true);
|
||||||
|
const courseLearningTime = new Trend('course_learning_duration', true);
|
||||||
|
const lessonLoadTime = new Trend('lesson_load_duration', true);
|
||||||
|
const progressSaveTime = new Trend('progress_save_duration', true);
|
||||||
|
const completeLessonTime = new Trend('complete_lesson_duration', true);
|
||||||
|
const completedCount = new Counter('completed_lessons');
|
||||||
|
const progressSaveCount = new Counter('progress_saves');
|
||||||
|
const videoLoadTime = new Trend('video_load_duration', true);
|
||||||
|
|
||||||
|
// ─── Load student credentials ────────────────────────────────────────────────
|
||||||
|
// อ่านจาก test-credentials.json (50 accounts)
|
||||||
|
const students = new SharedArray('students', function () {
|
||||||
|
return JSON.parse(open('./test-credentials.json')).students;
|
||||||
|
});
|
||||||
|
|
||||||
|
// ─── Config ───────────────────────────────────────────────────────────────────
|
||||||
|
const BASE_URL = __ENV.APP_URL || 'http://192.168.1.137:4000';
|
||||||
|
const COURSE_ID = __ENV.COURSE_ID || '1';
|
||||||
|
const LESSON_ID = __ENV.LESSON_ID || '1';
|
||||||
|
|
||||||
|
// วีดีโอความยาว (วินาที) — ปรับตามจริง
|
||||||
|
const VIDEO_DURATION_SECONDS = parseInt(__ENV.VIDEO_DURATION || '98'); // default 5 นาที
|
||||||
|
|
||||||
|
// save progress interval: ทุก 5 วินาที (เหมือน client จริง)
|
||||||
|
// แต่ในการ test เราจะ simulate เร็วขึ้นโดยใช้ sleep น้อยลง
|
||||||
|
const PROGRESS_INTERVAL_SECONDS = parseInt(__ENV.PROGRESS_INTERVAL || '15');
|
||||||
|
|
||||||
|
// ─── Test Options ─────────────────────────────────────────────────────────────
|
||||||
|
export const options = {
|
||||||
|
stages: [
|
||||||
|
{ duration: '30s', target: 10 }, // Ramp up: 10 คนเริ่มดูวีดีโอ
|
||||||
|
{ duration: '1m', target: 30 }, // Ramp up: เพิ่มเป็น 30 คน
|
||||||
|
{ duration: '2m', target: 30 }, // Steady: 30 คนดูพร้อมกัน
|
||||||
|
{ duration: '30s', target: 50 }, // Peak: เพิ่มเป็น 50 คน
|
||||||
|
{ duration: '1m', target: 50 }, // Steady Peak: 50 คนพร้อมกัน
|
||||||
|
{ duration: '30s', target: 0 }, // Ramp down
|
||||||
|
],
|
||||||
|
thresholds: {
|
||||||
|
// Response times
|
||||||
|
'login_duration': ['p(95)<2000'], // Login < 2s
|
||||||
|
'course_learning_duration': ['p(95)<1000'], // Load course page < 1s
|
||||||
|
'lesson_load_duration': ['p(95)<1000'], // Load lesson < 1s
|
||||||
|
'video_load_duration': ['p(95)<3000'], // Fetch video from MinIO < 3s
|
||||||
|
'progress_save_duration': ['p(95)<500'], // Save progress < 500ms (critical — บ่อย)
|
||||||
|
'complete_lesson_duration': ['p(95)<1000'], // Complete lesson < 1s
|
||||||
|
|
||||||
|
// Error rate
|
||||||
|
'errors': ['rate<0.05'], // Error < 5%
|
||||||
|
'http_req_failed': ['rate<0.05'], // HTTP error < 5%
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// ─── Helper ───────────────────────────────────────────────────────────────────
|
||||||
|
function jsonHeaders(token) {
|
||||||
|
const h = { 'Content-Type': 'application/json' };
|
||||||
|
if (token) h['Authorization'] = `Bearer ${token}`;
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Per-VU persistent state (จำข้ามรอบ iteration) ──────────────────────────
|
||||||
|
// ตัวแปรนี้อยู่ระดับ module → k6 สร้างแยกต่างหากสำหรับแต่ละ VU
|
||||||
|
// ค่าจะถูกจำไว้ตลอดอายุของ VU (ข้ามหลายรอบ iteration)
|
||||||
|
let vuToken = null; // token ที่ login ไว้แล้ว
|
||||||
|
let vuSetupDone = false; // เคย load course+lesson แล้วหรือยัง
|
||||||
|
let vuProgress = 0; // ตำแหน่งวีดีโอปัจจุบัน (วินาที)
|
||||||
|
let vuCompleted = false; // lesson complete แล้วหรือยัง
|
||||||
|
|
||||||
|
// ─── Main ─────────────────────────────────────────────────────────────────────
|
||||||
|
export default function () {
|
||||||
|
const student = students[__VU % students.length];
|
||||||
|
|
||||||
|
// ── Step 1: Login (ทำครั้งเดียวตอน VU เริ่มต้น หรือถ้า token หาย) ─────────
|
||||||
|
if (!vuToken) {
|
||||||
|
group('1. Login', () => {
|
||||||
|
const res = http.post(
|
||||||
|
`${BASE_URL}/api/auth/login`,
|
||||||
|
JSON.stringify({ email: student.email, password: student.password }),
|
||||||
|
{ headers: jsonHeaders(null) }
|
||||||
|
);
|
||||||
|
|
||||||
|
loginTime.add(res.timings.duration);
|
||||||
|
const ok = res.status === 200;
|
||||||
|
errorRate.add(!ok);
|
||||||
|
|
||||||
|
check(res, {
|
||||||
|
'login: status 200': (r) => r.status === 200,
|
||||||
|
'login: has token': (r) => { try { return !!r.json('data.token'); } catch { return false; } },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
try { vuToken = res.json('data.token'); } catch {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!vuToken) {
|
||||||
|
console.warn(`[VU ${__VU}] Login failed for ${student.email} — skipping`);
|
||||||
|
sleep(2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Step 2 (removed): Enroll ทำผ่าน enroll-load-test.js แยกต่างหาก ─────────
|
||||||
|
|
||||||
|
// ── Step 3+4: Setup — Load course และ open lesson (ทำครั้งเดียวต่อ VU) ─────
|
||||||
|
if (!vuSetupDone) {
|
||||||
|
group('3. Load Course Learning Page', () => {
|
||||||
|
const res = http.get(
|
||||||
|
`${BASE_URL}/api/students/courses/${COURSE_ID}/learn`,
|
||||||
|
{ headers: jsonHeaders(vuToken) }
|
||||||
|
);
|
||||||
|
courseLearningTime.add(res.timings.duration);
|
||||||
|
errorRate.add(res.status !== 200);
|
||||||
|
check(res, { 'course learn: status 200': (r) => r.status === 200 });
|
||||||
|
});
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
let videoUrl = null;
|
||||||
|
group('4. Open Lesson', () => {
|
||||||
|
const res = http.get(
|
||||||
|
`${BASE_URL}/api/students/courses/${COURSE_ID}/lessons/${LESSON_ID}`,
|
||||||
|
{ headers: jsonHeaders(vuToken) }
|
||||||
|
);
|
||||||
|
lessonLoadTime.add(res.timings.duration);
|
||||||
|
errorRate.add(res.status !== 200);
|
||||||
|
check(res, { 'lesson: status 200': (r) => r.status === 200 });
|
||||||
|
if (res.status === 200) {
|
||||||
|
try { videoUrl = res.json('data.video_url'); } catch {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Step 4.5: Fetch video จาก MinIO ──────────────────────────────────────
|
||||||
|
if (videoUrl) {
|
||||||
|
group('4.5 Fetch Video from MinIO', () => {
|
||||||
|
const res = http.get(videoUrl, {
|
||||||
|
headers: { 'Range': 'bytes=0-1048575' }, // ขอแค่ 1MB แรก
|
||||||
|
timeout: '10s',
|
||||||
|
});
|
||||||
|
videoLoadTime.add(res.timings.duration);
|
||||||
|
const ok = res.status === 200 || res.status === 206;
|
||||||
|
errorRate.add(!ok);
|
||||||
|
check(res, {
|
||||||
|
'minio video: 200 or 206': (r) => r.status === 200 || r.status === 206,
|
||||||
|
'minio video: fast': (r) => r.timings.duration < 3000,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log(`[VU ${__VU}] No video_url returned — skipping MinIO fetch`);
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(2); // รอ buffer เริ่มต้น
|
||||||
|
vuSetupDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Step 5: Save Progress ทีละ tick (ต่อจากตำแหน่งเดิม) ────────────────────
|
||||||
|
// แต่ละ iteration ของ VU = ส่ง progress 1 ครั้ง แล้ว sleep ตาม interval จริง
|
||||||
|
if (!vuCompleted) {
|
||||||
|
vuProgress += PROGRESS_INTERVAL_SECONDS;
|
||||||
|
|
||||||
|
group('5. Watch Video (Save Progress)', () => {
|
||||||
|
const res = http.post(
|
||||||
|
`${BASE_URL}/api/students/lessons/${LESSON_ID}/progress`,
|
||||||
|
JSON.stringify({
|
||||||
|
video_progress_seconds: vuProgress,
|
||||||
|
video_duration_seconds: VIDEO_DURATION_SECONDS,
|
||||||
|
}),
|
||||||
|
{ headers: jsonHeaders(vuToken) }
|
||||||
|
);
|
||||||
|
|
||||||
|
progressSaveTime.add(res.timings.duration);
|
||||||
|
progressSaveCount.add(1);
|
||||||
|
|
||||||
|
const ok = res.status === 200;
|
||||||
|
errorRate.add(!ok);
|
||||||
|
check(res, {
|
||||||
|
'progress save: status 200': (r) => r.status === 200,
|
||||||
|
'progress save: fast': (r) => r.timings.duration < 500,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`[VU ${__VU}] progress: ${vuProgress}s / ${VIDEO_DURATION_SECONDS}s (${Math.round(vuProgress / VIDEO_DURATION_SECONDS * 100)}%)`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── Step 6: Mark complete เมื่อดูครบ ≥95% ──────────────────────────────
|
||||||
|
if (vuProgress >= VIDEO_DURATION_SECONDS * 0.95) {
|
||||||
|
group('6. Complete Lesson', () => {
|
||||||
|
const res = http.post(
|
||||||
|
`${BASE_URL}/api/students/courses/${COURSE_ID}/lessons/${LESSON_ID}/complete`,
|
||||||
|
null,
|
||||||
|
{ headers: jsonHeaders(vuToken) }
|
||||||
|
);
|
||||||
|
completeLessonTime.add(res.timings.duration);
|
||||||
|
errorRate.add(res.status !== 200 && res.status !== 409);
|
||||||
|
if (res.status === 200) completedCount.add(1);
|
||||||
|
check(res, {
|
||||||
|
'complete: status 200 or 409': (r) => r.status === 200 || r.status === 409,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
vuCompleted = true;
|
||||||
|
console.log(`[VU ${__VU}] ✓ Lesson completed`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sleep ตาม interval จริง — ทุก VU ส่ง progress ทุก PROGRESS_INTERVAL_SECONDS วินาที
|
||||||
|
sleep(PROGRESS_INTERVAL_SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Summary ──────────────────────────────────────────────────────────────────
|
||||||
|
export function handleSummary(data) {
|
||||||
|
const m = data.metrics;
|
||||||
|
|
||||||
|
const avg = (k) => m[k]?.values?.avg?.toFixed(0) ?? 'N/A';
|
||||||
|
const p95 = (k) => m[k]?.values?.['p(95)']?.toFixed(0) ?? 'N/A';
|
||||||
|
const rate = (k) => ((m[k]?.values?.rate ?? 0) * 100).toFixed(2);
|
||||||
|
const count = (k) => m[k]?.values?.count ?? 0;
|
||||||
|
|
||||||
|
return {
|
||||||
|
stdout: `
|
||||||
|
╔══════════════════════════════════════════════════════════╗
|
||||||
|
║ Concurrent Video Watching — Load Test ║
|
||||||
|
╠══════════════════════════════════════════════════════════╣
|
||||||
|
║ Course ID : ${COURSE_ID.padEnd(44)}║
|
||||||
|
║ Lesson ID : ${LESSON_ID.padEnd(44)}║
|
||||||
|
║ Video : ${String(VIDEO_DURATION_SECONDS + 's').padEnd(44)}║
|
||||||
|
╠══════════════════════════════════════════════════════════╣
|
||||||
|
║ RESPONSE TIMES (avg / p95) ║
|
||||||
|
║ Login : ${avg('login_duration')}ms / ${p95('login_duration')}ms${' '.repeat(Math.max(0, 20 - avg('login_duration').length - p95('login_duration').length))}║
|
||||||
|
║ Course Learning Page: ${avg('course_learning_duration')}ms / ${p95('course_learning_duration')}ms${' '.repeat(Math.max(0, 20 - avg('course_learning_duration').length - p95('course_learning_duration').length))}║
|
||||||
|
║ Lesson Load : ${avg('lesson_load_duration')}ms / ${p95('lesson_load_duration')}ms${' '.repeat(Math.max(0, 20 - avg('lesson_load_duration').length - p95('lesson_load_duration').length))}║
|
||||||
|
║ MinIO Video Fetch : ${avg('video_load_duration')}ms / ${p95('video_load_duration')}ms${' '.repeat(Math.max(0, 20 - avg('video_load_duration').length - p95('video_load_duration').length))}║
|
||||||
|
║ Save Progress : ${avg('progress_save_duration')}ms / ${p95('progress_save_duration')}ms${' '.repeat(Math.max(0, 20 - avg('progress_save_duration').length - p95('progress_save_duration').length))}║
|
||||||
|
║ Complete Lesson : ${avg('complete_lesson_duration')}ms / ${p95('complete_lesson_duration')}ms${' '.repeat(Math.max(0, 20 - avg('complete_lesson_duration').length - p95('complete_lesson_duration').length))}║
|
||||||
|
╠══════════════════════════════════════════════════════════╣
|
||||||
|
║ COUNTS ║
|
||||||
|
║ Total Requests : ${String(count('http_reqs')).padEnd(33)}║
|
||||||
|
║ Progress Saves : ${String(count('progress_saves')).padEnd(33)}║
|
||||||
|
║ Lessons Completed : ${String(count('completed_lessons')).padEnd(33)}║
|
||||||
|
╠══════════════════════════════════════════════════════════╣
|
||||||
|
║ ERROR RATES ║
|
||||||
|
║ HTTP Failed : ${(rate('http_req_failed') + '%').padEnd(33)}║
|
||||||
|
║ Custom Errors : ${(rate('errors') + '%').padEnd(33)}║
|
||||||
|
╚══════════════════════════════════════════════════════════╝
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
}
|
||||||
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"
|
||||||
|
|
@ -1,27 +1,34 @@
|
||||||
<script setup>
|
<script setup lang="ts">
|
||||||
// ดึงฟังก์ชันจัดการ Authentication
|
/**
|
||||||
const { fetchUserProfile, isAuthenticated } = useAuth()
|
* @file app.vue
|
||||||
|
* @description Root application component.
|
||||||
|
* Handles initialization of authentication and theme settings.
|
||||||
|
*/
|
||||||
|
|
||||||
// เมื่อ App เริ่มทำงาน (Mounted)
|
// Initialize composables
|
||||||
|
const { fetchUserProfile, isAuthenticated } = useAuth()
|
||||||
|
const { isDark, set: setTheme } = useThemeMode()
|
||||||
|
|
||||||
|
// App initialization logic
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 1. หากผู้ใช้ Login ค้างไว้ (มี Token) ให้ดึงข้อมูล Profile ล่าสุดทันที
|
// 1. Fetch user profile if tokens exist
|
||||||
if (isAuthenticated.value) {
|
if (isAuthenticated.value) {
|
||||||
fetchUserProfile()
|
fetchUserProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. ตรวจสอบและคืนค่า Theme (Dark/Light) จาก LocalStorage
|
// 2. Initialize theme from persistent storage or system preference
|
||||||
const savedTheme = localStorage.getItem('theme')
|
const savedTheme = localStorage.getItem('theme')
|
||||||
if (savedTheme === 'dark' || (!savedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
if (savedTheme) {
|
||||||
document.documentElement.classList.add('dark')
|
setTheme(savedTheme === 'dark')
|
||||||
} else {
|
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
document.documentElement.classList.remove('dark')
|
setTheme(true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<!-- แสดง Loader ระหว่างเปลี่ยนหน้า หรือโหลดข้อมูล -->
|
<!-- แสดงแถบโหลดด้านบนจอ (Progress Bar) แทนการโหลดเต็มหน้าจอ -->
|
||||||
<GlobalLoader />
|
<NuxtLoadingIndicator color="#2563EB" :height="4" />
|
||||||
|
|
||||||
<!-- NuxtLayout: แสดง Layout ที่กำหนดในแต่ละเพจ (default: layouts/default.vue) -->
|
<!-- NuxtLayout: แสดง Layout ที่กำหนดในแต่ละเพจ (default: layouts/default.vue) -->
|
||||||
<NuxtLayout>
|
<NuxtLayout>
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
/* Typography */
|
/* Typography */
|
||||||
/* Typography */
|
/* Typography */
|
||||||
--font-main:
|
--font-main:
|
||||||
"Prompt", "Sarabun", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
|
"Prompt", "Inter", "Sarabun", -apple-system, BlinkMacSystemFont, "Segoe UI",
|
||||||
"Roboto", "Helvetica Neue", Arial, sans-serif;
|
"Roboto", "Helvetica Neue", Arial, sans-serif;
|
||||||
|
|
||||||
/* Layout */
|
/* Layout */
|
||||||
|
|
@ -113,9 +113,9 @@ body {
|
||||||
background-attachment: fixed;
|
background-attachment: fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
/* a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: #3b82f6;
|
color: #2563eb;
|
||||||
transition: color 0.2s;
|
transition: color 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ a:hover {
|
||||||
|
|
||||||
.dark a:hover {
|
.dark a:hover {
|
||||||
color: #93c5fd;
|
color: #93c5fd;
|
||||||
}
|
} */
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
|
@ -634,6 +634,7 @@ ul {
|
||||||
}
|
}
|
||||||
.font-bold {
|
.font-bold {
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
letter-spacing: normal;
|
||||||
}
|
}
|
||||||
.w-full {
|
.w-full {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
@ -644,9 +645,9 @@ ul {
|
||||||
.rounded {
|
.rounded {
|
||||||
border-radius: var(--radius-md);
|
border-radius: var(--radius-md);
|
||||||
}
|
}
|
||||||
.border-b {
|
/* .border-b {
|
||||||
border-bottom: 1px solid var(--border-color);
|
border-bottom: 1px solid var(--border-color);
|
||||||
}
|
} */
|
||||||
.load-more-wrap {
|
.load-more-wrap {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file AnnouncementModal.vue
|
* @file AnnouncementModal.vue
|
||||||
* @description Modal component to display course announcements
|
* @description คอมโพเนนต์ Modal สำหรับแสดงประกาศของคอร์สเรียน (Modal component to display course announcements)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
|
@ -15,7 +15,7 @@ const emit = defineEmits<{
|
||||||
|
|
||||||
const { locale, t } = useI18n()
|
const { locale, t } = useI18n()
|
||||||
|
|
||||||
// Helper for localization
|
// ตัวช่วยจัดการข้อความหลายภาษา (Helper for localization)
|
||||||
const getLocalizedText = (text: any) => {
|
const getLocalizedText = (text: any) => {
|
||||||
if (!text) return ''
|
if (!text) return ''
|
||||||
if (typeof text === 'string') return text
|
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="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}"
|
: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">
|
<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" />
|
<q-icon name="push_pin" color="orange" size="18px" class="transform rotate-45" />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file CurriculumSidebar.vue
|
* @file CurriculumSidebar.vue
|
||||||
* @description Sidebar Component for displaying course curriculum (Chapters & Lessons)
|
* @description คอมโพเนนต์แถบเมนูด้านข้างสำหรับแสดงหลักสูตรของคอร์สเรียน (บทเรียน & ตอนต่างๆ)
|
||||||
* Handles lesson navigation, locked status display, and unread announcement badge.
|
* จัดการการนำทางไปยังบทเรียน, แสดงสถานะการล็อค, และแจ้งเตือนประกาศที่ยังไม่ได้อ่าน
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: boolean; // Sidebar open state (v-model)
|
modelValue: boolean; // สถานะการเปิด/ปิดของ Sidebar (Sidebar open state - v-model)
|
||||||
courseData: any;
|
courseData: any;
|
||||||
currentLessonId?: number;
|
currentLessonId?: number;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
|
@ -21,16 +21,41 @@ const emit = defineEmits<{
|
||||||
|
|
||||||
const { locale } = useI18n()
|
const { locale } = useI18n()
|
||||||
|
|
||||||
// Helper for localization
|
// สถานะของส่วนที่ขยายได้ (State for expansion items)
|
||||||
|
const chapterOpenState = ref<Record<string, boolean>>({})
|
||||||
|
|
||||||
|
// ตัวช่วยจัดการข้อความหลายภาษา (Helper for localization)
|
||||||
const getLocalizedText = (text: any) => {
|
const getLocalizedText = (text: any) => {
|
||||||
if (!text) return ''
|
if (!text) return ''
|
||||||
if (typeof text === 'string') return text
|
if (typeof text === 'string') return text
|
||||||
|
|
||||||
const currentLocale = locale.value as 'th' | 'en'
|
// Safe locale access
|
||||||
|
const currentLocale = (locale?.value || 'th') as 'th' | 'en'
|
||||||
return text[currentLocale] || text.th || text.en || ''
|
return text[currentLocale] || text.th || text.en || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local Progress Calculation
|
// ตัวช่วยตรวจสอบว่าบทเรียนเรียนจบหรือยัง (Helper: Check if lesson is completed)
|
||||||
|
const isLessonCompleted = (lesson: any) => {
|
||||||
|
return lesson.is_completed === true || lesson.progress?.is_completed === true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ตรวจสอบสถานะการสำเร็จของบท (Reactive Chapter Completion Status)
|
||||||
|
// คำนวณเป็น Map ของ chapterId -> boolean (true ถ้าทุกบทเรียนย่อยเรียนจบแล้ว)
|
||||||
|
const chapterCompletionStatus = computed(() => {
|
||||||
|
const status: Record<string, boolean> = {}
|
||||||
|
if (!props.courseData || !props.courseData.chapters) return status
|
||||||
|
|
||||||
|
props.courseData.chapters.forEach((chapter: any) => {
|
||||||
|
if (chapter.lessons && chapter.lessons.length > 0) {
|
||||||
|
status[chapter.id] = chapter.lessons.every((l: any) => isLessonCompleted(l))
|
||||||
|
} else {
|
||||||
|
status[chapter.id] = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return status
|
||||||
|
})
|
||||||
|
|
||||||
|
// คำนวณความคืบหน้าแบบ Local (Local Progress Calculation)
|
||||||
const progressPercentage = computed(() => {
|
const progressPercentage = computed(() => {
|
||||||
if (!props.courseData || !props.courseData.chapters) return 0
|
if (!props.courseData || !props.courseData.chapters) return 0
|
||||||
let total = 0
|
let total = 0
|
||||||
|
|
@ -38,11 +63,34 @@ const progressPercentage = computed(() => {
|
||||||
props.courseData.chapters.forEach((c: any) => {
|
props.courseData.chapters.forEach((c: any) => {
|
||||||
c.lessons.forEach((l: any) => {
|
c.lessons.forEach((l: any) => {
|
||||||
total++
|
total++
|
||||||
if (l.is_completed || l.progress?.is_completed) completed++
|
if (isLessonCompleted(l)) completed++
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return total > 0 ? Math.round((completed / total) * 100) : 0
|
return total > 0 ? Math.round((completed / total) * 100) : 0
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ขยายบทเรียนปัจจุบันอัตโนมัติ (Auto-expand chapter containing current lesson)
|
||||||
|
watch(() => props.currentLessonId, (newId) => {
|
||||||
|
if (newId && props.courseData?.chapters) {
|
||||||
|
props.courseData.chapters.forEach((chapter: any) => {
|
||||||
|
const hasLesson = chapter.lessons.some((l: any) => l.id === newId)
|
||||||
|
if (hasLesson) {
|
||||||
|
chapterOpenState.value[chapter.id] = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, { immediate: true })
|
||||||
|
|
||||||
|
// ตั้งค่าเริ่มต้นให้ทุกบทเรียนเปิดอยู่เมื่อโหลด (Initialize all chapters as open by default on load)
|
||||||
|
watch(() => props.courseData, (newData) => {
|
||||||
|
if (newData?.chapters) {
|
||||||
|
newData.chapters.forEach((chapter: any) => {
|
||||||
|
if (chapterOpenState.value[chapter.id] === undefined) {
|
||||||
|
chapterOpenState.value[chapter.id] = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, { immediate: true })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -51,70 +99,110 @@ const progressPercentage = computed(() => {
|
||||||
@update:model-value="(val) => emit('update:modelValue', val)"
|
@update:model-value="(val) => emit('update:modelValue', val)"
|
||||||
show-if-above
|
show-if-above
|
||||||
bordered
|
bordered
|
||||||
side="left"
|
side="right"
|
||||||
:width="280"
|
:width="300"
|
||||||
:breakpoint="1024"
|
:breakpoint="1024"
|
||||||
class="bg-slate-50 dark:bg-slate-900 shadow-xl"
|
class="bg-slate-50 dark:!bg-slate-900 shadow-xl"
|
||||||
content-class="flex flex-col h-full"
|
|
||||||
>
|
>
|
||||||
<div v-if="courseData" class="flex flex-col h-full overflow-hidden">
|
<!-- คอนเทนเนอร์หลักบังคับใช้ความกว้างเต็มที่ (Main Container: Enforce Column Layout and Full Width) -->
|
||||||
<!-- Course Progress Header -->
|
<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">
|
||||||
<div class="p-5 border-b border-gray-200 dark:border-white/10 bg-slate-50/50 dark:bg-slate-900/50">
|
|
||||||
<div class="flex justify-between items-center mb-2">
|
<!-- 1. ส่วนหัว ด้านบนคงที่ (Header Section - Fixed at Top) -->
|
||||||
<span class="text-xs font-black uppercase tracking-widest text-slate-500 dark:text-slate-400">{{ $t('course.progress') }}</span>
|
<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">
|
||||||
<span class="text-sm font-black text-blue-600 dark:text-blue-400">{{ progressPercentage }}%</span>
|
<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>
|
||||||
|
|
||||||
|
<div class="flex justify-between items-center mb-2 w-full">
|
||||||
|
<span class="text-xs font-black uppercase tracking-widest text-slate-500 dark:!text-slate-400">{{ $t('course.progress') }}</span>
|
||||||
|
<span class="text-sm font-black text-blue-600 dark:!text-blue-400">{{ progressPercentage }}%</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="h-2 w-full bg-slate-200 dark:bg-slate-800 rounded-full overflow-hidden shadow-inner">
|
<div class="h-2 w-full bg-slate-100 dark:!bg-slate-800 rounded-full overflow-hidden">
|
||||||
<div
|
<div
|
||||||
class="h-full bg-blue-600 dark:bg-blue-500 rounded-full transition-all duration-700 ease-out shadow-[0_0_12px_rgba(37,99,235,0.3)]"
|
class="h-full bg-blue-600 dark:bg-blue-500 rounded-full transition-all duration-700 ease-out"
|
||||||
:style="{ width: `${progressPercentage}%` }"
|
:style="{ width: `${progressPercentage}%` }"
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex-grow scroll">
|
<!-- 2. รายการหลักสูตร พื้นที่เลื่อนได้ (Curriculum List - Scrollable Area) -->
|
||||||
<q-list padding class="py-2">
|
<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">
|
||||||
<template v-for="chapter in courseData.chapters" :key="chapter.id">
|
<!-- กล่องข้อมูลของบท (Chapter Accordion) -->
|
||||||
<q-item-label header class="bg-slate-100 dark:bg-slate-800 text-[var(--text-main)] font-bold sticky top-0 z-10 border-b dark:border-white/5 text-sm py-4">
|
<q-expansion-item
|
||||||
{{ getLocalizedText(chapter.title) }}
|
v-model="chapterOpenState[chapter.id]"
|
||||||
</q-item-label>
|
class="bg-white dark:!bg-slate-800 rounded-xl overflow-hidden shadow-sm border border-slate-200 dark:border-slate-700 w-full"
|
||||||
|
header-class="rounded-t-xl w-full text-slate-900 dark:!text-white"
|
||||||
<q-item
|
expand-icon-class="text-slate-400 dark:!text-slate-300"
|
||||||
v-for="lesson in chapter.lessons"
|
|
||||||
:key="lesson.id"
|
|
||||||
clickable
|
|
||||||
v-ripple
|
|
||||||
:active="currentLessonId === lesson.id"
|
|
||||||
active-class="bg-blue-50 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300 active-lesson-indicator"
|
|
||||||
class="px-5 py-3 transition-all duration-200 group relative border-b border-gray-100/50 dark:border-white/5"
|
|
||||||
@click="!lesson.is_locked && emit('select-lesson', lesson.id)"
|
|
||||||
:disable="lesson.is_locked"
|
|
||||||
>
|
>
|
||||||
<q-item-section avatar v-if="lesson.is_locked">
|
<template v-slot:header>
|
||||||
<q-icon name="lock" size="xs" color="grey" />
|
<div class="flex items-center w-full py-3 text-slate-900 dark:!text-white">
|
||||||
</q-item-section>
|
<div class="mr-3 flex-shrink-0">
|
||||||
|
<!-- ตัวบ่งชี้บทเรียน เครื่องหมายถูกหรือตัวเลข (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'
|
||||||
|
: 'border-slate-300 dark:!border-slate-600 text-slate-500 dark:!text-slate-400 bg-slate-100 dark:!bg-slate-700'">
|
||||||
|
<q-icon v-if="chapterCompletionStatus[chapter.id]" name="check" size="14px" class="font-bold" />
|
||||||
|
<span v-else class="text-[10px]">{{ Number(idx) + 1 }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- จัดการตัวอักษรที่ล้นเกินอย่างชัดเจน (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">
|
||||||
|
{{ chapter.lessons.length }} {{ $t('course.lessonsUnit') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<q-item-section>
|
<!-- รายการบทเรียนย่อย (Lessons List) -->
|
||||||
<q-item-label
|
<div class="bg-slate-50 dark:!bg-slate-800/50 border-t border-slate-100 dark:border-slate-700 w-full">
|
||||||
class="text-sm font-bold line-clamp-2 transition-colors"
|
<div
|
||||||
:class="currentLessonId === lesson.id ? 'text-blue-700 dark:text-blue-300' : 'text-slate-700 dark:text-slate-300'"
|
v-for="(lesson, lIdx) in chapter.lessons"
|
||||||
|
:key="lesson.id"
|
||||||
|
class="flex items-center px-4 py-3 cursor-pointer transition-all border-l-4 hover:bg-slate-100 dark:hover:!bg-slate-700/50 w-full"
|
||||||
|
:class="currentLessonId === lesson.id
|
||||||
|
? 'border-blue-600 bg-blue-50 dark:!bg-blue-900/40'
|
||||||
|
: 'border-transparent'"
|
||||||
|
@click="!lesson.is_locked && emit('select-lesson', lesson.id)"
|
||||||
|
>
|
||||||
|
<!-- ไอคอนสถานะของบทเรียน (Lesson Status Icon) -->
|
||||||
|
<div class="mr-3 flex-shrink-0">
|
||||||
|
<!-- เรียนจบแล้ว (สำคัญที่สุด) (Completed - Takes Precedence) -->
|
||||||
|
<q-icon v-if="isLessonCompleted(lesson)"
|
||||||
|
name="check_circle"
|
||||||
|
class="text-green-500"
|
||||||
|
size="20px"
|
||||||
|
/>
|
||||||
|
<!-- กำลังเรียนอยู่ (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) -->
|
||||||
|
<q-icon v-else-if="lesson.is_locked"
|
||||||
|
name="lock"
|
||||||
|
class="text-slate-400 dark:!text-slate-500 opacity-70"
|
||||||
|
size="18px"
|
||||||
|
/>
|
||||||
|
<!-- ยังไม่ได้เริ่ม (Not Started) -->
|
||||||
|
<div v-else class="w-[18px] h-[18px] rounded-full border-2 border-slate-300 dark:border-slate-600"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-1 min-w-0 overflow-hidden">
|
||||||
|
<div class="text-xs font-bold truncate leading-snug block w-full"
|
||||||
|
:class="currentLessonId === lesson.id ? 'text-blue-700 dark:!text-blue-300' : 'text-slate-600 dark:!text-slate-300'"
|
||||||
>
|
>
|
||||||
{{ getLocalizedText(lesson.title) }}
|
{{ getLocalizedText(lesson.title) }}
|
||||||
</q-item-label>
|
|
||||||
</q-item-section>
|
|
||||||
|
|
||||||
<q-item-section side>
|
|
||||||
<div class="flex items-center">
|
|
||||||
<q-icon v-if="lesson.is_completed || lesson.progress?.is_completed" name="check_circle" color="positive" size="18px" />
|
|
||||||
<q-icon v-else-if="currentLessonId === lesson.id" name="play_arrow" color="primary" size="18px" class="animate-pulse" />
|
|
||||||
<q-icon v-else-if="lesson.is_locked" name="lock" color="grey-4" size="18px" />
|
|
||||||
<q-icon v-else name="radio_button_unchecked" color="grey-3" size="18px" />
|
|
||||||
</div>
|
</div>
|
||||||
</q-item-section>
|
|
||||||
</q-item>
|
</div>
|
||||||
</template>
|
</div>
|
||||||
|
</div>
|
||||||
|
</q-expansion-item>
|
||||||
|
</div>
|
||||||
</q-list>
|
</q-list>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -126,31 +214,18 @@ const progressPercentage = computed(() => {
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.active-lesson-indicator {
|
/* สครอลบาร์ปรับแต่งเพื่อความสวยงาม (Custom scrollbar for better aesthetics) */
|
||||||
position: relative;
|
::-webkit-scrollbar {
|
||||||
}
|
|
||||||
.active-lesson-indicator::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
width: 4px;
|
|
||||||
background: #2563eb; /* blue-600 */
|
|
||||||
border-radius: 0 4px 4px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.scroll::-webkit-scrollbar {
|
|
||||||
width: 4px;
|
width: 4px;
|
||||||
}
|
}
|
||||||
.scroll::-webkit-scrollbar-track {
|
::-webkit-scrollbar-track {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
}
|
}
|
||||||
.scroll::-webkit-scrollbar-thumb {
|
::-webkit-scrollbar-thumb {
|
||||||
background: rgba(0, 0, 0, 0.05);
|
background: rgba(0, 0, 0, 0.1);
|
||||||
border-radius: 10px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
.dark .scroll::-webkit-scrollbar-thumb {
|
.dark ::-webkit-scrollbar-thumb {
|
||||||
background: rgba(255, 255, 255, 0.05);
|
background: rgba(255, 255, 255, 0.1);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file VideoPlayer.vue
|
* @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<{
|
const props = defineProps<{
|
||||||
|
|
@ -22,7 +22,7 @@ const videoProgress = ref(0);
|
||||||
const currentTime = ref(0);
|
const currentTime = ref(0);
|
||||||
const duration = ref(0);
|
const duration = ref(0);
|
||||||
|
|
||||||
// Media Prefs
|
// การตั้งค่าเกี่ยวกับสื่อ (Media Prefs)
|
||||||
const { volume, muted: isMuted, setVolume, setMuted, applyTo } = useMediaPrefs();
|
const { volume, muted: isMuted, setVolume, setMuted, applyTo } = useMediaPrefs();
|
||||||
|
|
||||||
const volumeIcon = computed(() => {
|
const volumeIcon = computed(() => {
|
||||||
|
|
@ -40,7 +40,7 @@ const formatTime = (time: number) => {
|
||||||
const currentTimeDisplay = computed(() => formatTime(currentTime.value));
|
const currentTimeDisplay = computed(() => formatTime(currentTime.value));
|
||||||
const durationDisplay = computed(() => formatTime(duration.value || 0));
|
const durationDisplay = computed(() => formatTime(duration.value || 0));
|
||||||
|
|
||||||
// YouTube Helper Logic
|
// ตรรกะตัวช่วยสำหรับ YouTube (YouTube Helper Logic)
|
||||||
const isYoutube = computed(() => {
|
const isYoutube = computed(() => {
|
||||||
const s = props.src.toLowerCase();
|
const s = props.src.toLowerCase();
|
||||||
return s.includes('youtube.com') || s.includes('youtu.be');
|
return s.includes('youtube.com') || s.includes('youtu.be');
|
||||||
|
|
@ -50,7 +50,7 @@ const youtubeEmbedUrl = computed(() => {
|
||||||
if (!isYoutube.value) return '';
|
if (!isYoutube.value) return '';
|
||||||
let videoId = '';
|
let videoId = '';
|
||||||
|
|
||||||
// Extract Video ID
|
// ดึงรหัสวิดีโอ (Extract Video ID)
|
||||||
if (props.src.includes('youtu.be')) {
|
if (props.src.includes('youtu.be')) {
|
||||||
videoId = props.src.split('youtu.be/')[1]?.split('?')[0];
|
videoId = props.src.split('youtu.be/')[1]?.split('?')[0];
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -58,18 +58,18 @@ const youtubeEmbedUrl = computed(() => {
|
||||||
videoId = urlParams.get('v') || '';
|
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`;
|
return `https://www.youtube.com/embed/${videoId}?enablejsapi=1&rel=0`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// YouTube API Tracking
|
// การติดตามผ่าน YouTube API (YouTube API Tracking)
|
||||||
let ytPlayer: any = null;
|
let ytPlayer: any = null;
|
||||||
let ytInterval: any = null;
|
let ytInterval: any = null;
|
||||||
|
|
||||||
const initYoutubeAPI = () => {
|
const initYoutubeAPI = () => {
|
||||||
if (!isYoutube.value || typeof window === 'undefined') return;
|
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) {
|
if (!(window as any).YT) {
|
||||||
const tag = document.createElement('script');
|
const tag = document.createElement('script');
|
||||||
tag.src = "https://www.youtube.com/iframe_api";
|
tag.src = "https://www.youtube.com/iframe_api";
|
||||||
|
|
@ -83,7 +83,7 @@ const initYoutubeAPI = () => {
|
||||||
'onReady': (event: any) => {
|
'onReady': (event: any) => {
|
||||||
duration.value = event.target.getDuration();
|
duration.value = event.target.getDuration();
|
||||||
|
|
||||||
// Resume Logic for YouTube
|
// ตรรกะการเล่นต่อสำหรับ YouTube (Resume Logic for YouTube)
|
||||||
if (props.initialSeekTime && props.initialSeekTime > 0) {
|
if (props.initialSeekTime && props.initialSeekTime > 0) {
|
||||||
event.target.seekTo(props.initialSeekTime, true);
|
event.target.seekTo(props.initialSeekTime, true);
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +118,7 @@ const startYTTracking = () => {
|
||||||
currentTime.value = ytPlayer.getCurrentTime();
|
currentTime.value = ytPlayer.getCurrentTime();
|
||||||
emit('timeupdate', currentTime.value, duration.value);
|
emit('timeupdate', currentTime.value, duration.value);
|
||||||
}
|
}
|
||||||
}, 1000); // Check every second
|
}, 1000); // ตรวจสอบทุกๆ วินาที (Check every second)
|
||||||
};
|
};
|
||||||
|
|
||||||
const stopYTTracking = () => {
|
const stopYTTracking = () => {
|
||||||
|
|
@ -145,7 +145,7 @@ onUnmounted(() => {
|
||||||
destroyYoutubePlayer();
|
destroyYoutubePlayer();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Watch for src change to re-init
|
// เฝ้าดูการเปลี่ยนแปลงของ src เพื่อเริ่มต้นใหม่ (Watch for src change to re-init)
|
||||||
watch(() => props.src, (newSrc, oldSrc) => {
|
watch(() => props.src, (newSrc, oldSrc) => {
|
||||||
if (newSrc !== oldSrc) {
|
if (newSrc !== oldSrc) {
|
||||||
destroyYoutubePlayer();
|
destroyYoutubePlayer();
|
||||||
|
|
@ -174,8 +174,8 @@ const togglePlay = () => {
|
||||||
playPromise.then(() => {
|
playPromise.then(() => {
|
||||||
isPlaying.value = true;
|
isPlaying.value = true;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
// Auto-play was prevented or play was interrupted
|
// การเล่นอัตโนมัติถูกป้องกันหรือถูกขัดจังหวะ (Auto-play was prevented or play was interrupted)
|
||||||
// We can safely ignore this error
|
// สามารถละเว้นข้อผิดพลาดนี้ได้อย่างปลอดภัย (We can safely ignore this error)
|
||||||
console.log("Video play request handled:", error.name);
|
console.log("Video play request handled:", error.name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -223,14 +223,14 @@ const handleVolumeChange = (val: any) => {
|
||||||
setVolume(newVol);
|
setVolume(newVol);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Expose video ref for parent to control if needed
|
// เปิดเผย video ref ให้คอมโพเนนต์แม่ควบคุมถ้าจำเป็น (Expose video ref for parent to control if needed)
|
||||||
defineExpose({
|
defineExpose({
|
||||||
videoRef,
|
videoRef,
|
||||||
pause: () => videoRef.value?.pause(),
|
pause: () => videoRef.value?.pause(),
|
||||||
currentTime: () => videoRef.value?.currentTime || 0
|
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], () => {
|
watch([volume, isMuted], () => {
|
||||||
if (videoRef.value) applyTo(videoRef.value);
|
if (videoRef.value) applyTo(videoRef.value);
|
||||||
});
|
});
|
||||||
|
|
@ -238,7 +238,7 @@ watch([volume, isMuted], () => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="bg-black rounded-xl overflow-hidden shadow-2xl mb-6 aspect-video relative group ring-1 ring-white/10">
|
<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
|
<iframe
|
||||||
v-if="isYoutube"
|
v-if="isYoutube"
|
||||||
id="youtube-iframe"
|
id="youtube-iframe"
|
||||||
|
|
@ -249,7 +249,7 @@ watch([volume, isMuted], () => {
|
||||||
allowfullscreen
|
allowfullscreen
|
||||||
></iframe>
|
></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">
|
<div v-else class="w-full h-full relative group/video cursor-pointer">
|
||||||
<video
|
<video
|
||||||
ref="videoRef"
|
ref="videoRef"
|
||||||
|
|
@ -262,9 +262,9 @@ watch([volume, isMuted], () => {
|
||||||
@ended="handleEnded"
|
@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">
|
<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="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 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>
|
</div>
|
||||||
|
|
@ -275,7 +275,7 @@ watch([volume, isMuted], () => {
|
||||||
|
|
||||||
<div class="flex-grow"></div>
|
<div class="flex-grow"></div>
|
||||||
|
|
||||||
<!-- Volume Control -->
|
<!-- ตัวควบคุมระดับเสียง (Volume Control) -->
|
||||||
<div class="flex items-center gap-2 group/volume relative">
|
<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" />
|
<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">
|
<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">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file FormInput.vue
|
* @file FormInput.vue
|
||||||
* @description Reusable input component with label, error handling, and support for disabled/required states.
|
* @description คอมโพเนนต์ช่องกรอกข้อมูล (Input) แบบนำกลับมาใช้ใหม่ได้ พร้อมรองรับข้อความป้ายกำกับ, จัดการข้อผิดพลาด และสถานะปิดใช้งาน/บังคับกรอก
|
||||||
* Now supports password visibility toggle.
|
* รองรับการสลับซ่อน/แสดงรหัสผ่าน
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
|
@ -16,19 +16,19 @@ const props = defineProps<{
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
/** Update v-model value */
|
/** อัปเดตค่า v-model (Update v-model value) */
|
||||||
'update:modelValue': [value: string]
|
'update:modelValue': [value: string]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
// Password visibility state
|
// สถานะการซ่อน/แสดงรหัสผ่าน (Password visibility state)
|
||||||
const showPassword = ref(false)
|
const showPassword = ref(false)
|
||||||
|
|
||||||
// Toggle function
|
// ฟังก์ชันสำหรับสลับสถานะ (Toggle function)
|
||||||
const togglePassword = () => {
|
const togglePassword = () => {
|
||||||
showPassword.value = !showPassword.value
|
showPassword.value = !showPassword.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute input type based on visibility state
|
// คำนวณประเภทของช่องกรอกข้อมูล بناءً pada state (Compute input type based on visibility state)
|
||||||
const inputType = computed(() => {
|
const inputType = computed(() => {
|
||||||
if (props.type === 'password') {
|
if (props.type === 'password') {
|
||||||
return showPassword.value ? 'text' : 'password'
|
return showPassword.value ? 'text' : 'password'
|
||||||
|
|
@ -59,7 +59,7 @@ const updateValue = (event: Event) => {
|
||||||
@input="updateValue"
|
@input="updateValue"
|
||||||
>
|
>
|
||||||
|
|
||||||
<!-- Password Toggle Button -->
|
<!-- ปุ่มสลับซ่อน/แสดงรหัสผ่าน (Password Toggle Button) -->
|
||||||
<button
|
<button
|
||||||
v-if="type === 'password'"
|
v-if="type === 'password'"
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -67,13 +67,13 @@ const updateValue = (event: Event) => {
|
||||||
@click="togglePassword"
|
@click="togglePassword"
|
||||||
tabindex="-1"
|
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">
|
<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"/>
|
<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"/>
|
<circle cx="12" cy="12" r="3"/>
|
||||||
</svg>
|
</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">
|
<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="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"/>
|
<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">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file GlobalLoader.vue
|
* @file GlobalLoader.vue
|
||||||
* @description Global full-screen loading overlay that triggers during page navigation.
|
* @description คอมโพเนนต์หน้าจอโหลดแบบเต็มจอ (Global full-screen loading) แสดงผลตอนเปลี่ยนหน้า
|
||||||
* Uses a premium pulsing logo animation.
|
* พร้มแอนิเมชันโลโก้ขยับได้แบบพรีเมียม
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
|
|
||||||
// Hook into Nuxt page transitions
|
// ดักจับจังหวะการเปลี่ยนหน้าผ่าย Nuxt hook (Hook into Nuxt page transitions)
|
||||||
nuxtApp.hook('page:start', () => {
|
nuxtApp.hook('page:start', () => {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
})
|
})
|
||||||
|
|
||||||
nuxtApp.hook('page:finish', () => {
|
nuxtApp.hook('page:finish', () => {
|
||||||
// Add a small delay for better UX (prevents flickering on fast loads)
|
// หน่วงเวลาเล็กน้อยเพื่อให้ไหลลื่น ไม่กระพริบเร็วไปหากหน้าโหลดเสร็จไว (Add a small delay for better UX)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
@ -25,14 +25,14 @@ nuxtApp.hook('page:finish', () => {
|
||||||
<Transition name="fade">
|
<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 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">
|
<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-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">
|
<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>
|
<span class="text-2xl font-black text-white">E</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Loading Text -->
|
<!-- ข้อความระหว่างโหลด (Loading Text) -->
|
||||||
<div class="flex flex-col items-center gap-2">
|
<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>
|
<h3 class="text-lg font-bold text-slate-800 dark:text-white tracking-wide">e-Learning</h3>
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file LanguageSwitcher.vue
|
* @file LanguageSwitcher.vue
|
||||||
* @description Language switcher component using Quasar dropdown.
|
* @description คอมโพเนนต์ตัวสลับภาษาใช้ปุ่ม Dropdown ของ Quasar
|
||||||
* Allows switching between Thai (th) and English (en) locales.
|
* ใช้สลับระหว่างภาษาไทย (th) และภาษาอังกฤษ (en)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { locale, setLocale, locales } = useI18n()
|
const { locale, setLocale, locales } = useI18n()
|
||||||
|
|
||||||
// Get available locales with their names
|
// ดึงรายการภาษาที่มีอยู่พร้อมชื่อภาษา (Get available locales with their names)
|
||||||
const availableLocales = computed(() => {
|
const availableLocales = computed(() => {
|
||||||
return (locales.value as Array<{ code: string; name: string }>).map((loc) => ({
|
return (locales.value as Array<{ code: string; name: string }>).map((loc) => ({
|
||||||
code: loc.code,
|
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`
|
const getFlagPath = (code: string) => `/flags/${code}.png`
|
||||||
|
|
||||||
// Handle locale change
|
// จัดการเมื่อเปลี่ยนภาษา (Handle locale change)
|
||||||
const changeLocale = async (code: string) => {
|
const changeLocale = async (code: string) => {
|
||||||
await setLocale(code as 'th' | 'en')
|
await setLocale(code as 'th' | 'en')
|
||||||
// Cookie is automatically handled by @nuxtjs/i18n with detectBrowserLanguage.useCookie
|
// คุกกี้ (Cookie) จะถูกจัดการอัตโนมัติโดย @nuxtjs/i18n จากออปชัน detectBrowserLanguage.useCookie
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ const changeLocale = async (code: string) => {
|
||||||
class="language-btn"
|
class="language-btn"
|
||||||
:aria-label="$t('language.label')"
|
:aria-label="$t('language.label')"
|
||||||
>
|
>
|
||||||
<!-- Show current locale flag -->
|
<!-- แสดงธงชาติตามภาษาที่ใช้อยู่ (Show current locale flag) -->
|
||||||
<img
|
<img
|
||||||
:src="getFlagPath(locale)"
|
:src="getFlagPath(locale)"
|
||||||
:alt="locale.toUpperCase()"
|
:alt="locale.toUpperCase()"
|
||||||
|
|
@ -178,7 +178,7 @@ const changeLocale = async (code: string) => {
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Global styles for teleported menu */
|
/* สไตล์ Global สำหรับเมนูที่ถูกข้ามไปแสดงผลที่อื่นด้วย Teleport (Global styles for teleported menu) */
|
||||||
.language-menu {
|
.language-menu {
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
|
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* @file LoadingSkeleton.vue
|
||||||
|
* @description คอมโพเนนต์ Skeleton สำหรับแสดงโครงร่างหน้าจอระหว่างรอโหลดข้อมูล (Loading Skeleton Component)
|
||||||
|
*/
|
||||||
defineProps<{
|
defineProps<{
|
||||||
type?: 'text' | 'avatar' | 'card' | 'button'
|
type?: 'text' | 'avatar' | 'card' | 'button'
|
||||||
width?: string
|
width?: string
|
||||||
|
|
@ -9,6 +13,7 @@ defineProps<{
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="skeleton-wrapper">
|
<div class="skeleton-wrapper">
|
||||||
|
<!-- กรณีเป็นโครงร่างประเภทการ์ด (Card type skeleton) -->
|
||||||
<template v-if="type === 'card'">
|
<template v-if="type === 'card'">
|
||||||
<div v-for="i in (count || 1)" :key="i" class="skeleton-card">
|
<div v-for="i in (count || 1)" :key="i" class="skeleton-card">
|
||||||
<div class="skeleton skeleton-image"/>
|
<div class="skeleton skeleton-image"/>
|
||||||
|
|
@ -20,14 +25,17 @@ defineProps<{
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<!-- กรณีเป็นโครงร่างประเภทรูปโปรไฟล์ (Avatar type skeleton) -->
|
||||||
<template v-else-if="type === 'avatar'">
|
<template v-else-if="type === 'avatar'">
|
||||||
<div class="skeleton skeleton-avatar"/>
|
<div class="skeleton skeleton-avatar"/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<!-- กรณีเป็นโครงร่างประเภทปุ่มกด (Button type skeleton) -->
|
||||||
<template v-else-if="type === 'button'">
|
<template v-else-if="type === 'button'">
|
||||||
<div class="skeleton skeleton-button" :style="{ width: width || '120px' }"/>
|
<div class="skeleton skeleton-button" :style="{ width: width || '120px' }"/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<!-- กรณีอื่นๆ จะแสดงเป็นบรรทัดข้อความ (Fallback/Text type skeleton) -->
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div
|
<div
|
||||||
v-for="i in (count || 1)"
|
v-for="i in (count || 1)"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* @file LoadingSpinner.vue
|
||||||
|
* @description ไอคอนหมุนแสดงการโหลด (Loading Spinner Component) เหมาะสำหรับใช้ตรงจุดเล็กๆ หรือตอนโหลดหน้าเว็บ
|
||||||
|
*/
|
||||||
defineProps<{
|
defineProps<{
|
||||||
size?: 'sm' | 'md' | 'lg'
|
size?: 'sm' | 'md' | 'lg'
|
||||||
text?: string
|
text?: string
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file CourseCard.vue
|
* @file CourseCard.vue
|
||||||
* @description Standardized Course Card Component.
|
* @description คอมโพเนนต์การ์ดแสดงคอร์สเรียนมาตรฐาน (Standardized Course Card Component)
|
||||||
* Usage: <CourseCard :id="1" title="..." ... />
|
* วิธีใช้งาน: <CourseCard :id="1" title="..." ... />
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface CourseCardProps {
|
interface CourseCardProps {
|
||||||
|
|
@ -20,11 +20,13 @@ interface CourseCardProps {
|
||||||
image?: string
|
image?: string
|
||||||
loading?: boolean
|
loading?: boolean
|
||||||
|
|
||||||
// Action Flags
|
// ตัวควบคุมการแสดงปุ่มต่างๆ (Action Flags)
|
||||||
showViewDetails?: boolean
|
showViewDetails?: boolean
|
||||||
showContinue?: boolean
|
showContinue?: boolean
|
||||||
showCertificate?: boolean
|
showCertificate?: boolean
|
||||||
showStudyAgain?: boolean
|
showStudyAgain?: boolean
|
||||||
|
hideProgress?: boolean
|
||||||
|
hideActions?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<CourseCardProps>(), {
|
const props = withDefaults(defineProps<CourseCardProps>(), {
|
||||||
|
|
@ -55,9 +57,9 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="group relative flex flex-col bg-white dark:!bg-[#0f172a] rounded-3xl overflow-hidden border border-slate-200 dark:border-slate-800 shadow-sm hover:shadow-xl dark:shadow-none hover:-translate-y-1 transition-all duration-300 h-full">
|
<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">
|
<div class="relative w-full aspect-video overflow-hidden">
|
||||||
<img
|
<img
|
||||||
v-if="image"
|
v-if="image"
|
||||||
|
|
@ -69,12 +71,12 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
||||||
<q-icon name="image" size="48px" class="text-slate-300 dark:text-slate-600" />
|
<q-icon name="image" size="48px" class="text-slate-300 dark:text-slate-600" />
|
||||||
</div>
|
</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>
|
<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">
|
<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">
|
<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" />
|
<q-icon name="check" size="24px" />
|
||||||
|
|
@ -82,9 +84,9 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Content Section -->
|
<!-- ส่วนเนื้อหาข้อมูล (Content Section) -->
|
||||||
<div class="p-6 flex flex-col flex-grow">
|
<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">
|
<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">
|
<span v-if="lessons" class="flex items-center gap-1">
|
||||||
<q-icon name="menu_book" size="14px" /> {{ lessons }} {{ $t('course.lessonsUnit') }}
|
<q-icon name="menu_book" size="14px" /> {{ lessons }} {{ $t('course.lessonsUnit') }}
|
||||||
|
|
@ -94,19 +96,19 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</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">
|
<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 }}
|
{{ displayTitle }}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<!-- Description -->
|
<!-- รายละเอียดเพิ่มเติม (Description) -->
|
||||||
<p v-if="displayDescription" class="text-sm text-slate-500 dark:text-slate-400 line-clamp-2 mb-6">
|
<p v-if="displayDescription" class="text-sm text-slate-500 dark:text-slate-400 line-clamp-2 mb-6">
|
||||||
{{ displayDescription }}
|
{{ displayDescription }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="mt-auto pt-4">
|
<div class="mt-auto pt-4">
|
||||||
<!-- Progress Bar -->
|
<!-- หลอดความคืบหน้า (Progress Bar) -->
|
||||||
<div v-if="progress !== undefined && !completed" class="mb-4">
|
<div v-if="progress !== undefined && !completed && !hideProgress" class="mb-4">
|
||||||
<div class="flex justify-between text-[10px] font-bold uppercase mb-1">
|
<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>
|
<span class="text-slate-500 dark:text-slate-400">{{ $t('course.progress') }}</span>
|
||||||
<span class="text-blue-600 dark:text-blue-400">{{ progress }}%</span>
|
<span class="text-blue-600 dark:text-blue-400">{{ progress }}%</span>
|
||||||
|
|
@ -116,18 +118,19 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Action Buttons -->
|
<!-- ปุ่มปฏิบัติการต่างๆ (Action Buttons) -->
|
||||||
<!-- View Details (Secondary Action) -->
|
<div v-if="!hideActions" class="flex flex-col gap-3">
|
||||||
|
<!-- ปุ่มดูรายละเอียด (ปุ่มรอง) (View Details - Secondary Action) -->
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="showViewDetails && !completed && !progress"
|
v-if="showViewDetails && !completed && !progress"
|
||||||
flat
|
flat
|
||||||
rounded
|
rounded
|
||||||
class="w-full font-bold !text-blue-600 !bg-blue-50 hover:!bg-blue-100 dark:!bg-blue-900/40 dark:!text-blue-300 dark:hover:!bg-blue-900/60"
|
class="w-full font-bold !text-blue-600 !bg-blue-50 hover:!bg-blue-100 dark:!bg-blue-500/10 dark:!text-blue-400 dark:hover:!bg-blue-500/20"
|
||||||
:label="$t('menu.viewDetails')"
|
:label="$t('menu.viewDetails')"
|
||||||
:to="`/course/${id}`"
|
:to="`/course/${id}`"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Continue Learning (Primary Action) -->
|
<!-- ปุ่มเรียนต่อ/เริ่มเรียน (ปุ่มหลัก) (Continue Learning - Primary Action) -->
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="showContinue || (progress && !completed) || (progress === 0 && !completed)"
|
v-if="showContinue || (progress && !completed) || (progress === 0 && !completed)"
|
||||||
unelevated
|
unelevated
|
||||||
|
|
@ -136,9 +139,10 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
||||||
:label="(!progress || progress === 0) ? $t('course.startLearning') : $t('course.continueLearning')"
|
:label="(!progress || progress === 0) ? $t('course.startLearning') : $t('course.continueLearning')"
|
||||||
:to="`/classroom/learning?course_id=${id}`"
|
:to="`/classroom/learning?course_id=${id}`"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="completed" class="space-y-2">
|
<div v-if="completed" class="space-y-2">
|
||||||
<!-- Study Again -->
|
<!-- ปุ่มเรียนอีกครั้ง (Study Again) -->
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="showStudyAgain"
|
v-if="showStudyAgain"
|
||||||
unelevated
|
unelevated
|
||||||
|
|
@ -148,7 +152,7 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
||||||
:to="`/classroom/learning?course_id=${id}`"
|
:to="`/classroom/learning?course_id=${id}`"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Download Certificate -->
|
<!-- ปุ่มดาวน์โหลดใบรับรอง (Download Certificate) -->
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="showCertificate"
|
v-if="showCertificate"
|
||||||
unelevated
|
unelevated
|
||||||
|
|
@ -164,5 +168,5 @@ const displayCategory = computed(() => getLocalizedText(props.category))
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
/* Scoped overrides if needed */
|
/* ใส่โค้ด CSS เพิ่มได้ถ้าต้องการครอบคลุมเฉพาะไฟล์นี้ (Scoped overrides if needed) */
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file CategorySidebar.vue
|
* @file CategorySidebar.vue
|
||||||
* @description Sidebar for filtering courses by category
|
* @description แถบเมนูด้านข้างสำหรับกรองคอร์สตามหมวดหมู่ (Sidebar for filtering courses by category)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
|
@ -81,13 +81,13 @@ const toggleCategory = (id: number) => {
|
||||||
{{ getLocalizedText(cat.name) }}
|
{{ getLocalizedText(cat.name) }}
|
||||||
</span>
|
</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 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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Show More/Less Action -->
|
<!-- ปุ่มแสดงเพิ่มเติม/แสดงน้อยลง (Show More/Less Action) -->
|
||||||
<div
|
<div
|
||||||
v-if="categories.length > 5"
|
v-if="categories.length > 5"
|
||||||
@click="showAllCategories = !showAllCategories"
|
@click="showAllCategories = !showAllCategories"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file CourseDetailView.vue
|
* @file CourseDetailView.vue
|
||||||
* @description Quick view of course details including video preview, curriculum, and enroll logic
|
* @description แสดงรายละเอียดคอร์สแบบรวดเร็ว รวมถึงตัวอย่างวิดีโอ, หลักสูตร, และระบบการลงทะเบียน
|
||||||
*/
|
*/
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
|
|
||||||
|
|
@ -33,30 +33,44 @@ const formatPrice = (price: number) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const enrollmentLoading = ref(false);
|
const enrollmentLoading = ref(false);
|
||||||
|
const activeTab = ref('curriculum');
|
||||||
|
|
||||||
|
const totalLessons = computed(() => {
|
||||||
|
if (!props.course?.chapters) return 0;
|
||||||
|
return props.course.chapters.reduce((acc: number, chapter: any) => acc + (chapter.lessons?.length || 0), 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
const totalDuration = computed(() => {
|
||||||
|
if (!props.course?.chapters) return 0;
|
||||||
|
return props.course.chapters.reduce((acc: number, chapter: any) => {
|
||||||
|
return acc + (chapter.lessons?.reduce((lAcc: number, lesson: any) => lAcc + (lesson.duration_minutes || 0), 0) || 0);
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
const handleEnroll = () => {
|
const handleEnroll = () => {
|
||||||
if(!props.course) return;
|
if(!props.course) return;
|
||||||
enrollmentLoading.value = true;
|
enrollmentLoading.value = true;
|
||||||
emit('enroll', props.course.id);
|
emit('enroll', props.course.id);
|
||||||
// Loading state reset depends on parent, but locally we can reset after emit or keep until prop changes
|
// สถานะ Loading ถูกจัดการโดยคอมโพเนนต์แม่ แต่ในคอมโพเนนต์นี้เรารีเซ็ตหลังจากส่ง event หรือเก็บไว้จนกว่า prop จะเปลี่ยน
|
||||||
// In this pattern, we just emit.
|
// ในรูปแบบนี้ เราแค่ส่ง event ออกไป (just emit)
|
||||||
setTimeout(() => enrollmentLoading.value = false, 2000); // Safety timeout
|
setTimeout(() => enrollmentLoading.value = false, 2000); // ตั้งเวลารีเซ็ตเพื่อความปลอดภัย (Safety timeout)
|
||||||
};
|
};
|
||||||
|
const instructorData = computed(() => {
|
||||||
|
if (props.course?.instructors && props.course.instructors.length > 0) {
|
||||||
|
const primary = props.course.instructors.find((i: any) => i.is_primary);
|
||||||
|
return primary ? primary.user : props.course.instructors[0].user;
|
||||||
|
}
|
||||||
|
return props.course?.creator || null;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="animate-fade-in-up">
|
<div class="animate-fade-in-up">
|
||||||
<div class="flex items-center gap-2 mb-8 group cursor-pointer" @click="emit('back')">
|
|
||||||
<q-icon name="arrow_back" size="20px" class="text-slate-400 group-hover:text-blue-600 transition-colors" />
|
|
||||||
<span class="text-sm font-bold text-slate-500 group-hover:text-blue-600 transition-colors uppercase tracking-widest">{{ $t('common.back') }}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
<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">
|
<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]">
|
<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">
|
<template v-if="course.media?.video_url">
|
||||||
<video
|
<video
|
||||||
|
|
@ -67,19 +81,19 @@ const handleEnroll = () => {
|
||||||
<source :src="course.media.video_url" type="video/mp4">
|
<source :src="course.media.video_url" type="video/mp4">
|
||||||
{{ $t('course.videoNotSupported') }}
|
{{ $t('course.videoNotSupported') }}
|
||||||
</video>
|
</video>
|
||||||
<!-- Custom Play Overlay when not playing - simple version is often best -->
|
<!-- ปุ่มเล่นวิดีโอแบบปรับแต่งเองตอนยังไม่เล่น (Custom Play Overlay when not playing) -->
|
||||||
</template>
|
</template>
|
||||||
<!-- Beautiful Image Showcase if no video -->
|
<!-- แสดงรูปภาพสวยๆ กรณีที่ไม่มีวิดีโอ (Beautiful Image Showcase if no video) -->
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div class="w-full h-full flex items-center justify-center relative overflow-hidden bg-slate-950 group">
|
<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
|
<img
|
||||||
v-if="course.thumbnail_url || course.cover_image"
|
v-if="course.thumbnail_url || course.cover_image"
|
||||||
:src="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"
|
class="absolute inset-0 w-full h-full object-cover opacity-40 blur-2xl scale-125"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Main Sharp Image -->
|
<!-- รูปหลักแบบคมชัด (Main Sharp Image) -->
|
||||||
<img
|
<img
|
||||||
v-if="course.thumbnail_url || course.cover_image"
|
v-if="course.thumbnail_url || course.cover_image"
|
||||||
:src="course.thumbnail_url || course.cover_image"
|
:src="course.thumbnail_url || course.cover_image"
|
||||||
|
|
@ -93,7 +107,7 @@ const handleEnroll = () => {
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Course Title & Description -->
|
<!-- ชื่อคอร์สและรายละเอียด (Course Title & Description) -->
|
||||||
<div>
|
<div>
|
||||||
<h1 class="text-3xl md:text-4xl font-extrabold text-slate-900 dark:text-white mb-4 leading-tight">
|
<h1 class="text-3xl md:text-4xl font-extrabold text-slate-900 dark:text-white mb-4 leading-tight">
|
||||||
{{ getLocalizedText(course.title) }}
|
{{ getLocalizedText(course.title) }}
|
||||||
|
|
@ -104,19 +118,37 @@ const handleEnroll = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Curriculum Preview -->
|
<!-- รายละเอียดคอร์ส - รูแแบบหน้าเดียว (Course Detail - Single Page Layout) -->
|
||||||
<div class="bg-slate-50 dark:bg-slate-900 rounded-3xl p-6 md:p-8 border border-slate-200 dark:border-white/5">
|
<div class="space-y-10">
|
||||||
<div class="flex items-center justify-between mb-8">
|
|
||||||
|
<!-- ข้อมูลผู้สอน (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'" />
|
||||||
|
</q-avatar>
|
||||||
<div>
|
<div>
|
||||||
<h3 class="text-xl font-black text-slate-900 dark:text-white mb-1 flex items-center gap-2">
|
<div class="text-sm text-slate-500 mb-1 font-bold uppercase tracking-wider">{{ $t('course.instructor') }}</div>
|
||||||
|
<div class="font-bold text-xl text-slate-800 dark:text-white">
|
||||||
|
{{ instructorData?.profile?.first_name || 'Unknown' }} {{ instructorData?.profile?.last_name || 'Instructor' }}
|
||||||
|
</div>
|
||||||
|
<div class="text-slate-500 text-sm mt-1">{{ instructorData?.email || 'No contact info' }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- รายละเอียดหลักสูตร / บทเรียน (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">
|
||||||
{{ $t('course.courseContent') }}
|
{{ $t('course.courseContent') }}
|
||||||
</h3>
|
</h3>
|
||||||
|
<div class="text-sm font-bold text-slate-500 dark:text-slate-400 bg-slate-100 dark:bg-white/5 px-4 py-2 rounded-full">
|
||||||
|
{{ totalLessons }} {{ $t('course.lessons') }} • {{ totalDuration }} {{ $t('quiz.minutes') }}
|
||||||
</div>
|
</div>
|
||||||
<q-icon name="keyboard_command_key" class="text-slate-200 dark:text-slate-800" size="32px" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<div v-for="(chapter, idx) in course.chapters" :key="chapter.id" class="group">
|
<div v-for="(chapter, idx) in course.chapters" :key="chapter.id" class="group">
|
||||||
|
<!-- ส่วนหัวของบท (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">
|
<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="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>
|
<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>
|
||||||
|
|
@ -124,20 +156,24 @@ const handleEnroll = () => {
|
||||||
</span>
|
</span>
|
||||||
<span class="text-[10px] uppercase font-black tracking-widest text-slate-400 opacity-60">{{ chapter.lessons?.length || 0 }} {{ $t('course.lessonsUnit') }}</span>
|
<span class="text-[10px] uppercase font-black tracking-widest text-slate-400 opacity-60">{{ chapter.lessons?.length || 0 }} {{ $t('course.lessonsUnit') }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- รายการบทเรียน (Lessons List) -->
|
||||||
<div class="ml-4 pl-4 border-l-2 border-slate-100 dark:border-slate-800 space-y-1 mt-3">
|
<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 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" :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'">
|
<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'">
|
||||||
<q-icon
|
<q-icon
|
||||||
:name="lesson.type === 'VIDEO' ? 'play_arrow' : 'article'"
|
:name="lesson.type === 'VIDEO' ? 'play_arrow' : 'article'"
|
||||||
size="16px"
|
size="16px"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span class="flex-1 font-bold">{{ getLocalizedText(lesson.title) }}</span>
|
<span class="flex-1 font-bold truncate">{{ getLocalizedText(lesson.title) }}</span>
|
||||||
<span v-if="lesson.duration_minutes" class="text-slate-400 dark:text-slate-500 text-[10px] font-bold">{{ lesson.duration_minutes }} {{ $t('quiz.minutes') }}</span>
|
<span v-if="lesson.duration_minutes" class="text-slate-400 dark:text-slate-500 text-[10px] font-bold shrink-0">{{ lesson.duration_minutes }} {{ $t('quiz.minutes') }}</span>
|
||||||
<q-icon v-if="lesson.is_locked !== false" name="lock" size="14px" class="text-slate-300 dark:text-slate-600" />
|
<q-icon v-if="lesson.is_locked !== false" name="lock" size="14px" class="text-slate-300 dark:text-slate-600 shrink-0" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- กรณีที่ไม่มีข้อมูล (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">
|
<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" />
|
<q-icon name="menu_book" size="40px" class="mb-2 opacity-50" />
|
||||||
<p class="text-sm font-medium">{{ $t('course.noContent') }}</p>
|
<p class="text-sm font-medium">{{ $t('course.noContent') }}</p>
|
||||||
|
|
@ -147,11 +183,13 @@ const handleEnroll = () => {
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Right: Enrollment Card -->
|
</div>
|
||||||
|
|
||||||
|
<!-- ด้านขวา: การ์ดลงทะเบียน (Right: Enrollment Card) -->
|
||||||
<div class="lg:col-span-1">
|
<div class="lg:col-span-1">
|
||||||
<div class="sticky top-24">
|
<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">
|
<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="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">
|
<div class="relative">
|
||||||
|
|
|
||||||
|
|
@ -1,84 +1,116 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file AppHeader.vue
|
* @file AppHeader.vue
|
||||||
* @description The main header for the authenticated application dashboard.
|
* @description แถบเมนูด้านบนหลัก (Header) สำหรับหน้าแดชบอร์ด (Dashboard) ของระบบ EduLearn
|
||||||
* Uses Quasar QToolbar.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defineProps<{
|
const props = defineProps<{
|
||||||
/** Controls visibility of the search bar */
|
/** ควบคุมการแสดงผลของปุ่มเปิด/ปิดแถบเมนูด้านข้าง (Sidebar) */
|
||||||
showSearch?: boolean
|
showSidebarToggle?: boolean;
|
||||||
}>()
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
/** Emitted when the hamburger menu is clicked */
|
/** ส่งสัญญาณ (Emit) เมื่อผู้ใช้คลิกที่ปุ่มแฮมเบอร์เกอร์เมนู */
|
||||||
toggleSidebar: []
|
toggleSidebar: [];
|
||||||
}>()
|
}>();
|
||||||
|
|
||||||
const searchText = ref('')
|
const { currentUser } = useAuth();
|
||||||
|
const { locale, setLocale } = useI18n();
|
||||||
|
const { isDark, set: setTheme } = useThemeMode();
|
||||||
|
|
||||||
|
const toggleLanguage = () => {
|
||||||
|
setLocale(locale.value === 'th' ? 'en' : 'th');
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleTheme = () => {
|
||||||
|
setTheme(!isDark.value);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<q-toolbar class="bg-transparent text-slate-800 dark:text-white h-16 px-4">
|
<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">
|
||||||
<!-- Menu Toggle (Always Visible) -->
|
|
||||||
|
<!-- ด้านซ้าย: ปุ่มย่อขยายแถบเมนูด้านข้าง (Hamburger Toggle) -->
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
round
|
round
|
||||||
dense
|
dense
|
||||||
icon="menu"
|
icon="menu"
|
||||||
@click="emit('toggleSidebar')"
|
class="text-slate-400 hover:text-blue-600 transition-colors"
|
||||||
class="mr-2 text-slate-900 dark:text-white bg-slate-100 dark:bg-slate-700/50 hover:bg-slate-200 dark:hover:bg-slate-600"
|
size="16px"
|
||||||
aria-label="Menu"
|
@click="$emit('toggleSidebar')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Branding -->
|
|
||||||
<div class="flex items-center gap-3 cursor-pointer group" @click="navigateTo('/dashboard')">
|
|
||||||
<div class="w-10 h-10 rounded-xl bg-blue-600 flex items-center justify-center text-white font-black shadow-lg shadow-blue-600/30 group-hover:scale-110 transition-transform">
|
|
||||||
E
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col">
|
|
||||||
<span class="font-black text-lg leading-none tracking-tight text-slate-900 dark:text-white group-hover:text-blue-600 transition-colors">E-Learning</span>
|
|
||||||
<span class="text-[10px] font-bold uppercase tracking-[0.2em] leading-none mt-1 text-slate-500 dark:text-slate-400">Platform</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<q-space />
|
<q-space />
|
||||||
|
|
||||||
<!-- Center Search (Optional) -->
|
<!-- ส่วนการตั้งค่าทางด้านขวา (Right Section) -->
|
||||||
<div v-if="showSearch !== false" class="hidden md:block w-1/3 max-w-md mx-4">
|
<div class="flex items-center gap-2 sm:gap-4 md:gap-6 no-wrap">
|
||||||
<q-input
|
|
||||||
|
<!-- ปุ่มสลับธีม (Theme Toggle) -->
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
round
|
||||||
dense
|
dense
|
||||||
outlined
|
:icon="isDark ? 'dark_mode' : 'light_mode'"
|
||||||
rounded
|
:class="isDark ? 'text-blue-400' : 'text-amber-500'"
|
||||||
v-model="searchText"
|
class="transition-all active:scale-90"
|
||||||
:placeholder="$t('menu.searchCourses')"
|
size="12px"
|
||||||
class="bg-slate-50 dark:bg-slate-700/50 search-input"
|
@click="toggleTheme"
|
||||||
bg-color="transparent"
|
|
||||||
>
|
>
|
||||||
<template v-slot:prepend>
|
<q-tooltip>{{ isDark ? 'โหมดกลางคืน' : 'โหมดกลางวัน' }}</q-tooltip>
|
||||||
<q-icon name="search" class="text-slate-400" />
|
</q-btn>
|
||||||
</template>
|
|
||||||
</q-input>
|
<!-- ตัวสลับภาษาแบบแคปซูล (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"
|
||||||
|
>
|
||||||
|
<div :class="locale === 'th' ? '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">TH</div>
|
||||||
|
<div class="w-[1px] h-3 bg-slate-200 dark:bg-slate-700 mx-0.5"></div>
|
||||||
|
<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>
|
</div>
|
||||||
|
|
||||||
<q-space />
|
<!-- เส้นคั่น (Divider) -->
|
||||||
|
<div class="hidden sm:block w-[1px] h-8 bg-slate-100 dark:bg-slate-800"></div>
|
||||||
|
|
||||||
<!-- Right Actions -->
|
<!-- ส่วนข้อมูลผู้ใช้งาน (User Profile) -->
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-3 cursor-pointer group" @click="navigateTo('/dashboard/profile')">
|
||||||
<!-- Language Switcher -->
|
<!-- ชื่อและบทบาท (แสดงเฉพาะบนจอที่ใหญ่กว่า 600px) -->
|
||||||
<LanguageSwitcher />
|
<div class="user-info-text flex flex-col items-end text-right">
|
||||||
|
<span class="text-[15px] font-bold text-slate-900 dark:text-white leading-tight">
|
||||||
|
{{ currentUser?.firstName || 'User' }} {{ currentUser?.lastName || '' }}
|
||||||
|
</span>
|
||||||
|
<span class="text-[11px] text-slate-500 font-medium">{{ $t('common.student') }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- รูปโปรไฟล์พร้อมวงแหวน Gradient นุ่มนวล -->
|
||||||
|
<div class="relative p-[3px] rounded-full bg-gradient-to-tr from-[#FFD1D1] via-[#E2E8FF] to-[#D1F7FF] dark:from-slate-800 dark:to-slate-700 transition-transform group-hover:scale-105">
|
||||||
|
<div class="bg-white dark:bg-[#020617] p-[1.5px] rounded-full shadow-sm">
|
||||||
|
<UserAvatar
|
||||||
|
:photoURL="currentUser?.photoURL"
|
||||||
|
:firstName="currentUser?.firstName"
|
||||||
|
:lastName="currentUser?.lastName"
|
||||||
|
size="40"
|
||||||
|
class="w-[40px] h-[40px]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- User Profile Dropdown -->
|
|
||||||
<UserMenu />
|
|
||||||
</div>
|
</div>
|
||||||
</q-toolbar>
|
</q-toolbar>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.search-input :deep(.q-field__control) {
|
/* บังคับให้ความสูงของ Header เท่ากันเสมอ (Ensure toolbar height is consistent) */
|
||||||
border-radius: 9999px; /* Full rounded */
|
:deep(.q-toolbar) {
|
||||||
|
min-height: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ซ่อนชื่อผู้ใช้ไว้เฉพาะบนหน้าจอมือถือขนาดเล็กเท่านั้น (Hide user name only on small mobile screens) */
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.user-info-text {
|
||||||
|
display: none !important;
|
||||||
}
|
}
|
||||||
.search-input :deep(.q-field__control:before) {
|
|
||||||
border-color: #e2e8f0; /* slate-200 */
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,97 +1,145 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file AppSidebar.vue
|
* @file AppSidebar.vue
|
||||||
* @description Sidebar navigation for the authenticated dashboard.
|
* @description เมนูด้านข้างสำหรับการนำทาง (Sidebar Navigation)
|
||||||
* Uses Quasar QList for structure.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// 1. นำเข้า Composables และไลบรารี
|
||||||
|
import { useQuasar } from 'quasar'
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const route = useRoute()
|
||||||
|
const $q = useQuasar()
|
||||||
|
const { logout } = useAuth()
|
||||||
|
const { isDark } = useThemeMode()
|
||||||
|
|
||||||
const navItems = computed(() => [
|
// 2. กำหนดข้อมูลเมนูหลัก (Main Navigation)
|
||||||
{
|
const menuItems = computed(() => [
|
||||||
to: "/dashboard",
|
{ to: '/dashboard', icon: 'grid_view', label: t('sidebar.overview') },
|
||||||
label: t('sidebar.overview'),
|
{ to: '/dashboard/my-courses', icon: 'book', label: t('sidebar.myCourses') }
|
||||||
icon: "dashboard", // Using Material Icons names where possible or SVG paths
|
])
|
||||||
isSvg: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
to: "/browse/discovery",
|
|
||||||
label: t('sidebar.browseCourses'),
|
|
||||||
icon: "explore",
|
|
||||||
isSvg: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
to: "/dashboard/my-courses",
|
|
||||||
label: t('sidebar.myCourses'),
|
|
||||||
icon: "school",
|
|
||||||
isSvg: false
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
|
|
||||||
const handleNavigate = (path: string) => {
|
// 3. กำหนดข้อมูลเมนูบัญชี (Account Navigation)
|
||||||
if (import.meta.client) {
|
const accountItems = computed(() => [
|
||||||
window.location.href = path
|
{ to: '/dashboard/profile', icon: 'settings', label: t('userMenu.settings') }
|
||||||
}
|
])
|
||||||
|
|
||||||
|
// 4. ฟังก์ชันการออกจากระบบ (Logout Function)
|
||||||
|
const handleLogout = () => {
|
||||||
|
$q.dialog({
|
||||||
|
title: t('auth.logoutConfirmTitle'),
|
||||||
|
message: t('auth.logoutConfirmMessage'),
|
||||||
|
cancel: {
|
||||||
|
flat: true,
|
||||||
|
color: isDark.value ? 'grey-4' : 'grey-7',
|
||||||
|
label: t('common.cancel')
|
||||||
|
},
|
||||||
|
ok: {
|
||||||
|
flat: false,
|
||||||
|
color: 'red-500',
|
||||||
|
label: t('auth.logout'),
|
||||||
|
unelevated: true
|
||||||
|
},
|
||||||
|
dark: isDark.value,
|
||||||
|
class: 'p-4 rounded-2xl text-slate-900 dark:text-white',
|
||||||
|
persistent: true
|
||||||
|
}).onOk(async () => {
|
||||||
|
await logout()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col h-full bg-transparent border-r border-slate-200 dark:border-slate-800">
|
<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) -->
|
||||||
|
<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" />
|
||||||
|
</div>
|
||||||
|
<span class="text-[22px] font-black tracking-tight text-slate-800 dark:text-white">EduLearn</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Navigation Items -->
|
<!-- การนำทางหลัก (Main Navigation) -->
|
||||||
<q-list padding class="text-slate-600 dark:text-slate-400 flex-grow px-3 pt-6">
|
<div class="space-y-1 mb-8">
|
||||||
<q-item
|
<NuxtLink
|
||||||
v-for="item in navItems"
|
v-for="item in menuItems"
|
||||||
:key="item.to"
|
:key="item.to"
|
||||||
clickable
|
:to="item.to"
|
||||||
v-ripple
|
class="flex items-center gap-4 px-4 py-3 rounded-2xl transition-all group relative nav-item"
|
||||||
@click="handleNavigate(item.to)"
|
:class="route.path === item.to ? 'active' : 'text-slate-500 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-slate-900 dark:hover:text-slate-200'"
|
||||||
class="rounded-xl mb-1 text-slate-700 dark:text-slate-200 hover:bg-slate-100 dark:hover:bg-white/5"
|
|
||||||
:class="{ 'sidebar-item--active': $route.path === item.to || ($route.path === '/dashboard' && item.to === '/dashboard') }"
|
|
||||||
>
|
>
|
||||||
<q-item-section avatar>
|
<q-icon :name="item.icon" size="24px" class="transition-colors" />
|
||||||
<q-icon :name="item.icon" size="22px" />
|
<span class="font-bold text-[15px]">{{ item.label }}</span>
|
||||||
</q-item-section>
|
|
||||||
|
|
||||||
<q-item-section>
|
<!-- ตัวบ่งชี้หน้าปัจจุบัน (Active Indicator) -->
|
||||||
<q-item-label class="font-bold text-sm">{{ item.label }}</q-item-label>
|
<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>
|
||||||
</q-item-section>
|
</NuxtLink>
|
||||||
</q-item>
|
</div>
|
||||||
</q-list>
|
|
||||||
|
|
||||||
|
<!-- หมวดหมู่บัญชี (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>
|
||||||
|
<div class="space-y-1">
|
||||||
|
<NuxtLink
|
||||||
|
v-for="item in accountItems"
|
||||||
|
:key="item.to"
|
||||||
|
:to="item.to"
|
||||||
|
class="flex items-center gap-4 px-4 py-3 rounded-2xl transition-all group nav-item"
|
||||||
|
:class="route.path === item.to ? 'active' : 'text-slate-500 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-slate-900 dark:hover:text-slate-200'"
|
||||||
|
>
|
||||||
|
<q-icon :name="item.icon" size="24px" />
|
||||||
|
<span class="font-bold text-[15px]">{{ item.label }}</span>
|
||||||
|
</NuxtLink>
|
||||||
|
|
||||||
|
<!-- ปุ่มออกจากระบบ (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"
|
||||||
|
>
|
||||||
|
<q-icon name="logout" size="24px" class="group-hover:translate-x-1 transition-transform" />
|
||||||
|
<span>{{ $t('userMenu.logout') }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<q-space />
|
||||||
|
|
||||||
|
<!-- การ์ดโปรโมชั่น (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>
|
||||||
|
<p class="text-[11px] text-slate-500 dark:text-slate-400 mb-4">{{ $t('sidebar.promoSubtitle') }}</p>
|
||||||
|
<q-btn
|
||||||
|
unelevated
|
||||||
|
class="full-width rounded-xl bg-blue-600 hover:bg-blue-700 text-white font-bold py-2.5 no-caps transition-all active:scale-95 text-xs shadow-md shadow-blue-500/20"
|
||||||
|
@click="navigateTo('/browse/discovery')"
|
||||||
|
>
|
||||||
|
{{ $t('sidebar.learnMore') }}
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- การตกแต่งพื้นหลังแบบจางๆ (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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.sidebar-item--active {
|
.nav-item.active {
|
||||||
background: #eff6ff !important; /* blue-50 */
|
background: #EFF6FF;
|
||||||
color: #1d4ed8 !important; /* blue-700 */
|
color: #2563EB;
|
||||||
position: relative;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-item--active::before {
|
.dark .nav-item.active {
|
||||||
content: '';
|
background: rgba(37,99,235,0.1);
|
||||||
position: absolute;
|
color: #60A5FA;
|
||||||
left: 0;
|
|
||||||
top: 15%;
|
|
||||||
height: 70%;
|
|
||||||
width: 4px;
|
|
||||||
background: #2563eb;
|
|
||||||
border-radius: 0 4px 4px 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dark Mode Active State Enhancement */
|
.nav-item.active .q-icon {
|
||||||
.dark .sidebar-item--active {
|
color: #2563EB;
|
||||||
background: rgba(59, 130, 246, 0.12) !important;
|
|
||||||
color: #60a5fa !important; /* blue-400 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark .sidebar-item--active .q-icon {
|
.dark .nav-item.active .q-icon {
|
||||||
color: #60a5fa !important; /* blue-400 */
|
color: #60A5FA;
|
||||||
}
|
|
||||||
|
|
||||||
.dark .sidebar-item--active::before {
|
|
||||||
background: #3b82f6;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
95
Frontend-Learner/components/layout/LandingFooter.vue
Normal file
95
Frontend-Learner/components/layout/LandingFooter.vue
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* @file LandingFooter.vue
|
||||||
|
* @description ส่วนท้ายของหน้าแรก (Footer component for the landing page)
|
||||||
|
*/
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<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) -->
|
||||||
|
<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">
|
||||||
|
<q-icon name="o_school" size="24px" />
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="font-bold text-lg leading-none tracking-tight transition-colors text-slate-900">
|
||||||
|
EduLearn
|
||||||
|
</span>
|
||||||
|
<span class="text-[10px] text-slate-500 font-semibold uppercase tracking-[0.4em] leading-none mt-0.5 transition-colors">
|
||||||
|
Platform
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</NuxtLink>
|
||||||
|
<p class="text-slate-500 text-sm leading-relaxed max-w-xs">
|
||||||
|
แพลตฟอร์มการเรียนรู้ออนไลน์ที่มุ่งเน้นการพัฒนาทักษะดิจิทัลสำหรับคนรุ่นใหม่ เรียนรู้ได้ทุกที่ ทุกเวลา กับผู้เชี่ยวชาญตัวจริง
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ลิงก์ต่างๆ (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">
|
||||||
|
<li class=""><NuxtLink to="/browse" class="hover:text-blue-600 transition-colors inline-block">คอร์สทั้งหมด</NuxtLink></li>
|
||||||
|
<li><a href="#" class="hover:text-blue-600 transition-colors inline-block">โปรโมชั่น</a></li>
|
||||||
|
<li><a href="#" class="hover:text-blue-600 transition-colors inline-block">สำหรับองค์กร</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- การสนับสนุนผู้ใช้ (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">
|
||||||
|
<li><a href="#" class="hover:text-blue-600 transition-colors inline-block">คำถามที่พบบ่อย (FAQ)</a></li>
|
||||||
|
<li><a href="#" class="hover:text-blue-600 transition-colors inline-block">วิธีการใช้งาน</a></li>
|
||||||
|
<li><a href="#" class="hover:text-blue-600 transition-colors inline-block">เงื่อนไขการใช้งาน</a></li>
|
||||||
|
<li><a href="#" class="hover:text-blue-600 transition-colors inline-block">นโยบายความเป็นส่วนตัว</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ข้อมูลการติดต่อ (Contact) -->
|
||||||
|
<div class="space-y-6">
|
||||||
|
<h4 class="font-bold text-slate-900 text-base">ติดต่อเรา</h4>
|
||||||
|
<div class="flex flex-col gap-5">
|
||||||
|
<!-- สถานที่ตั้ง (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">
|
||||||
|
<span class="font-semibold text-slate-800 text-sm leading-tight">Bronco Hourse</span>
|
||||||
|
<p class="text-slate-500 text-[11px] leading-relaxed">
|
||||||
|
74/2 Wiang Kaew Road, Tambon Si Phum, Amphoe Mueang Chiang Mai, Chang Wat Chiang Mai 50200
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- เบอร์โทรศัพท์ (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 transition-colors truncate">
|
||||||
|
052-076-025
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- อีเมล (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 transition-colors truncate">
|
||||||
|
info@chamomind.com
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- แถบด้านล่างสำหรับสงวนลิขสิทธิ์ (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
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
</template>
|
||||||
|
|
@ -1,50 +1,64 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file LandingHeader.vue
|
* @file LandingHeader.vue
|
||||||
* @description The main header for the public landing pages.
|
* @description คอมโพเนนต์แถบเมนูด้านบน (Header Navigation) สำหรับหน้า Landing Page และหน้าเปิดอื่นๆ
|
||||||
* Features a transparent background that becomes solid/glass upon scrolling.
|
* รองรับการเปลี่ยนภาษา เปลี่ยนโหมดสว่าง/มืด และเข้าถึงเมนูผู้ใช้ (Profile/Logout)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Track scrolling state to adjust header styling
|
// ติดตามสถานะการเลื่อนเมาส์ (scroll) เพื่อปรับรูปแบบของ Header
|
||||||
const isScrolled = ref(false)
|
const isScrolled = ref(false)
|
||||||
const { isAuthenticated } = useAuth()
|
const { isAuthenticated } = useAuth()
|
||||||
|
// สถานะเมนูสำหรับหน้าจอมือถือ (Mobile Drawer State)
|
||||||
|
// ตัวแปรควบคุมการเปิด/ปิดเมนูบนหน้าจอขนาดเล็ก (Mobile Drawer)
|
||||||
|
const mobileMenuOpen = ref(false)
|
||||||
|
|
||||||
|
const handleScroll = () => {
|
||||||
|
isScrolled.value = window.scrollY > 20
|
||||||
|
}
|
||||||
|
|
||||||
|
// ปิดการเลื่อนหน้าเว็บ (Lock body scroll) เมื่อเปิดเมนูบนมือถือ
|
||||||
|
watch(mobileMenuOpen, (isOpen) => {
|
||||||
|
if (isOpen) {
|
||||||
|
document.body.style.overflow = 'hidden'
|
||||||
|
} else {
|
||||||
|
document.body.style.overflow = ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// Add scroll listener to toggle 'isScrolled' class
|
window.addEventListener('scroll', handleScroll)
|
||||||
window.addEventListener('scroll', () => {
|
|
||||||
isScrolled.value = window.scrollY > 20
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener('scroll', handleScroll)
|
||||||
|
document.body.style.overflow = '' // คืนค่าเริ่มต้น (Cleanup)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<!--
|
<!--
|
||||||
Header Container
|
คอนเทนเนอร์ของ Header (Header Container)
|
||||||
- Transitions between transparent and glass effect based on scroll.
|
- เปลี่ยนจากสีใส (transparent) เป็นเอฟเฟกต์กระจก (glass effect) เมื่อเลื่อนเมาส์ลง
|
||||||
-->
|
-->
|
||||||
<header
|
<header
|
||||||
class="landing-header transition-all duration-300"
|
class="fixed top-0 left-0 right-0 z-[100] transition-all"
|
||||||
:class="[isScrolled ? 'h-16 glass-nav shadow-lg' : 'h-24 bg-transparent']"
|
:class="[isScrolled ? 'h-20 glass-nav shadow-lg' : 'h-20 bg-transparent duration-300 border-b border-b-grey-7 ']"
|
||||||
>
|
>
|
||||||
<div class="container h-full flex items-center justify-between">
|
<div class="container mx-auto px-6 md:px-12 h-full flex items-center justify-between">
|
||||||
<!--
|
<!-- ด้านซ้าย: โลโก้แบรนด์ (Left Section: Logo) -->
|
||||||
Left Section: Logo & Desktop Navigation
|
|
||||||
-->
|
|
||||||
<div class="flex items-center gap-12">
|
|
||||||
<!-- Logo -->
|
|
||||||
<NuxtLink to="/" class="flex items-center gap-3 group">
|
<NuxtLink to="/" class="flex items-center gap-3 group">
|
||||||
<div class="logo-box bg-blue-600 text-white font-black rounded-xl w-10 h-10 flex items-center justify-center shadow-lg shadow-blue-600/30 group-hover:scale-110 transition-transform">
|
<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">
|
||||||
E
|
<q-icon name="o_school" size="24px" />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<span
|
<span
|
||||||
class="font-black text-lg leading-none tracking-tight transition-colors"
|
class="font-bold text-lg leading-none tracking-tight transition-colors"
|
||||||
:class="[isScrolled ? 'text-white' : 'text-slate-900 group-hover:text-blue-600']"
|
:class="[isScrolled ? 'text-white' : 'text-slate-900 group-hover:text-blue-600']"
|
||||||
>
|
>
|
||||||
E-Learning
|
EduLearn
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
class="text-[10px] font-bold uppercase tracking-[0.2em] leading-none mt-1 transition-colors"
|
class="text-[10px] font-semibold uppercase tracking-[0.4em] leading-none mt-0.5 transition-colors"
|
||||||
:class="[isScrolled ? 'text-slate-400' : 'text-slate-500']"
|
:class="[isScrolled ? 'text-slate-400' : 'text-slate-500']"
|
||||||
>
|
>
|
||||||
Platform
|
Platform
|
||||||
|
|
@ -52,81 +66,157 @@ onMounted(() => {
|
||||||
</div>
|
</div>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
|
|
||||||
<!-- Desktop Links -->
|
<!-- การนำทางสำหรับเดสก์ท็อป (แสดงผลเป็นค่าเริ่มต้น, ซ่อนบนมือถือผ่าน CSS 'desktop-nav') -->
|
||||||
<nav class="hidden md:block">
|
<!-- <nav class="flex desktop-nav items-center gap-8 text-[16px] font-medium">
|
||||||
<ul class="flex items-center gap-8 text-sm font-bold">
|
|
||||||
<li>
|
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
to="/browse"
|
to="/browse"
|
||||||
class="transition-colors relative group"
|
class="transition-colors relative group py-2"
|
||||||
:class="[isScrolled ? 'text-slate-400 hover:text-white' : 'text-slate-600 hover:text-blue-600']"
|
:class="[isScrolled ? 'text-white hover:text-white' : 'text-grey-8 hover:text-blue-600']"
|
||||||
>
|
>
|
||||||
{{ $t('landing.allCourses') }}
|
{{ $t('sidebar.onlineCourses') }}
|
||||||
<span class="absolute -bottom-1 left-0 w-0 h-0.5 bg-blue-600 transition-all group-hover:w-full"/>
|
<span class="absolute bottom-0 left-0 w-0 h-0.5 bg-blue-600 transition-all group-hover:w-full"/>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
to="/browse/discovery"
|
to="/browse/recommended"
|
||||||
class="transition-colors relative group"
|
class="transition-colors relative group py-2"
|
||||||
:class="[isScrolled ? 'text-slate-400 hover:text-white' : 'text-slate-600 hover:text-blue-600']"
|
:class="[isScrolled ? 'text-white hover:text-white' : 'text-grey-8 hover:text-blue-600']"
|
||||||
>
|
>
|
||||||
{{ $t('landing.discovery') }}
|
{{ $t('sidebar.recommendedCourses') }}
|
||||||
<span class="absolute -bottom-1 left-0 w-0 h-0.5 bg-blue-600 transition-all group-hover:w-full"/>
|
<span class="absolute bottom-0 left-0 w-0 h-0.5 bg-blue-600 transition-all group-hover:w-full"/>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</li>
|
</nav> -->
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Right Section: Action Buttons (Login/Register or Dashboard)
|
|
||||||
-->
|
<!-- ปุ่มปฏิบัติการสำหรับเดสก์ท็อป (แสดงผลเป็นค่าเริ่มต้น, ซ่อนบนมือถือผ่าน CSS 'desktop-nav') -->
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex desktop-nav items-center gap-4">
|
||||||
<template v-if="!isAuthenticated">
|
<template v-if="!isAuthenticated">
|
||||||
|
<!-- ปุ่มเข้าสู่ระบบ (Login Button) -->
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
to="/auth/login"
|
to="/auth/login"
|
||||||
class="btn-secondary-premium shadow-sm"
|
class="px-5 py-4 rounded-full text-slate-700 font-semibold text-sm transition-all hover:-translate-y-0.5"
|
||||||
:class="[isScrolled ? 'border-white/20 text-white hover:bg-white/10' : 'bg-blue-50 border-blue-100 text-blue-600 hover:bg-blue-100 hover:border-blue-200']"
|
:class="[isScrolled ? 'border-white/20 text-white hover:bg-white/10' : 'border-white text-grey-9 bg-white hover:bg-blue-100 hover:border-blue-200']"
|
||||||
>
|
>
|
||||||
{{ $t('auth.login') }}
|
{{ $t('auth.login') }}
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<NuxtLink to="/auth/register" class="btn-primary-premium shadow-lg shadow-blue-600/20">
|
|
||||||
|
<!-- ปุ่มสมัครสมาชิก (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"
|
||||||
|
>
|
||||||
{{ $t('auth.getStarted') }}
|
{{ $t('auth.getStarted') }}
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<NuxtLink to="/dashboard" class="btn-primary-premium shadow-lg shadow-blue-600/20">
|
<NuxtLink
|
||||||
|
to="/dashboard"
|
||||||
|
class="bg-blue-600 text-white font-semibold text-sm px-5 py-4 rounded-full hover:shadow-blue-600/40 hover:-translate-y-0.5 transition-all"
|
||||||
|
>
|
||||||
{{ $t('landing.goToDashboard') }}
|
{{ $t('landing.goToDashboard') }}
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- ปุ่มเปิดเมนูบนมือถือ (แสดงผลเฉพาะบน 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]' : '']"
|
||||||
|
@click="mobileMenuOpen = !mobileMenuOpen"
|
||||||
|
>
|
||||||
|
<q-icon :name="mobileMenuOpen ? 'close' : 'menu'" size="24px" />
|
||||||
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
<!-- ลิ้นชักเมนูด้านข้างสำหรับมือถือ (Mobile Navigation Drawer - แยกส่วนไปยัง body เพื่อไม่ให้มีปัญหา z-index หรือถูกบัง) -->
|
||||||
|
<Teleport to="body">
|
||||||
|
<div v-if="mobileMenuOpen">
|
||||||
|
<div
|
||||||
|
class="fixed inset-0 bg-slate-900/50 backdrop-blur-sm z-[2000] transition-opacity duration-300 md:hidden"
|
||||||
|
:class="[mobileMenuOpen ? 'opacity-100 pointer-events-auto' : 'opacity-0 pointer-events-none']"
|
||||||
|
@click="mobileMenuOpen = false"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="fixed top-0 right-0 h-full w-4/5 max-w-sm bg-white shadow-2xl z-[2001] transform transition-transform duration-300 ease-out md:hidden flex flex-col"
|
||||||
|
: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) -->
|
||||||
|
<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"
|
||||||
|
>
|
||||||
|
<q-icon name="close" size="20px" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- ลิงก์สำหรับมือถือ (Mobile Links) -->
|
||||||
|
<nav class="flex flex-col gap-2 mt-8">
|
||||||
|
<NuxtLink
|
||||||
|
to="/"
|
||||||
|
class="flex items-center justify-between p-4 rounded-xl hover:bg-slate-50 text-slate-700 font-bold transition-colors"
|
||||||
|
@click="mobileMenuOpen = false"
|
||||||
|
>
|
||||||
|
{{ $t('sidebar.overview') }}
|
||||||
|
<q-icon name="chevron_right" size="20px" class="text-slate-400" />
|
||||||
|
</NuxtLink>
|
||||||
|
<NuxtLink
|
||||||
|
to="/browse"
|
||||||
|
class="flex items-center justify-between p-4 rounded-xl hover:bg-slate-50 text-slate-700 font-bold transition-colors"
|
||||||
|
@click="mobileMenuOpen = false"
|
||||||
|
>
|
||||||
|
{{ $t('sidebar.onlineCourses') }}
|
||||||
|
<q-icon name="chevron_right" size="20px" class="text-slate-400" />
|
||||||
|
</NuxtLink>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="mt-auto pb-8 border-t border-slate-100 pt-8">
|
||||||
|
<template v-if="!isAuthenticated">
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<NuxtLink
|
||||||
|
to="/auth/login"
|
||||||
|
class="w-full py-3 rounded-xl font-bold text-center border-2 border-slate-200 text-slate-700 hover:bg-slate-50 transition-colors"
|
||||||
|
@click="mobileMenuOpen = false"
|
||||||
|
>
|
||||||
|
{{ $t('auth.login') }}
|
||||||
|
</NuxtLink>
|
||||||
|
<NuxtLink
|
||||||
|
to="/auth/register"
|
||||||
|
class="w-full py-3 rounded-xl font-bold text-center text-white bg-blue-600 shadow-lg hover:bg-blue-700 transition-colors"
|
||||||
|
@click="mobileMenuOpen = false"
|
||||||
|
>
|
||||||
|
{{ $t('auth.getStarted') }}
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<NuxtLink
|
||||||
|
to="/dashboard"
|
||||||
|
class="flex items-center justify-center w-full py-3 rounded-xl font-bold text-white bg-gradient-to-r from-blue-600 to-indigo-600 shadow-lg shadow-blue-500/30"
|
||||||
|
@click="mobileMenuOpen = false"
|
||||||
|
>
|
||||||
|
{{ $t('landing.goToDashboard') }} <q-icon name="arrow_forward" class="ml-2" />
|
||||||
|
</NuxtLink>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Teleport>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
/* Header content */
|
/* เอฟเฟกต์ Glassmorphism สำหรับ Header ตอนเลื่อนเมาส์ลง */
|
||||||
.landing-header {
|
|
||||||
width: 100%;
|
|
||||||
z-index: 100;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Glassmorphism Effect for Scrolled Header */
|
|
||||||
.glass-nav {
|
.glass-nav {
|
||||||
background: rgba(15, 23, 42, 0.8);
|
background: rgba(15, 23, 42, 0.95); /* พื้นหลังเข้มขึ้นเพื่อให้อ่านตัวหนังสือชัดเจน */
|
||||||
backdrop-filter: blur(12px);
|
backdrop-filter: blur(16px);
|
||||||
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
/* สไตล์ปุ่มหลัก (Primary Button) แบบพรีเมียม */
|
||||||
max-width: 1440px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 0 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Premium Primary Button Styling */
|
|
||||||
.btn-primary-premium {
|
.btn-primary-premium {
|
||||||
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
|
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
|
||||||
color: white;
|
color: white;
|
||||||
|
|
@ -145,7 +235,7 @@ onMounted(() => {
|
||||||
box-shadow: 0 8px 20px -4px rgba(37, 99, 235, 0.5);
|
box-shadow: 0 8px 20px -4px rgba(37, 99, 235, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Secondary Premium Button Styling */
|
/* สไตล์ปุ่มดรอง (Secondary Button) แบบพรีเมียม */
|
||||||
.btn-secondary-premium {
|
.btn-secondary-premium {
|
||||||
padding: 0.75rem 1.5rem;
|
padding: 0.75rem 1.5rem;
|
||||||
border-radius: 0.75rem;
|
border-radius: 0.75rem;
|
||||||
|
|
@ -167,4 +257,21 @@ onMounted(() => {
|
||||||
padding: 0 16px;
|
padding: 0 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
โลจิกบังคับการแสดงผล เพื่อแก้ปัญหาการคอมไฟล์ของ Tailwind
|
||||||
|
ยืนยันว่าส่วน Desktop และ Mobile เลย์เอาต์แยกจากกันอย่างชัดเจน
|
||||||
|
*/
|
||||||
|
.desktop-nav {
|
||||||
|
display: flex; /* แสดงผลเป็นค่าเริ่มต้น */
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 767.98px) {
|
||||||
|
.desktop-nav {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
.mobile-toggle {
|
||||||
|
display: flex !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { t } = useI18n()
|
const { mobileItems } = useNavItems()
|
||||||
|
const navItems = mobileItems
|
||||||
const navItems = computed(() => [
|
|
||||||
{ to: '/dashboard', icon: 'dashboard', label: t('sidebar.overview') },
|
|
||||||
{ to: '/browse/discovery', icon: 'explore', label: t('sidebar.browseCourses') },
|
|
||||||
{ to: '/dashboard/my-courses', icon: 'school', label: t('sidebar.myCourses') }
|
|
||||||
])
|
|
||||||
|
|
||||||
const handleNavigate = (path: string) => {
|
const handleNavigate = (path: string) => {
|
||||||
if (import.meta.client) {
|
if (import.meta.client) {
|
||||||
|
|
@ -27,7 +22,7 @@ const handleNavigate = (path: string) => {
|
||||||
:key="item.to"
|
:key="item.to"
|
||||||
@click="handleNavigate(item.to)"
|
@click="handleNavigate(item.to)"
|
||||||
:icon="item.icon"
|
:icon="item.icon"
|
||||||
:label="item.label"
|
:label="$t(item.labelKey)"
|
||||||
no-caps
|
no-caps
|
||||||
class="py-2"
|
class="py-2"
|
||||||
:class="{ 'q-tab--active text-primary': $route.path === item.to }"
|
:class="{ 'q-tab--active text-primary': $route.path === item.to }"
|
||||||
|
|
@ -36,7 +31,7 @@ const handleNavigate = (path: string) => {
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
/* Optional shadow for better separation */
|
/* เงาด้านบนแบบบางๆ เพื่อแบ่งส่วนล่างให้ชัดเจนขึ้น (Optional shadow for better separation) */
|
||||||
.shadow-up-1 {
|
.shadow-up-1 {
|
||||||
box-shadow: 0 -1px 3px rgba(0,0,0,0.05);
|
box-shadow: 0 -1px 3px rgba(0,0,0,0.05);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file PasswordChangeForm.vue
|
* @file PasswordChangeForm.vue
|
||||||
* @description From for changing user password
|
* @description ฟอร์มสำหรับเปลี่ยนรหัสผ่านของผู้ใช้ (From for changing user password)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: any; // passwordForm (currentPassword, newPassword, confirmPassword)
|
modelValue: any; // passwordForm (currentPassword, newPassword, confirmPassword)
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
flat?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
|
@ -33,11 +34,15 @@ const showConfirmPassword = ref(false);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="card-premium p-8 h-fit">
|
<div :class="[!flat ? 'card-premium p-6 md:p-8' : '']" class="h-fit">
|
||||||
<h2 class="text-xl font-bold flex items-center gap-3 text-slate-900 dark:text-white mb-6">
|
<div v-if="!flat" class="flex items-center gap-3 mb-8">
|
||||||
<q-icon name="lock" class="text-amber-500 text-2xl" />
|
<div class="w-10 h-10 rounded-xl bg-blue-50 dark:bg-blue-900/30 flex items-center justify-center">
|
||||||
|
<q-icon name="lock" class="text-blue-600 dark:text-blue-400 text-xl" />
|
||||||
|
</div>
|
||||||
|
<h2 class="text-xl font-black text-slate-900 dark:text-white">
|
||||||
{{ $t('profile.security') }}
|
{{ $t('profile.security') }}
|
||||||
</h2>
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
<q-form @submit="emit('submit')" class="flex flex-col gap-6">
|
<q-form @submit="emit('submit')" class="flex flex-col gap-6">
|
||||||
<div class="text-sm text-slate-500 dark:text-slate-400 mb-2">
|
<div class="text-sm text-slate-500 dark:text-slate-400 mb-2">
|
||||||
|
|
@ -113,8 +118,8 @@ const showConfirmPassword = ref(false);
|
||||||
type="submit"
|
type="submit"
|
||||||
unelevated
|
unelevated
|
||||||
rounded
|
rounded
|
||||||
class="w-full py-3 font-bold text-base shadow-lg shadow-amber-500/20"
|
class="w-full py-3 font-bold text-base shadow-lg shadow-blue-500/20"
|
||||||
style="background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); color: white;"
|
style="background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); color: white;"
|
||||||
:label="$t('profile.changePasswordBtn')"
|
:label="$t('profile.changePasswordBtn')"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
/>
|
/>
|
||||||
|
|
@ -125,7 +130,12 @@ const showConfirmPassword = ref(false);
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.card-premium {
|
.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-radius: 1.5rem;
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05);
|
box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file ProfileEditForm.vue
|
* @file ProfileEditForm.vue
|
||||||
* @description From for editing user personal information
|
* @description ฟอร์มสำหรับแก้ไขข้อมูลส่วนตัวของผู้ใช้ (Form for editing user personal information)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: any; // userData (firstName, lastName, phone, etc.)
|
modelValue: any; // userData (firstName, lastName, phone, etc.)
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
verifying?: boolean;
|
verifying?: boolean;
|
||||||
|
flat?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
|
@ -67,11 +68,15 @@ const onPhoneKeydown = (e: KeyboardEvent) => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="card-premium p-8 h-fit">
|
<div :class="[!flat ? 'card-premium p-6 md:p-8' : '']" class="h-fit">
|
||||||
<h2 class="text-xl font-bold flex items-center gap-3 text-slate-900 dark:text-white mb-6">
|
<div v-if="!flat" class="flex items-center gap-3 mb-8">
|
||||||
<q-icon name="person" class="text-blue-500 text-2xl" />
|
<div class="w-10 h-10 rounded-xl bg-blue-50 dark:bg-blue-900/30 flex items-center justify-center">
|
||||||
|
<q-icon name="person" class="text-blue-600 dark:text-blue-400 text-xl" />
|
||||||
|
</div>
|
||||||
|
<h2 class="text-xl font-black text-slate-900 dark:text-white">
|
||||||
{{ $t('profile.editPersonalDesc') }}
|
{{ $t('profile.editPersonalDesc') }}
|
||||||
</h2>
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col gap-6">
|
<div class="flex flex-col gap-6">
|
||||||
|
|
||||||
|
|
@ -88,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">
|
<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" />
|
<q-icon name="camera_alt" class="text-white text-xl" />
|
||||||
</div>
|
</div>
|
||||||
<!-- Hidden Input -->
|
<!-- ช่องเลือกไฟล์ที่ถูกซ่อนไว้ (Hidden Input) -->
|
||||||
<input ref="fileInput" type="file" class="hidden" accept="image/*" @change="handleFileUpload" >
|
<input ref="fileInput" type="file" class="hidden" accept="image/*" @change="handleFileUpload" >
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<div class="font-bold text-slate-900 dark:text-white mb-1">{{ $t('profile.yourAvatar') }}</div>
|
<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">
|
<div class="flex items-center gap-3">
|
||||||
<template v-if="modelValue.photoURL">
|
<template v-if="modelValue.photoURL">
|
||||||
<q-btn
|
<q-btn
|
||||||
|
|
@ -119,7 +124,7 @@ const onPhoneKeydown = (e: KeyboardEvent) => {
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add Limit Text -->
|
<!-- ข้อความจำกัดขนาดไฟล์ (Add Limit Text) -->
|
||||||
<div class="mt-1 text-xs text-slate-500 dark:text-slate-400">
|
<div class="mt-1 text-xs text-slate-500 dark:text-slate-400">
|
||||||
{{ $t('profile.uploadLimit') }}
|
{{ $t('profile.uploadLimit') }}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -243,7 +248,12 @@ const onPhoneKeydown = (e: KeyboardEvent) => {
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.card-premium {
|
.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-radius: 1.5rem;
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05);
|
box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* @file UserAvatar.vue
|
||||||
|
* @description คอมโพเนนต์แสดงรูปโปรไฟล์ผู้ใช้ หากไม่มีรูปจะแสดงตัวอักษรย่อของชื่อ
|
||||||
|
*/
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
size?: number | string
|
size?: number | string
|
||||||
photoURL?: string
|
photoURL?: string
|
||||||
|
|
@ -19,7 +23,7 @@ const avatarSize = computed(() => {
|
||||||
const initials = computed(() => {
|
const initials = computed(() => {
|
||||||
const getFirstChar = (name?: string) => {
|
const getFirstChar = (name?: string) => {
|
||||||
if (!name) return ''
|
if (!name) return ''
|
||||||
// For Thai names, if the first char is a leading vowel (เ แ โ ใ ไ), skip it to get the consonant
|
// สำหรับชื่อภาษาไทย ถ้าตัวอักษรแรกเป็นสระนำหน้า (เ แ โ ใ ไ) ให้ข้ามไปเอาพยัญชนะ
|
||||||
const leadingVowels = ['เ', 'แ', 'โ', 'ใ', 'ไ']
|
const leadingVowels = ['เ', 'แ', 'โ', 'ใ', 'ไ']
|
||||||
if (leadingVowels.includes(name.charAt(0)) && name.length > 1) {
|
if (leadingVowels.includes(name.charAt(0)) && name.length > 1) {
|
||||||
return name.charAt(1)
|
return name.charAt(1)
|
||||||
|
|
@ -36,7 +40,7 @@ const handleImageError = () => {
|
||||||
imageError.value = true
|
imageError.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch for photoURL changes to reset error state
|
// รีเซ็ตสถานะข้อผิดพลาดเมื่อรูปโปรไฟล์เปลี่ยน (Watch for photoURL changes to reset error state)
|
||||||
watch(() => props.photoURL, () => {
|
watch(() => props.photoURL, () => {
|
||||||
imageError.value = false
|
imageError.value = false
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file UserMenu.vue
|
* @file UserMenu.vue
|
||||||
* @description User profile dropdown menu component using Quasar.
|
* @description คอมโพเนนต์เมนู Dropdown ของโปรไฟล์ผู้ใช้ ใช้ Quasar
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
|
|
@ -12,7 +12,7 @@ const { currentUser, logout } = useAuth()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const $q = useQuasar()
|
const $q = useQuasar()
|
||||||
|
|
||||||
// Use centralized theme management
|
// จัดการการเปลี่ยนธีมแบบรวมศูนย์ (Use centralized theme management)
|
||||||
const { isDark, set } = useThemeMode()
|
const { isDark, set } = useThemeMode()
|
||||||
|
|
||||||
const isHydrated = ref(false)
|
const isHydrated = ref(false)
|
||||||
|
|
@ -21,7 +21,7 @@ onMounted(() => {
|
||||||
isHydrated.value = true
|
isHydrated.value = true
|
||||||
})
|
})
|
||||||
|
|
||||||
// User Initials
|
// ตัวอักษรย่อของผู้ใช้ (User Initials)
|
||||||
const userInitials = computed(() => {
|
const userInitials = computed(() => {
|
||||||
if (!currentUser.value) return ''
|
if (!currentUser.value) return ''
|
||||||
const f = currentUser.value.firstName?.charAt(0).toUpperCase() || 'U'
|
const f = currentUser.value.firstName?.charAt(0).toUpperCase() || 'U'
|
||||||
|
|
@ -29,12 +29,9 @@ const userInitials = computed(() => {
|
||||||
return f + l
|
return f + l
|
||||||
})
|
})
|
||||||
|
|
||||||
const menuItems = computed(() => [
|
const { userMenuItems } = useNavItems()
|
||||||
{ label: t('userMenu.home'), to: '/dashboard' },
|
const menuItems = userMenuItems
|
||||||
{ label: t('userMenu.courseList'), to: '/browse/discovery' },
|
|
||||||
{ label: t('userMenu.myCourses'), to: '/dashboard/my-courses' },
|
|
||||||
{ label: t('userMenu.settings'), to: '/dashboard/profile' }
|
|
||||||
])
|
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
await logout()
|
await logout()
|
||||||
|
|
@ -63,14 +60,14 @@ const handleLogout = async () => {
|
||||||
<q-list class="py-2">
|
<q-list class="py-2">
|
||||||
<q-item
|
<q-item
|
||||||
v-for="item in menuItems"
|
v-for="item in menuItems"
|
||||||
:key="item.label"
|
:key="item.labelKey"
|
||||||
clickable
|
clickable
|
||||||
v-close-popup
|
v-close-popup
|
||||||
@click="navigateTo(item.to)"
|
@click="navigateTo(item.to)"
|
||||||
class="hover:bg-slate-100 dark:hover:bg-white/5 transition-colors"
|
class="hover:bg-slate-100 dark:hover:bg-white/5 transition-colors"
|
||||||
>
|
>
|
||||||
<q-item-section>
|
<q-item-section>
|
||||||
<q-item-label class="font-bold text-sm text-slate-800 dark:text-slate-100">{{ item.label }}</q-item-label>
|
<q-item-label class="font-bold text-sm text-slate-800 dark:text-slate-100">{{ $t(item.labelKey) }}</q-item-label>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,4 @@
|
||||||
|
import type { User, LoginResponse, RegisterPayload } from '@/types/auth'
|
||||||
// Interface สำหรับข้อมูลผู้ใช้งาน (User)
|
|
||||||
interface User {
|
|
||||||
id: number
|
|
||||||
username: string
|
|
||||||
email: string
|
|
||||||
email_verified_at?: string | null
|
|
||||||
created_at?: string
|
|
||||||
updated_at?: string
|
|
||||||
role: {
|
|
||||||
code: string // เช่น 'STUDENT', 'INSTRUCTOR', 'ADMIN'
|
|
||||||
name: { th: string; en: string }
|
|
||||||
}
|
|
||||||
profile?: {
|
|
||||||
prefix: { th: string; en: string }
|
|
||||||
first_name: string
|
|
||||||
last_name: string
|
|
||||||
phone: string | null
|
|
||||||
avatar_url: string | null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Interface สำหรับข้อมูลตอบกลับตอน Login
|
|
||||||
interface loginResponse {
|
|
||||||
token: string
|
|
||||||
refreshToken: string
|
|
||||||
user: User
|
|
||||||
profile: User['profile']
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interface สำหรับข้อมูลที่ใช้ลงทะเบียน
|
|
||||||
interface RegisterPayload {
|
|
||||||
username: string
|
|
||||||
email: string
|
|
||||||
password: string
|
|
||||||
first_name: string
|
|
||||||
last_name: string
|
|
||||||
prefix: { th: string; en: string }
|
|
||||||
phone: string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// Composable: useAuth
|
// Composable: useAuth
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,21 @@
|
||||||
// Interface สำหรับข้อมูลหมวดหมู่ (Category)
|
/**
|
||||||
|
* @interface Category
|
||||||
|
* @description โครงสร้างข้อมูลหมวดหมู่ (Category)
|
||||||
|
*/
|
||||||
export interface Category {
|
export interface Category {
|
||||||
id: number
|
id: number
|
||||||
name: {
|
name: { // ชื่อหมวดหมู่รองรับ 2 ภาษา
|
||||||
th: string
|
th: string
|
||||||
en: string
|
en: string
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
slug: string
|
slug: string // Slug สำหรับใช้งานบน URL
|
||||||
description: {
|
description: { // รายละเอียดหมวดหมู่
|
||||||
th: string
|
th: string
|
||||||
en: string
|
en: string
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
icon: string
|
icon: string // ไอคอนของหมวดหมู่อ้างอิงจาก Material Icons
|
||||||
sort_order: number
|
sort_order: number
|
||||||
is_active: boolean
|
is_active: boolean
|
||||||
created_at: string
|
created_at: string
|
||||||
|
|
@ -20,7 +23,7 @@ export interface Category {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CategoryData {
|
export interface CategoryData {
|
||||||
total: number
|
total: number // จำนวนหมวดหมู่ทั้งหมด
|
||||||
categories: Category[]
|
categories: Category[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,18 +33,24 @@ interface CategoryResponse {
|
||||||
data: CategoryData
|
data: CategoryData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Composable สำหรับจัดการข้อมูลหมวดหมู่
|
/**
|
||||||
|
* @composable useCategory
|
||||||
|
* @description จัดการข้อมูลหมวดหมู่ (Categories) การดึงข้อมูล และการจัดการ Cache (เก็บข้อมูลจำลองชั่วคราว)
|
||||||
|
*/
|
||||||
export const useCategory = () => {
|
export const useCategory = () => {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBase as string
|
const API_BASE_URL = config.public.apiBase as string
|
||||||
const { token } = useAuth()
|
const { token } = useAuth()
|
||||||
|
|
||||||
// ใช้ useState เพื่อเก็บ Cached Data ระดับ Global (แชร์กันทุก Component)
|
// เก็บ Cache การดึงข้อมูลหมวดหมู่ในระดับ Global (ใช้ข้าม Component ได้โดยไม่ต้องโหลดใหม่)
|
||||||
const categoriesState = useState<Category[]>('categories_cache', () => [])
|
const categoriesState = useState<Category[]>('categories_cache', () => [])
|
||||||
const isLoaded = useState<boolean>('categories_loaded', () => false)
|
const isLoaded = useState<boolean>('categories_loaded', () => false)
|
||||||
|
|
||||||
// ฟังก์ชันดึงข้อมูลหมวดหมู่ทั้งหมด
|
/**
|
||||||
// Endpoint: GET /categories
|
* @function fetchCategories
|
||||||
|
* @description ดึงรายการหมวดหมู่ทั้งหมดจาก API (GET /categories)
|
||||||
|
* หากมีแคชอยู่แล้วจะดึงจาก State ทันที แต่อาจบังคับให้โหลดใหม่ (forceRefresh) ได้
|
||||||
|
*/
|
||||||
const fetchCategories = async (forceRefresh = false) => {
|
const fetchCategories = async (forceRefresh = false) => {
|
||||||
// ถ้ามีข้อมูลอยู่แล้วและไม่สั่งบังคับโหลดใหม่ ให้ใช้ข้อมูลเดิมทันที
|
// ถ้ามีข้อมูลอยู่แล้วและไม่สั่งบังคับโหลดใหม่ ให้ใช้ข้อมูลเดิมทันที
|
||||||
if (isLoaded.value && !forceRefresh && categoriesState.value.length > 0) {
|
if (isLoaded.value && !forceRefresh && categoriesState.value.length > 0) {
|
||||||
|
|
@ -62,7 +71,7 @@ export const useCategory = () => {
|
||||||
|
|
||||||
const categories = response.data?.categories || []
|
const categories = response.data?.categories || []
|
||||||
|
|
||||||
// เก็บข้อมูลลง State
|
// บันทึกรายการหมวดหมู่ลง State Cache
|
||||||
categoriesState.value = categories
|
categoriesState.value = categories
|
||||||
isLoaded.value = true
|
isLoaded.value = true
|
||||||
|
|
||||||
|
|
@ -74,9 +83,9 @@ export const useCategory = () => {
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Fetch categories failed:', err)
|
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) {
|
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 {
|
try {
|
||||||
const retryRes = await $fetch<CategoryResponse>(`${API_BASE_URL}/categories`, {
|
const retryRes = await $fetch<CategoryResponse>(`${API_BASE_URL}/categories`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
|
||||||
|
|
@ -1,125 +1,14 @@
|
||||||
// Interface สำหรับข้อมูลคอร์สเรียน (Public Course Data)
|
import type {
|
||||||
export interface Course {
|
Course,
|
||||||
id: number
|
CourseResponse,
|
||||||
title: string | { th: string; en: string } // รองรับ 2 ภาษา
|
SingleCourseResponse,
|
||||||
slug: string
|
EnrolledCourse,
|
||||||
description: string | { th: string; en: string }
|
EnrolledCourseResponse,
|
||||||
thumbnail_url: string
|
QuizAnswerSubmission,
|
||||||
price: string
|
QuizSubmitRequest,
|
||||||
is_free: boolean
|
QuizResult,
|
||||||
original_price?: string
|
Certificate
|
||||||
have_certificate: boolean
|
} from '@/types/course'
|
||||||
status: string // DRAFT, PUBLISHED
|
|
||||||
category_id: number
|
|
||||||
created_at?: string
|
|
||||||
updated_at?: string
|
|
||||||
created_by?: number
|
|
||||||
updated_by?: number
|
|
||||||
approved_at?: string
|
|
||||||
approved_by?: number
|
|
||||||
rejection_reason?: string
|
|
||||||
enrolled?: boolean
|
|
||||||
total_lessons?: number
|
|
||||||
|
|
||||||
|
|
||||||
rating?: string
|
|
||||||
lessons?: number | string
|
|
||||||
levelType?: 'neutral' | 'warning' | 'success' // ใช้สำหรับการแสดงผล Badge ระดับความยาก (Frontend Logic)
|
|
||||||
|
|
||||||
// โครงสร้างบทเรียน (Chapters & Lessons)
|
|
||||||
chapters?: {
|
|
||||||
id: number
|
|
||||||
title: string | { th: string; en: string }
|
|
||||||
lessons: {
|
|
||||||
id: number
|
|
||||||
title: string | { th: string; en: string }
|
|
||||||
duration_minutes: number
|
|
||||||
video_url?: string
|
|
||||||
}[]
|
|
||||||
}[]
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CourseResponse {
|
|
||||||
code: number
|
|
||||||
message: string
|
|
||||||
data: Course[]
|
|
||||||
total: number
|
|
||||||
page?: number
|
|
||||||
limit?: number
|
|
||||||
totalPages?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SingleCourseResponse {
|
|
||||||
code: number
|
|
||||||
message: string
|
|
||||||
data: Course
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interface สำหรับคอร์สที่ผู้ใช้ลงทะเบียนเรียนแล้ว (My Course)
|
|
||||||
export interface EnrolledCourse {
|
|
||||||
id: number
|
|
||||||
course_id: number
|
|
||||||
course: Course
|
|
||||||
status: 'ENROLLED' | 'IN_PROGRESS' | 'COMPLETED' | 'DROPPED'
|
|
||||||
progress_percentage: number
|
|
||||||
enrolled_at: string
|
|
||||||
started_at?: string
|
|
||||||
completed_at?: string
|
|
||||||
last_accessed_at?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface EnrolledCourseResponse {
|
|
||||||
code: number
|
|
||||||
message: string
|
|
||||||
data: EnrolledCourse[]
|
|
||||||
total: number
|
|
||||||
page: number
|
|
||||||
limit: number
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interface สำหรับการส่งคำตอบแบบทดสอบ (Quiz Submission)
|
|
||||||
export interface QuizAnswerSubmission {
|
|
||||||
question_id: number
|
|
||||||
choice_id: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface QuizSubmitRequest {
|
|
||||||
answers: QuizAnswerSubmission[]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interface สำหรับผลลัพธ์การสอบ (Quiz Result)
|
|
||||||
export interface QuizResult {
|
|
||||||
answers_review: {
|
|
||||||
score: number
|
|
||||||
is_correct: boolean
|
|
||||||
correct_choice_id: number
|
|
||||||
selected_choice_id: number
|
|
||||||
question_id: number
|
|
||||||
}[]
|
|
||||||
completed_at: string
|
|
||||||
started_at: string
|
|
||||||
attempt_number: number
|
|
||||||
passing_score: number
|
|
||||||
is_passed: boolean
|
|
||||||
correct_answers: number
|
|
||||||
total_questions: number
|
|
||||||
total_score: number
|
|
||||||
score: number
|
|
||||||
quiz_id: number
|
|
||||||
attempt_id: number
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interface สำหรับ Certificate
|
|
||||||
export interface Certificate {
|
|
||||||
certificate_id: number
|
|
||||||
course_id: number
|
|
||||||
course_title: {
|
|
||||||
en: string
|
|
||||||
th: string
|
|
||||||
}
|
|
||||||
issued_at: string
|
|
||||||
download_url: string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// Composable: useCourse
|
// Composable: useCourse
|
||||||
|
|
@ -145,6 +34,7 @@ export const useCourse = () => {
|
||||||
category_id?: number;
|
category_id?: number;
|
||||||
page?: number;
|
page?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
|
search?: string;
|
||||||
random?: boolean;
|
random?: boolean;
|
||||||
is_recommended?: boolean;
|
is_recommended?: boolean;
|
||||||
forceRefresh?: boolean
|
forceRefresh?: boolean
|
||||||
|
|
@ -167,6 +57,7 @@ export const useCourse = () => {
|
||||||
if (apiParams.category_id) queryParams.append('category_id', apiParams.category_id.toString())
|
if (apiParams.category_id) queryParams.append('category_id', apiParams.category_id.toString())
|
||||||
if (apiParams.page) queryParams.append('page', apiParams.page.toString())
|
if (apiParams.page) queryParams.append('page', apiParams.page.toString())
|
||||||
if (apiParams.limit) queryParams.append('limit', apiParams.limit.toString())
|
if (apiParams.limit) queryParams.append('limit', apiParams.limit.toString())
|
||||||
|
if (apiParams.search) queryParams.append('search', apiParams.search)
|
||||||
if (apiParams.random !== undefined) queryParams.append('random', apiParams.random.toString())
|
if (apiParams.random !== undefined) queryParams.append('random', apiParams.random.toString())
|
||||||
if (apiParams.is_recommended !== undefined) queryParams.append('is_recommended', apiParams.is_recommended.toString())
|
if (apiParams.is_recommended !== undefined) queryParams.append('is_recommended', apiParams.is_recommended.toString())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
/**
|
||||||
|
* @interface ValidationRule
|
||||||
|
* @description กฎการตรวจสอบความถูกต้องของฟิลด์ (เช่น บังคับกรอก, เช็คความยาว, ตรวจอีเมล)
|
||||||
|
*/
|
||||||
export interface ValidationRule {
|
export interface ValidationRule {
|
||||||
required?: boolean
|
required?: boolean
|
||||||
minLength?: number
|
minLength?: number
|
||||||
|
|
@ -8,10 +12,18 @@ export interface ValidationRule {
|
||||||
custom?: (value: string) => string | null
|
custom?: (value: string) => string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @interface FieldErrors
|
||||||
|
* @description รูปแบบการเก็บข้อผิดพลาด (Key ของฟิลด์ คู่กับข้อความแจ้งเตือน)
|
||||||
|
*/
|
||||||
export interface FieldErrors {
|
export interface FieldErrors {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @composable useFormValidation
|
||||||
|
* @description ใช้สำหรับตรวจสอบความถูกต้อง (Validate) ของข้อมูลในแบบฟอร์ม
|
||||||
|
*/
|
||||||
export function useFormValidation() {
|
export function useFormValidation() {
|
||||||
const errors = ref<FieldErrors>({})
|
const errors = ref<FieldErrors>({})
|
||||||
|
|
||||||
|
|
@ -52,6 +64,7 @@ export function useFormValidation() {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ฟังก์ชันหลักที่เอาแบบฟอร์ม (formData) มาตรวจกับเช็คลิสต์ทั้งหมด (validationRules)
|
||||||
const validate = (
|
const validate = (
|
||||||
formData: Record<string, string>,
|
formData: Record<string, string>,
|
||||||
validationRules: Record<string, { rules: ValidationRule; label: string; messages?: 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
|
errors.value = newErrors
|
||||||
|
// คืนค่าบอกว่า "ฟอร์มนี้ผ่านทั้งหมดไหม" (true คือผ่านหมด)
|
||||||
return isValid
|
return isValid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ฟังก์ชันลบข้อผิดพลาดทิ้งทั้งหมด (สำหรับตอนเริ่มกรอกใหม่)
|
||||||
const clearErrors = () => {
|
const clearErrors = () => {
|
||||||
errors.value = {}
|
errors.value = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ฟังก์ชันลบข้อผิดพลาดเฉพาะฟิลด์ที่กำหนด
|
||||||
const clearFieldError = (field: string) => {
|
const clearFieldError = (field: string) => {
|
||||||
if (errors.value[field]) {
|
if (errors.value[field]) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,27 @@
|
||||||
|
/**
|
||||||
|
* @composable useMediaPrefs
|
||||||
|
* @description จัดการตั้งค่าระดับเสียงและสถานะปิดเสียง (Mute) ของวิดีโอ/สื่อ
|
||||||
|
* โดยจะเก็บค่าแยกตามบัญชีผู้ใช้งาน และสั่งประยุกต์ใช้กับ <video> ให้อัตโนมัติ
|
||||||
|
*/
|
||||||
export const useMediaPrefs = () => {
|
export const useMediaPrefs = () => {
|
||||||
// 1. Global State
|
// 1. สถานะส่วนกลาง (Global State)
|
||||||
// ใช้ useState เพื่อแชร์ค่าเดียวกันทั่วทั้ง App (เช่น เปลี่ยนหน้าแล้วเสียงยังเท่าเดิม)
|
// ใช้ useState เพื่อแชร์ค่าเดียวกันทั่วหน้าเว็บ (เช่น เปลี่ยนหน้าแล้วระดับเสียงยังคงที่)
|
||||||
const volume = useState<number>('media_prefs_volume', () => 1)
|
const volume = useState<number>('media_prefs_volume', () => 1)
|
||||||
const muted = useState<boolean>('media_prefs_muted', () => false)
|
const muted = useState<boolean>('media_prefs_muted', () => false)
|
||||||
|
|
||||||
const { user } = useAuth()
|
const { user } = useAuth()
|
||||||
|
|
||||||
// 2. Storage Key Helper (User Specific)
|
// 2. ฟังก์ชันช่วยสร้าง Key สำหรับ Storage (เก็บแยกตาม User)
|
||||||
const getStorageKey = () => {
|
const getStorageKey = () => {
|
||||||
const userId = user.value?.id || 'guest'
|
const userId = user.value?.id || 'guest'
|
||||||
return `media:prefs:v1:${userId}`
|
return `media:prefs:v1:${userId}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Save Logic (Throttled)
|
// 3. ระบบบันทึกการตั้งค่าลงเบราว์เซอร์ (Throttled เพื่อไม่ให้บันทึกถี่เกินไป)
|
||||||
let saveTimeout: ReturnType<typeof setTimeout> | null = null
|
let saveTimeout: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
if (import.meta.server) return
|
if (import.meta.server) return // เลี่ยงไม่ได้ต้องทำงานบนฝั่ง Client เท่านั้น
|
||||||
|
|
||||||
if (saveTimeout) clearTimeout(saveTimeout)
|
if (saveTimeout) clearTimeout(saveTimeout)
|
||||||
saveTimeout = setTimeout(() => {
|
saveTimeout = setTimeout(() => {
|
||||||
|
|
@ -29,12 +34,12 @@ export const useMediaPrefs = () => {
|
||||||
}
|
}
|
||||||
localStorage.setItem(key, JSON.stringify(data))
|
localStorage.setItem(key, JSON.stringify(data))
|
||||||
} catch (e) {
|
} 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 = () => {
|
const load = () => {
|
||||||
if (import.meta.server) return
|
if (import.meta.server) return
|
||||||
|
|
||||||
|
|
@ -51,20 +56,20 @@ export const useMediaPrefs = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to load media prefs', e)
|
console.error('ไม่สามารถโหลดการตั้งค่าสื่อได้', e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Setters (With Logic)
|
// 5. ฟังก์ชันสำหรับอัปเดตและสั่งบันทึกการตั้งค่า (Setters)
|
||||||
const setVolume = (val: number) => {
|
const setVolume = (val: number) => {
|
||||||
const clamped = Math.max(0, Math.min(1, val))
|
const clamped = Math.max(0, Math.min(1, val))
|
||||||
volume.value = clamped
|
volume.value = clamped
|
||||||
|
|
||||||
// Auto unmute if volume increased from 0
|
// ยกเลิกปิดเสียงอัตโนมัติ ถ้าระดับเสียงเพิ่มขึ้นจาก 0
|
||||||
if (clamped > 0 && muted.value) {
|
if (clamped > 0 && muted.value) {
|
||||||
muted.value = false
|
muted.value = false
|
||||||
}
|
}
|
||||||
// Auto mute if volume set to 0
|
// ปิดเสียงอัตโนมัติ ถ้าระดับเสียงกลายเป็น 0
|
||||||
if (clamped === 0 && !muted.value) {
|
if (clamped === 0 && !muted.value) {
|
||||||
muted.value = true
|
muted.value = true
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +80,7 @@ export const useMediaPrefs = () => {
|
||||||
const setMuted = (val: boolean) => {
|
const setMuted = (val: boolean) => {
|
||||||
muted.value = val
|
muted.value = val
|
||||||
|
|
||||||
// Logic: Unmuting should restore volume if it was 0
|
// หากผู้ใช้กดยกเลิกการปิดเสียงขณะที่ระดับเสียงเคยเป็น 0 ควรตั้งค่าเริ่มต้นให้เป็น 1
|
||||||
if (!val && volume.value === 0) {
|
if (!val && volume.value === 0) {
|
||||||
volume.value = 1
|
volume.value = 1
|
||||||
}
|
}
|
||||||
|
|
@ -83,15 +88,15 @@ export const useMediaPrefs = () => {
|
||||||
save()
|
save()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Apply & Bind to Element (The Magic)
|
// 6. ฟังก์ชันจับคู่ใช้กับการเล่นสื่อ (ตย. <video ref="videoEl"> -> applyTo(videoEl.value))
|
||||||
const applyTo = (el: HTMLMediaElement | null | undefined) => {
|
const applyTo = (el: HTMLMediaElement | null | undefined) => {
|
||||||
if (!el) return () => {}
|
if (!el) return () => {}
|
||||||
|
|
||||||
// Initial Apply
|
// ใส่ค่าตั้งต้นให้กับออบเจ็กต์สื่อ
|
||||||
el.volume = volume.value
|
el.volume = volume.value
|
||||||
el.muted = muted.value
|
el.muted = muted.value
|
||||||
|
|
||||||
// A. Watch State -> Update Element
|
// A. สังเกตการเปลี่ยนแปลงจาก State -> เพื่อส่งไปอัปเดต Element สื่อ
|
||||||
const stopVolWatch = watch(volume, (v) => {
|
const stopVolWatch = watch(volume, (v) => {
|
||||||
if (Math.abs(el.volume - v) > 0.01) el.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
|
if (el.muted !== m) el.muted = m
|
||||||
})
|
})
|
||||||
|
|
||||||
// B. Listen Element -> Update State (e.g. Native Controls)
|
// B. สังเกตการเปลี่ยนแปลงจาก Element (เช่น ผู้ใช้กดปุ่มเร่งเสียงในวิดีโอตรงๆ) -> เพื่อเอาค่ามาอัปเดต State
|
||||||
const onVolumeChange = () => {
|
const onVolumeChange = () => {
|
||||||
// Update state only if diff allows (prevent loop)
|
// อัปเดตเฉพาะเมื่อมีความแตกต่างเพื่อหลีกเลี่ยง Loop อนันต์
|
||||||
if (Math.abs(el.volume - volume.value) > 0.01) {
|
if (Math.abs(el.volume - volume.value) > 0.01) {
|
||||||
volume.value = el.volume
|
volume.value = el.volume
|
||||||
save()
|
save()
|
||||||
|
|
@ -113,7 +118,7 @@ export const useMediaPrefs = () => {
|
||||||
}
|
}
|
||||||
el.addEventListener('volumechange', onVolumeChange)
|
el.addEventListener('volumechange', onVolumeChange)
|
||||||
|
|
||||||
// Cleanup function
|
// ฟังก์ชันล้างค่าเพื่อเลิกติดตาม (Cleanup แบบส่งกลับ (Return))
|
||||||
return () => {
|
return () => {
|
||||||
stopVolWatch()
|
stopVolWatch()
|
||||||
stopMutedWatch()
|
stopMutedWatch()
|
||||||
|
|
@ -121,11 +126,11 @@ export const useMediaPrefs = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Lifecycle & Sync
|
// 7. จังหวะวงจรชีวิตตอนโหลดเสร็จและระบบ Sync
|
||||||
if (import.meta.client) {
|
if (import.meta.client) {
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
load()
|
load()
|
||||||
// Cross-tab sync
|
// ระบบ Sync กับแท็บหรือหน้าต่างเดียวกันหากถูกเปิดไว้
|
||||||
window.addEventListener('storage', (e) => {
|
window.addEventListener('storage', (e) => {
|
||||||
if (e.key === getStorageKey()) {
|
if (e.key === getStorageKey()) {
|
||||||
load()
|
load()
|
||||||
|
|
|
||||||
79
Frontend-Learner/composables/useNavItems.ts
Normal file
79
Frontend-Learner/composables/useNavItems.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
/**
|
||||||
|
* @file useNavItems.ts
|
||||||
|
* @description ศูนย์รวมจัดการเมนูนำทาง (Navigation Items) เพื่อให้ใช้ข้อมูลชุดเดียวกันทั้งเว็บ
|
||||||
|
* (เช่น เมนูด้านข้าง, เมนูบนมือถือ, และเมนูโปรไฟล์ผู้ใช้)
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface NavItem {
|
||||||
|
to: string // ลิงก์ปลายทาง
|
||||||
|
labelKey: string // คีย์ภาษาสำหรับ i18n
|
||||||
|
icon: string // ไอคอนจาก Material Icons
|
||||||
|
showOn: ('sidebar' | 'mobile' | 'userMenu')[] // กำหนดให้โชว์ที่ส่วนไหนบ้าง
|
||||||
|
roles?: string[] // กำหนดสิทธิ์ผู้ใช้ที่จะเห็น (ถ้ามี)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useNavItems = () => {
|
||||||
|
// เมนูทั้งหมดในระบบ กำหนดไว้ที่เดียว
|
||||||
|
const allNavItems: NavItem[] = [
|
||||||
|
{
|
||||||
|
to: '/dashboard',
|
||||||
|
labelKey: 'sidebar.overview',
|
||||||
|
icon: 'dashboard',
|
||||||
|
showOn: ['sidebar', 'mobile', 'userMenu']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
to: '/browse',
|
||||||
|
labelKey: 'sidebar.onlineCourses',
|
||||||
|
icon: 'video_library',
|
||||||
|
showOn: ['mobile']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
to: '/browse/discovery',
|
||||||
|
labelKey: 'sidebar.recommendedCourses',
|
||||||
|
icon: 'auto_awesome',
|
||||||
|
showOn: ['mobile']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
to: '/browse/discovery',
|
||||||
|
labelKey: 'sidebar.browseCourses',
|
||||||
|
icon: 'explore',
|
||||||
|
showOn: ['sidebar', 'mobile', 'userMenu']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
to: '/dashboard/my-courses',
|
||||||
|
labelKey: 'sidebar.myCourses',
|
||||||
|
icon: 'school',
|
||||||
|
showOn: ['sidebar', 'mobile', 'userMenu']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
to: '/dashboard/announcements',
|
||||||
|
labelKey: 'sidebar.announcements',
|
||||||
|
icon: 'campaign',
|
||||||
|
showOn: ['mobile']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
to: '/dashboard/profile',
|
||||||
|
labelKey: 'sidebar.profile',
|
||||||
|
icon: 'person',
|
||||||
|
showOn: [] // Was ['sidebar']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
to: '/dashboard/profile',
|
||||||
|
labelKey: 'userMenu.settings',
|
||||||
|
icon: 'settings',
|
||||||
|
showOn: ['userMenu']
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
// คัดกรองเมนูที่จะเอาไปแสดงแต่ละตำแหน่ง
|
||||||
|
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')))
|
||||||
|
|
||||||
|
return {
|
||||||
|
allNavItems,
|
||||||
|
sidebarItems,
|
||||||
|
mobileItems,
|
||||||
|
userMenuItems
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,95 +19,107 @@ export interface AnswerState {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @composable useQuizRunner
|
* @composable useQuizRunner
|
||||||
* @description Manages the state and logic for running a quiz activity.
|
* @description จัดการ State (สถานะ) และ Logic สำหรับการทำแบบทดสอบ (Quiz)
|
||||||
|
* ครอบคลุมการแสดงคำถาม, บันทึกคำตอบ, และตรวจสอบการข้ามคำถาม
|
||||||
*/
|
*/
|
||||||
export const useQuizRunner = () => {
|
export const useQuizRunner = () => {
|
||||||
// State
|
// ================= State (สถานะเก็บค่าต่างๆ ของข้อสอบ) =================
|
||||||
const questions = useState<QuizQuestion[]>('quiz-questions', () => []);
|
const questions = useState<QuizQuestion[]>('quiz-questions', () => []); // เก็บรายการคำถามทั้งหมด
|
||||||
const answers = useState<Record<number, AnswerState>>('quiz-answers', () => ({}));
|
const answers = useState<Record<number, AnswerState>>('quiz-answers', () => ({})); // เก็บคำตอบที่ผู้ใช้ตอบ แยกตาม ID คำถาม
|
||||||
const currentQuestionIndex = useState<number>('quiz-current-index', () => 0);
|
const currentQuestionIndex = useState<number>('quiz-current-index', () => 0); // ลำดับคำถามที่กำลังทำอยู่ปัจจุบัน (เริ่มที่ 0)
|
||||||
const loading = useState<boolean>('quiz-loading', () => false);
|
const loading = useState<boolean>('quiz-loading', () => false); // สถานะตอนกำลังกดเซฟหรือโหลดข้อมูล
|
||||||
const lastError = useState<string | null>('quiz-error', () => null);
|
const lastError = useState<string | null>('quiz-error', () => null); // เก็บข้อความแจ้งเตือนข้อผิดพลาดล่าสุด
|
||||||
|
|
||||||
// Getters
|
// ================= Getters (ดึงค่าที่ถูกประมวลผลแล้ว) =================
|
||||||
const currentQuestion = computed(() => questions.value[currentQuestionIndex.value]);
|
const currentQuestion = computed(() => questions.value[currentQuestionIndex.value]); // ดึงคำถามข้อปัจจุบัน
|
||||||
|
|
||||||
const currentAnswer = computed(() => {
|
const currentAnswer = computed(() => { // ดึงคำตอบในข้อปัจจุบัน
|
||||||
if (!currentQuestion.value) return null;
|
if (!currentQuestion.value) return null;
|
||||||
return answers.value[currentQuestion.value.id];
|
return answers.value[currentQuestion.value.id];
|
||||||
});
|
});
|
||||||
|
|
||||||
const totalQuestions = computed(() => questions.value.length);
|
const totalQuestions = computed(() => questions.value.length); // จำนวนคำถามทั้งหมดในแบบทดสอบ
|
||||||
const isLastQuestion = computed(() => currentQuestionIndex.value === questions.value.length - 1);
|
const isLastQuestion = computed(() => currentQuestionIndex.value === questions.value.length - 1); // เช็คว่าใช่คำถามข้อสุดท้ายหรือไม่
|
||||||
const isFirstQuestion = computed(() => currentQuestionIndex.value === 0);
|
const isFirstQuestion = computed(() => currentQuestionIndex.value === 0); // เช็คว่าใช่คำถามข้อแรกหรือไม่
|
||||||
|
|
||||||
// Actions
|
// ================= Actions (ฟังก์ชันหลักสำหรับการทำงาน) =================
|
||||||
|
|
||||||
|
// ฟังก์ชันเริ่มต้นสร้าง/โหลดข้อสอบ (กำหนดโครงสร้างพื้นฐาน)
|
||||||
function initQuiz(quizData: any) {
|
function initQuiz(quizData: any) {
|
||||||
if (!quizData || !quizData.questions) return;
|
if (!quizData || !quizData.questions) return;
|
||||||
|
|
||||||
questions.value = quizData.questions;
|
questions.value = quizData.questions;
|
||||||
currentQuestionIndex.value = 0;
|
currentQuestionIndex.value = 0; // รีเซ็ตไปที่ข้อ 1 ใหม่
|
||||||
answers.value = {};
|
answers.value = {};
|
||||||
lastError.value = null;
|
lastError.value = null;
|
||||||
|
|
||||||
|
// เตรียมโครงสร้างคำตอบรองรับทุกข้อ
|
||||||
questions.value.forEach(q => {
|
questions.value.forEach(q => {
|
||||||
answers.value[q.id] = {
|
answers.value[q.id] = {
|
||||||
questionId: q.id,
|
questionId: q.id,
|
||||||
value: null,
|
value: null,
|
||||||
is_saved: false,
|
is_saved: false, // บันทึกและส่ง API เรียบร้อยหรือยัง
|
||||||
status: 'not_started',
|
status: 'not_started', // สถานะเริ่มต้นของคำถาม
|
||||||
touched: false,
|
touched: false, // ผู้ใช้เคยเปิดเข้ามาดูข้อนีัหรือยัง
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// เริ่มต้นบันทึกเวลา/เข้าสู่ข้อที่ 1 ทันทีเมื่ออธิบายเสร็จ
|
||||||
if (questions.value.length > 0) {
|
if (questions.value.length > 0) {
|
||||||
enterQuestion(questions.value[0].id);
|
enterQuestion(questions.value[0].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ฟังก์ชันสลับสถานะเมื่อกดเข้ามาที่คำถามนั้นๆ
|
||||||
function enterQuestion(qId: number) {
|
function enterQuestion(qId: number) {
|
||||||
const ans = answers.value[qId];
|
const ans = answers.value[qId];
|
||||||
if (ans) {
|
if (ans) {
|
||||||
ans.touched = true;
|
ans.touched = true;
|
||||||
if (ans.status === 'not_started' || ans.status === 'skipped') {
|
if (ans.status === 'not_started' || ans.status === 'skipped') {
|
||||||
ans.status = 'in_progress';
|
ans.status = 'in_progress'; // เปลี่ยนสถานะเป็น 'กำลังทำ'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ตรวจสอบเงื่อนไขว่าผู้ใช้สามารถออกจากคำถามปัจจุบันไปยังข้ออื่นได้หรือไม่
|
||||||
function canLeaveCurrent(): { allowed: boolean; reason?: string } {
|
function canLeaveCurrent(): { allowed: boolean; reason?: string } {
|
||||||
if (!currentQuestion.value) return { allowed: true };
|
if (!currentQuestion.value) return { allowed: true };
|
||||||
const q = currentQuestion.value;
|
const q = currentQuestion.value;
|
||||||
const a = answers.value[q.id];
|
const a = answers.value[q.id];
|
||||||
|
|
||||||
|
// สามารถออกได้ถ้าคำถามทำถูกหรือโจทย์อนุญาตให้ข้ามได้
|
||||||
if (a.status === 'completed' || a.is_saved) return { allowed: true };
|
if (a.status === 'completed' || a.is_saved) return { allowed: true };
|
||||||
if (q.is_skippable) return { allowed: true };
|
if (q.is_skippable) return { allowed: true };
|
||||||
|
|
||||||
|
// บังคับให้ตอบถ้าไม่ได้อนุญาตให้ข้าม และไม่ได้ตอบ
|
||||||
if (!a.is_saved && a.value === null) {
|
if (!a.is_saved && a.value === null) {
|
||||||
return { allowed: false, reason: 'This question is required.' };
|
return { allowed: false, reason: 'ต้องการคำตอบสำหรับข้อบังคับนี้' };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { allowed: true };
|
return { allowed: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ฟังก์ชันอัปเดตค่าตัวเลือกที่ผู้ใช้กดเลือกในข้อปัจจุบัน
|
||||||
function updateAnswer(val: any) {
|
function updateAnswer(val: any) {
|
||||||
if (!currentQuestion.value) return;
|
if (!currentQuestion.value) return;
|
||||||
const qId = currentQuestion.value.id;
|
const qId = currentQuestion.value.id;
|
||||||
answers.value[qId].value = val;
|
answers.value[qId].value = val;
|
||||||
|
|
||||||
|
// หากมีแก้ไขคำตอบหลังจากกดเซฟไปแล้ว ให้เปลี่ยนสถานะให้ระบบรู้ว่าต้องเซฟใหม่
|
||||||
if (answers.value[qId].is_saved) {
|
if (answers.value[qId].is_saved) {
|
||||||
answers.value[qId].is_saved = false;
|
answers.value[qId].is_saved = false;
|
||||||
answers.value[qId].status = 'in_progress';
|
answers.value[qId].status = 'in_progress';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ล็อกและบันทึกข้อสอบเมื่อกดปุ่ม "ตกลง/ส่งคำตอบ" สำหรับข้อนั้นๆ
|
||||||
async function saveCurrentAnswer() {
|
async function saveCurrentAnswer() {
|
||||||
if (!currentQuestion.value) return;
|
if (!currentQuestion.value) return;
|
||||||
const qId = currentQuestion.value.id;
|
const qId = currentQuestion.value.id;
|
||||||
const ans = answers.value[qId];
|
const ans = answers.value[qId];
|
||||||
|
|
||||||
if (ans.value === null) {
|
if (ans.value === null) {
|
||||||
lastError.value = "Please provide an answer.";
|
lastError.value = "กรุณาเลือกคำตอบอย่างน้อย 1 ตัวเลือก";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,30 +127,34 @@ export const useQuizRunner = () => {
|
||||||
lastError.value = null;
|
lastError.value = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// หมายเหตุ: การเชื่อมต่อ API หลักต้องทำที่ไฟล์ component, ตัวนี้จัดการแค่เรื่อง State
|
||||||
ans.is_saved = true;
|
ans.is_saved = true;
|
||||||
ans.status = 'completed';
|
ans.status = 'completed'; // มาร์คว่าเป็นข้อที่ทำเสร็จแล้ว
|
||||||
ans.last_saved_at = new Date().toISOString();
|
ans.last_saved_at = new Date().toISOString();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
lastError.value = "Failed to save answer.";
|
lastError.value = "เกิดข้อผิดพลาดในการบันทึกคำตอบ";
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// วินิจฉัยก่อนสั่งผู้ใช้ย้ายไปยังคำถามอื่นหน้าอื่นตามดัชนีระบุ
|
||||||
function handleLeaveLogic(targetIndex: number) {
|
function handleLeaveLogic(targetIndex: number) {
|
||||||
if (targetIndex === currentQuestionIndex.value) return;
|
if (targetIndex === currentQuestionIndex.value) return;
|
||||||
|
|
||||||
|
// ตรวจสอบขั้นสุดท้าย ป้องกันคนคลิกแอบหนีข้อที่บังคับทำ
|
||||||
const check = canLeaveCurrent();
|
const check = canLeaveCurrent();
|
||||||
if (!check.allowed) {
|
if (!check.allowed) {
|
||||||
lastError.value = check.reason || "Required question.";
|
lastError.value = check.reason || "จำเป็นต้องตอบข้อนี้ก่อนข้าม";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currQ = currentQuestion.value;
|
const currQ = currentQuestion.value;
|
||||||
if (currQ) {
|
if (currQ) {
|
||||||
const currAns = answers.value[currQ.id];
|
const currAns = answers.value[currQ.id];
|
||||||
|
// หากผู้ใช้ทิ้งขว้างโดยที่ไม่บังคับ ให้ทิ้งสถานะเป็นข้าม ('skipped')
|
||||||
if (currAns.status !== 'completed' && !currAns.is_saved) {
|
if (currAns.status !== 'completed' && !currAns.is_saved) {
|
||||||
currAns.status = 'skipped';
|
currAns.status = 'skipped';
|
||||||
}
|
}
|
||||||
|
|
@ -147,6 +163,7 @@ export const useQuizRunner = () => {
|
||||||
currentQuestionIndex.value = targetIndex;
|
currentQuestionIndex.value = targetIndex;
|
||||||
lastError.value = null;
|
lastError.value = null;
|
||||||
|
|
||||||
|
// ติดตามสถานะ 'touched' ในข้อใหม่ที่เข้าไปล่าสุด
|
||||||
if (questions.value[targetIndex]) {
|
if (questions.value[targetIndex]) {
|
||||||
enterQuestion(questions.value[targetIndex].id);
|
enterQuestion(questions.value[targetIndex].id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,41 @@
|
||||||
import { useQuasar } from 'quasar'
|
import { useQuasar } from 'quasar'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @composable useThemeMode
|
||||||
|
* @description จัดการระบบโหมดสว่าง/มืด (Light/Dark Theme) ของแพลตฟอร์ม
|
||||||
|
* ครอบคลุมการสั่งบันทึกการตั้งค่า, เปลี่ยนคลาส Tailwind และ Sync ซิงก์กับ Quasar UI
|
||||||
|
*/
|
||||||
export const useThemeMode = () => {
|
export const useThemeMode = () => {
|
||||||
const $q = useQuasar()
|
const $q = useQuasar()
|
||||||
|
|
||||||
// deterministic on SSR: default = light
|
// สถานะเริ่มต้นของโหมดมืด (สำหรับการทำ SSR ถูกเซ็ตเป็น false (สว่าง) ไว้ก่อน)
|
||||||
const isDark = useState<boolean>('theme:isDark', () => false)
|
const isDark = useState<boolean>('theme:isDark', () => false)
|
||||||
|
|
||||||
|
// ฟังก์ชันใช้คลาสกับ Tag <html> เพื่อให้ Tailwind หรือ CSS รันโหมดมืด
|
||||||
const applyTheme = (value: boolean) => {
|
const applyTheme = (value: boolean) => {
|
||||||
if (!process.client) return
|
if (!process.client) return // หากทำงานฝั่งเซิร์ฟเวอร์ จะไม่สั่งให้รัน DOM
|
||||||
|
|
||||||
|
// สลับคลาส 'dark' หรือปิด
|
||||||
document.documentElement.classList.toggle('dark', value)
|
document.documentElement.classList.toggle('dark', value)
|
||||||
|
|
||||||
|
// สั่งให้ Quasar (UI Framework) ปรับโหมดสีให้ตรงกัน (มืด/สว่าง)
|
||||||
$q.dark.set(value)
|
$q.dark.set(value)
|
||||||
|
|
||||||
|
// บันทึกการตั้งค่าลงเครื่องระยะยาวเบราว์เซอร์
|
||||||
localStorage.setItem('theme', value ? 'dark' : 'light')
|
localStorage.setItem('theme', value ? 'dark' : 'light')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// จับตาดูเมื่อตัวแปรเปลี่ยนค่าค่อยทำการเปลี่ยนโหมดบนหน้าจอ
|
||||||
watch(isDark, (v) => applyTheme(v))
|
watch(isDark, (v) => applyTheme(v))
|
||||||
|
|
||||||
|
// ฟังก์ชันสั่งสลับโหมด ไปมา (Toggle)
|
||||||
const toggle = () => {
|
const toggle = () => {
|
||||||
isDark.value = !isDark.value
|
isDark.value = !isDark.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ฟังก์ชันสำหรับกำหนดตั้งค่าโหมดแบบเจาะจง
|
||||||
const set = (v: boolean) => {
|
const set = (v: boolean) => {
|
||||||
isDark.value = v
|
isDark.value = v
|
||||||
}
|
}
|
||||||
|
|
|
||||||
43
Frontend-Learner/constants/landing.ts
Normal file
43
Frontend-Learner/constants/landing.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* @file landing.ts
|
||||||
|
* @description ข้อมูลคงที่ (Static data) แบบจำลองที่เอาไว้แสดงผลบนหน้า Landing page
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const CATEGORY_CARDS = [
|
||||||
|
{
|
||||||
|
title: 'โปรแกรมมิ่ง',
|
||||||
|
desc: 'เชี่ยวชาญการเขียนโค้ดและพัฒนาซอฟต์แวร์',
|
||||||
|
icon: 'o_code',
|
||||||
|
slug: 'programming',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'การออกแบบ',
|
||||||
|
desc: 'ทักษะ UI/UX และการออกแบบระดับมือโปร',
|
||||||
|
icon: 'o_palette',
|
||||||
|
slug: 'design',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'ธุรกิจ',
|
||||||
|
desc: 'ทักษะการจัดการและความเป็นผู้นำสากล',
|
||||||
|
icon: 'o_business_center',
|
||||||
|
slug: 'business',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
export const WHY_CHOOSE_US = [
|
||||||
|
{
|
||||||
|
title: 'ผู้สอนเชี่ยวชาญ',
|
||||||
|
desc: 'เรียนรู้จากผู้นำในอุตสาหกรรมที่มีประสบการณ์การทำงานหลายปีในบริษัทเทคโนโลยีชั้นนำระดับโลก',
|
||||||
|
icon: 'o_groups',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'การเรียนรู้ที่ยืดหยุ่น',
|
||||||
|
desc: 'เรียนตามจังหวะของคุณเอง ได้ทุกที่ทุกเวลา เข้าถึงเนื้อหาคอร์สที่สมัครเรียนได้ตลอดชีพ',
|
||||||
|
icon: 'o_schedule',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'ประกาศนียบัตรเมื่อเรียนจบ',
|
||||||
|
desc: 'รับวุฒิบัตรที่เป็นที่ยอมรับเพื่อเสริมพอร์ตโฟลิโอระดับมืออาชีพของคุณและแชร์ลง LinkedIn ได้โดยตรง',
|
||||||
|
icon: 'o_verified',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -86,7 +86,7 @@ const handleError = () => {
|
||||||
background-color: var(--bg-body);
|
background-color: var(--bg-body);
|
||||||
color: var(--text-main);
|
color: var(--text-main);
|
||||||
padding: 24px;
|
padding: 24px;
|
||||||
font-family: 'Inter', 'Prompt', 'Sarabun', sans-serif;
|
font-family: var(--font-main);
|
||||||
}
|
}
|
||||||
|
|
||||||
.error-content {
|
.error-content {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,27 @@
|
||||||
},
|
},
|
||||||
"dashboard": {
|
"dashboard": {
|
||||||
"welcomeTitle": "Welcome back",
|
"welcomeTitle": "Welcome back",
|
||||||
"welcomeSubtitle": "Today is a great day to learn something new. Let's gain more knowledge!"
|
"welcomeSubtitle": "Today is a great day to learn something new. Let's gain more knowledge!",
|
||||||
|
"heroTitle": "Continually upskill yourself",
|
||||||
|
"heroSubtitle": "to achieve your goals",
|
||||||
|
"heroDesc": "How many minutes have you learned today? Let's build a great learning habit. We have many new recommended courses waiting for you.",
|
||||||
|
"goToMyCourses": "Go to My Courses",
|
||||||
|
"searchNewCourses": "Find New Courses",
|
||||||
|
"continueLearningTitle": "Continue learning with your courses",
|
||||||
|
"myCourses": "My Courses",
|
||||||
|
"studyAgain": "Study Again",
|
||||||
|
"continue": "Continue",
|
||||||
|
"startNewCourse": "Start new courses to fill this section",
|
||||||
|
"knowledgeLibrary": "Knowledge Library",
|
||||||
|
"libraryDesc": "You can choose to learn from courses you own",
|
||||||
|
"chooseLibrary": "Choose to learn from your knowledge library",
|
||||||
|
"viewAll": "View All",
|
||||||
|
"emptyLibraryTitle": "No courses in library yet",
|
||||||
|
"emptyLibraryDesc": "Start learning new things today. Browse interesting courses to develop your skills.",
|
||||||
|
"viewAllCourses": "View All Courses",
|
||||||
|
"recommendedCourses": "Recommended Courses",
|
||||||
|
"noRecommended": "No recommended courses found",
|
||||||
|
"moreCourses": "More Courses"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"continueLearning": "Continue Learning",
|
"continueLearning": "Continue Learning",
|
||||||
|
|
@ -40,26 +60,42 @@
|
||||||
"studyAgain": "Study Again",
|
"studyAgain": "Study Again",
|
||||||
"downloadCertificate": "Download Certificate",
|
"downloadCertificate": "Download Certificate",
|
||||||
"completed": "Completed",
|
"completed": "Completed",
|
||||||
"includes": "Course includes",
|
|
||||||
"fullLifetimeAccess": "Full lifetime access",
|
|
||||||
"accessOnMobile": "Access on mobile and TV",
|
|
||||||
"lifetimeAccess": "Lifetime access",
|
"lifetimeAccess": "Lifetime access",
|
||||||
"unlimitedQuizzes": "Unlimited quizzes",
|
"unlimitedQuizzes": "Unlimited quizzes",
|
||||||
"satisfactionGuarantee": "Satisfaction guarantee, 7-day refund",
|
"satisfactionGuarantee": "Satisfaction guarantee, 7-day refund",
|
||||||
"noContent": "No content available yet",
|
"noContent": "No content available yet",
|
||||||
"buyNow": "Buy this course",
|
|
||||||
"enrollFree": "Enroll for free",
|
"enrollFree": "Enroll for free",
|
||||||
"loginToEnroll": "Log in to enroll",
|
"loginToEnroll": "Log in to enroll",
|
||||||
"minutes": "Minutes",
|
"minutes": "Minutes",
|
||||||
"noVideoPreview": "Video preview not available",
|
"noVideoPreview": "Video preview not available",
|
||||||
"videoNotSupported": "Your browser does not support the video tag"
|
"videoNotSupported": "Your browser does not support the video tag",
|
||||||
|
"aboutCourse": "About Course",
|
||||||
|
"lessonDetails": "Lesson Details",
|
||||||
|
"courseStats": {
|
||||||
|
"level": "Level",
|
||||||
|
"duration": "Duration",
|
||||||
|
"lessons": "Lessons",
|
||||||
|
"students": "Students"
|
||||||
|
},
|
||||||
|
"certificatePreview": "Certificate Preview",
|
||||||
|
"certificateDesc": "Upon completion and passing criteria",
|
||||||
|
"includes": "This course includes",
|
||||||
|
"fullLifetimeAccess": "Full lifetime access",
|
||||||
|
"accessOnMobile": "Access on mobile and tablet",
|
||||||
|
"buyNow": "Buy Now"
|
||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
"overview": "Home",
|
"overview": "Home",
|
||||||
"myCourses": "My Courses",
|
"myCourses": "My Courses",
|
||||||
"browseCourses": "Browse Courses",
|
"browseCourses": "Browse Courses",
|
||||||
|
"onlineCourses": "All Courses",
|
||||||
|
"recommendedCourses": "Recommended Courses",
|
||||||
"announcements": "Announcements",
|
"announcements": "Announcements",
|
||||||
"profile": "My Profile"
|
"profile": "My Profile",
|
||||||
|
"accountGroup": "Account",
|
||||||
|
"promoTitle": "Find the right course",
|
||||||
|
"promoSubtitle": "Level up your skills",
|
||||||
|
"learnMore": "Learn More"
|
||||||
},
|
},
|
||||||
"discovery": {
|
"discovery": {
|
||||||
"title": "All Courses",
|
"title": "All Courses",
|
||||||
|
|
@ -67,6 +103,9 @@
|
||||||
"sortRecent": "Sort by: Recent",
|
"sortRecent": "Sort by: Recent",
|
||||||
"sortPopular": "Popular",
|
"sortPopular": "Popular",
|
||||||
"categoryTitle": "Categories",
|
"categoryTitle": "Categories",
|
||||||
|
"design": "Design",
|
||||||
|
"programming": "Programming",
|
||||||
|
"business": "Business",
|
||||||
"showMore": "Show More",
|
"showMore": "Show More",
|
||||||
"showLess": "Show Less",
|
"showLess": "Show Less",
|
||||||
"emptyTitle": "No courses found",
|
"emptyTitle": "No courses found",
|
||||||
|
|
@ -74,15 +113,24 @@
|
||||||
"showAll": "Show All",
|
"showAll": "Show All",
|
||||||
"loadMore": "Load More",
|
"loadMore": "Load More",
|
||||||
"backToCatalog": "Back to Catalog",
|
"backToCatalog": "Back to Catalog",
|
||||||
"selectable": "Selected"
|
"selectable": "Selected",
|
||||||
|
"foundTotal": "Found Total",
|
||||||
|
"items": "items",
|
||||||
|
"subtitle": "Choose to learn new skills from our curated quality courses",
|
||||||
|
"searchBtn": "Search"
|
||||||
},
|
},
|
||||||
"myCourses": {
|
"myCourses": {
|
||||||
|
"title": "My Courses",
|
||||||
|
"subtitle": "Track your progress and continue learning from where you left off",
|
||||||
|
"searchPlaceholder": "Search my courses...",
|
||||||
"filterAll": "All",
|
"filterAll": "All",
|
||||||
"filterProgress": "In Progress",
|
"filterProgress": "In Progress",
|
||||||
"filterCompleted": "Completed",
|
"filterCompleted": "Completed",
|
||||||
"emptyTitle": "No courses in this category",
|
"emptyTitle": "No courses in this category",
|
||||||
"emptyDesc": "You don't have any courses here yet. Browse our catalog to find interesting courses.",
|
"emptyDesc": "You don't have any courses here yet. Browse our catalog to find interesting courses.",
|
||||||
"goToDiscovery": "Go to Courses"
|
"goToDiscovery": "Go to Courses",
|
||||||
|
"searchNoResult": "No matching courses found",
|
||||||
|
"searchNoResultDesc": "Try changing category or your search term"
|
||||||
},
|
},
|
||||||
"enrollment": {
|
"enrollment": {
|
||||||
"successTitle": "Enrollment Successful!",
|
"successTitle": "Enrollment Successful!",
|
||||||
|
|
@ -107,9 +155,11 @@
|
||||||
"email": "Email",
|
"email": "Email",
|
||||||
"phone": "Phone",
|
"phone": "Phone",
|
||||||
"joinedAt": "Joined",
|
"joinedAt": "Joined",
|
||||||
|
"generalInfo": "General Information",
|
||||||
|
"accountDetails": "Account Details",
|
||||||
"editPersonalDesc": "Edit Personal Information",
|
"editPersonalDesc": "Edit Personal Information",
|
||||||
"yourAvatar": "Your Profile Photo",
|
"yourAvatar": "Your Profile Photo",
|
||||||
"avatarHint": "PNG, JPG only",
|
"avatarHint": "Only JPG, PNG",
|
||||||
"uploadNew": "Upload New Photo",
|
"uploadNew": "Upload New Photo",
|
||||||
"changeAvatar": "Change Profile Photo",
|
"changeAvatar": "Change Profile Photo",
|
||||||
"removeAvatar": "Remove Profile Photo",
|
"removeAvatar": "Remove Profile Photo",
|
||||||
|
|
@ -140,7 +190,15 @@
|
||||||
"emailVerified": "Email Verified",
|
"emailVerified": "Email Verified",
|
||||||
"myCertificates": "My Certificates",
|
"myCertificates": "My Certificates",
|
||||||
"viewCertificate": "View Certificate",
|
"viewCertificate": "View Certificate",
|
||||||
"issuedAt": "Issued at"
|
"issuedAt": "Issued at",
|
||||||
|
"publicInfo": "Information visible to the public on the platform",
|
||||||
|
"uploading": "Uploading...",
|
||||||
|
"selectPrefix": "Select Prefix",
|
||||||
|
"verifyNow": "Click to verify email",
|
||||||
|
"verifying": "Sending...",
|
||||||
|
"saving": "Saving...",
|
||||||
|
"securitySubtitle": "Manage password and account access",
|
||||||
|
"password": "Password"
|
||||||
},
|
},
|
||||||
"userMenu": {
|
"userMenu": {
|
||||||
"home": "Home",
|
"home": "Home",
|
||||||
|
|
@ -163,7 +221,9 @@
|
||||||
"emailVerifiedDesc": "Your account has been successfully verified.",
|
"emailVerifiedDesc": "Your account has been successfully verified.",
|
||||||
"invalidToken": "Invalid verification token",
|
"invalidToken": "Invalid verification token",
|
||||||
"tokenExpired": "Token expired or invalid",
|
"tokenExpired": "Token expired or invalid",
|
||||||
"logout": "Log Out"
|
"logout": "Log Out",
|
||||||
|
"logoutConfirmTitle": "Confirm Logout",
|
||||||
|
"logoutConfirmMessage": "Are you sure you want to log out of the system?"
|
||||||
},
|
},
|
||||||
"language": {
|
"language": {
|
||||||
"label": "Language / ภาษา",
|
"label": "Language / ภาษา",
|
||||||
|
|
@ -174,6 +234,7 @@
|
||||||
"newBadge": "New",
|
"newBadge": "New",
|
||||||
"popularBadge": "Popular",
|
"popularBadge": "Popular",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
|
"saveChanges": "Save Changes",
|
||||||
"ok": "OK",
|
"ok": "OK",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
|
|
@ -187,7 +248,9 @@
|
||||||
"backToHome": "Back to Home",
|
"backToHome": "Back to Home",
|
||||||
"error": "Error",
|
"error": "Error",
|
||||||
"loading": "Loading",
|
"loading": "Loading",
|
||||||
"items": "Items"
|
"items": "Items",
|
||||||
|
"student": "Student",
|
||||||
|
"latest": "Latest"
|
||||||
},
|
},
|
||||||
"classroom": {
|
"classroom": {
|
||||||
"backToDashboard": "Back to My Courses",
|
"backToDashboard": "Back to My Courses",
|
||||||
|
|
@ -256,5 +319,16 @@
|
||||||
"statusNotStarted": "Not Started",
|
"statusNotStarted": "Not Started",
|
||||||
"alertIncomplete": "Please answer all questions",
|
"alertIncomplete": "Please answer all questions",
|
||||||
"yourAnswer": "Your Answer"
|
"yourAnswer": "Your Answer"
|
||||||
|
},
|
||||||
|
"footer": {
|
||||||
|
"location": "LOCATION",
|
||||||
|
"connectWithUs": "CONNECT WITH US",
|
||||||
|
"broncoHorse": "Bronco Hourse",
|
||||||
|
"address": "123 อาคารสยามทาวเวอร์ ชั้น 15 เขตปทุมวัน กรุงเทพฯ 10330",
|
||||||
|
"emailLabel": "Email",
|
||||||
|
"emailValue": "info{'@'}chamomind.com",
|
||||||
|
"telLabel": "Tel",
|
||||||
|
"telValue": "02-123-4567",
|
||||||
|
"copyright": "© 2026 E-Learning Platform. All rights reserved."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,27 @@
|
||||||
},
|
},
|
||||||
"dashboard": {
|
"dashboard": {
|
||||||
"welcomeTitle": "ยินดีต้อนรับกลับ",
|
"welcomeTitle": "ยินดีต้อนรับกลับ",
|
||||||
"welcomeSubtitle": "วันนี้เป็นวันที่ดีสำหรับการเรียนรู้สิ่งใหม่ๆ มาเก็บความรู้เพิ่มกันเถอะ"
|
"welcomeSubtitle": "วันนี้เป็นวันที่ดีสำหรับการเรียนรู้สิ่งใหม่ๆ มาเก็บความรู้เพิ่มกันเถอะ",
|
||||||
|
"heroTitle": "อัปสกิลของคุณต่อเนื่อง",
|
||||||
|
"heroSubtitle": "เพื่อเป้าหมายที่วางไว้",
|
||||||
|
"heroDesc": "วันนี้คุณเรียนไปกี่นาทีแล้ว? มาสร้างนิสัยการเรียนรู้ที่ยอดเยี่ยมกันเถอะ เรามีคอร์สแนะนำใหม่ๆ มากมายรอคุณอยู่",
|
||||||
|
"goToMyCourses": "ไปที่คอร์สเรียนของฉัน",
|
||||||
|
"searchNewCourses": "ค้นหาคอร์สใหม่",
|
||||||
|
"continueLearningTitle": "เรียนต่อกับคอร์สของคุณ",
|
||||||
|
"myCourses": "คอร์สเรียนของฉัน",
|
||||||
|
"studyAgain": "เรียนอีกครั้ง",
|
||||||
|
"continue": "เรียนต่อ",
|
||||||
|
"startNewCourse": "เริ่มเรียนคอร์สใหม่ๆ เพื่อเติมเต็มส่วนนี้",
|
||||||
|
"knowledgeLibrary": "คลังความรู้",
|
||||||
|
"libraryDesc": "คุณสามารถเลือกเรียนคอร์สเรียนที่คุณเป็นเจ้าของ",
|
||||||
|
"chooseLibrary": "เลือกเรียนคอร์สในคลังความรู้ของคุณ",
|
||||||
|
"viewAll": "ดูทั้งหมด",
|
||||||
|
"emptyLibraryTitle": "ยังไม่มีคอร์สเรียนในคลัง",
|
||||||
|
"emptyLibraryDesc": "เริ่มเรียนรู้สิ่งใหม่ๆ วันนี้ เลือกดูคอร์สเรียนที่น่าสนใจเพื่อพัฒนาทักษะของคุณ",
|
||||||
|
"viewAllCourses": "ดูคอร์สเรียนทั้งหมด",
|
||||||
|
"recommendedCourses": "คอร์สแนะนำ",
|
||||||
|
"noRecommended": "ไม่พบข้อมูลคอร์สแนะนำ",
|
||||||
|
"moreCourses": "คอร์สเพิ่มเติม"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"continueLearning": "เรียนต่อจากเดิม",
|
"continueLearning": "เรียนต่อจากเดิม",
|
||||||
|
|
@ -40,26 +60,42 @@
|
||||||
"studyAgain": "ทบทวนบทเรียน",
|
"studyAgain": "ทบทวนบทเรียน",
|
||||||
"downloadCertificate": "ดาวน์โหลดประกาศนียบัตร",
|
"downloadCertificate": "ดาวน์โหลดประกาศนียบัตร",
|
||||||
"completed": "เรียนจบเรียบร้อย",
|
"completed": "เรียนจบเรียบร้อย",
|
||||||
"includes": "สิ่งที่รวมอยู่ในคอร์ส",
|
|
||||||
"fullLifetimeAccess": "เข้าเรียนได้ตลอดชีพ",
|
|
||||||
"accessOnMobile": "เรียนได้บนมือถือและแท็บเล็ต",
|
|
||||||
"lifetimeAccess": "เข้าเรียนได้ตลอดชีพ",
|
"lifetimeAccess": "เข้าเรียนได้ตลอดชีพ",
|
||||||
"unlimitedQuizzes": "ทำแบบทดสอบไม่จำกัด",
|
"unlimitedQuizzes": "ทำแบบทดสอบไม่จำกัด",
|
||||||
"satisfactionGuarantee": "รับประกันความพึงพอใจ คืนเงินภายใน 7 วัน",
|
"satisfactionGuarantee": "รับประกันความพึงพอใจ คืนเงินภายใน 7 วัน",
|
||||||
"noContent": "ยังไม่มีเนื้อหาในขณะนี้",
|
"noContent": "ยังไม่มีเนื้อหาในขณะนี้",
|
||||||
"buyNow": "ซื้อคอร์สเรียนนี้",
|
|
||||||
"enrollFree": "ลงทะเบียนเรียนฟรี",
|
"enrollFree": "ลงทะเบียนเรียนฟรี",
|
||||||
"loginToEnroll": "เข้าสู่ระบบเพื่อลงทะเบียน",
|
"loginToEnroll": "เข้าสู่ระบบเพื่อลงทะเบียน",
|
||||||
"minutes": "นาที",
|
"minutes": "นาที",
|
||||||
"noVideoPreview": "วิดีโอตัวอย่างยังไม่พร้อมใช้งาน",
|
"noVideoPreview": "วิดีโอตัวอย่างยังไม่พร้อมใช้งาน",
|
||||||
"videoNotSupported": "เบราว์เซอร์ของคุณไม่รองรับการเล่นวิดีโอ"
|
"videoNotSupported": "เบราว์เซอร์ของคุณไม่รองรับการเล่นวิดีโอ",
|
||||||
|
"aboutCourse": "เกี่ยวกับคอร์ส",
|
||||||
|
"lessonDetails": "รายละเอียดบทเรียน",
|
||||||
|
"courseStats": {
|
||||||
|
"level": "ระดับ",
|
||||||
|
"duration": "ระยะเวลา",
|
||||||
|
"lessons": "บทเรียน",
|
||||||
|
"students": "ผู้เรียน"
|
||||||
|
},
|
||||||
|
"certificatePreview": "ตัวอย่างใบประกาศนียบัตร",
|
||||||
|
"certificateDesc": "เมื่อเรียนจบและสอบผ่านตามเกณฑ์ที่กำหนด",
|
||||||
|
"includes": "สิ่งที่รวมอยู่ในคอร์ส",
|
||||||
|
"fullLifetimeAccess": "เข้าเรียนได้ตลอดชีพ",
|
||||||
|
"accessOnMobile": "เรียนได้บนมือถือและแท็บเล็ต",
|
||||||
|
"buyNow": "ซื้อคอร์สนี้"
|
||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
"overview": "หน้าหลัก",
|
"overview": "หน้าหลัก",
|
||||||
"myCourses": "คอร์สของฉัน",
|
"myCourses": "คอร์สของฉัน",
|
||||||
"browseCourses": "ค้นหาคอร์ส",
|
"browseCourses": "ค้นหาคอร์ส",
|
||||||
|
"onlineCourses": "คอร์สเรียนทั้งหมด",
|
||||||
|
"recommendedCourses": "คอร์สเรียนแนะนำ",
|
||||||
"announcements": "ข่าวประกาศ",
|
"announcements": "ข่าวประกาศ",
|
||||||
"profile": "บัญชีผู้ใช้"
|
"profile": "บัญชีผู้ใช้",
|
||||||
|
"accountGroup": "บัญชี",
|
||||||
|
"promoTitle": "ค้นหาคอร์สที่ใช่",
|
||||||
|
"promoSubtitle": "ยกระดับทักษะของคุณ",
|
||||||
|
"learnMore": "เรียนรู้เพิ่มเติม"
|
||||||
},
|
},
|
||||||
"discovery": {
|
"discovery": {
|
||||||
"title": "รายการคอร์สทั้งหมด",
|
"title": "รายการคอร์สทั้งหมด",
|
||||||
|
|
@ -67,6 +103,9 @@
|
||||||
"sortRecent": "เรียงตาม: ล่าสุด",
|
"sortRecent": "เรียงตาม: ล่าสุด",
|
||||||
"sortPopular": "ยอดนิยม",
|
"sortPopular": "ยอดนิยม",
|
||||||
"categoryTitle": "หมวดหมู่",
|
"categoryTitle": "หมวดหมู่",
|
||||||
|
"design": "การออกแบบ",
|
||||||
|
"programming": "การเขียนโปรแกรม",
|
||||||
|
"business": "ธุรกิจ",
|
||||||
"showMore": "แสดงเพิ่มเติม",
|
"showMore": "แสดงเพิ่มเติม",
|
||||||
"showLess": "แสดงน้อยลง",
|
"showLess": "แสดงน้อยลง",
|
||||||
"emptyTitle": "ไม่พบผลการค้นหา",
|
"emptyTitle": "ไม่พบผลการค้นหา",
|
||||||
|
|
@ -74,15 +113,24 @@
|
||||||
"showAll": "แสดงทั้งหมด",
|
"showAll": "แสดงทั้งหมด",
|
||||||
"loadMore": "โหลดเพิ่มเติม",
|
"loadMore": "โหลดเพิ่มเติม",
|
||||||
"backToCatalog": "กลับหน้ารายการคอร์ส",
|
"backToCatalog": "กลับหน้ารายการคอร์ส",
|
||||||
"selectable": "รายการที่เลือก"
|
"selectable": "รายการที่เลือก",
|
||||||
|
"foundTotal": "พบทั้งหมด",
|
||||||
|
"items": "รายการ",
|
||||||
|
"subtitle": "เลือกเรียนรู้ทักษะใหม่ๆ จากหลักสูตรคุณภาพที่คัดสรรมาเพื่อคุณ",
|
||||||
|
"searchBtn": "ค้นหา"
|
||||||
},
|
},
|
||||||
"myCourses": {
|
"myCourses": {
|
||||||
|
"title": "คอร์สของฉัน",
|
||||||
|
"subtitle": "ติดตามความคืบหน้าและเรียนรู้ต่อจากจุดที่ค้างไว้",
|
||||||
|
"searchPlaceholder": "ค้นหาชื่อคอร์สของฉัน...",
|
||||||
"filterAll": "ทั้งหมด",
|
"filterAll": "ทั้งหมด",
|
||||||
"filterProgress": "กำลังเรียน",
|
"filterProgress": "กำลังเรียน",
|
||||||
"filterCompleted": "เรียนจบแล้ว",
|
"filterCompleted": "เรียนจบแล้ว",
|
||||||
"emptyTitle": "ยังไม่มีคอร์สในหมวดหมู่นี้",
|
"emptyTitle": "ยังไม่มีคอร์สในหมวดหมู่นี้",
|
||||||
"emptyDesc": "คุณยังไม่มีคอร์สเรียนในส่วนนี้ ลองเลือกดูคอร์สที่น่าสนใจในระบบของเรา",
|
"emptyDesc": "คุณยังไม่มีคอร์สเรียนในส่วนนี้ ลองเลือกดูคอร์สที่น่าสนใจในระบบของเรา",
|
||||||
"goToDiscovery": "ไปที่รายการคอร์ส"
|
"goToDiscovery": "ไปที่รายการคอร์ส",
|
||||||
|
"searchNoResult": "ไม่พบคอร์สที่สอดคล้อง",
|
||||||
|
"searchNoResultDesc": "ลองเปลี่ยนหมวดหมู่หรือคำค้นหาของคุณ"
|
||||||
},
|
},
|
||||||
"enrollment": {
|
"enrollment": {
|
||||||
"successTitle": "ลงทะเบียนสำเร็จ!",
|
"successTitle": "ลงทะเบียนสำเร็จ!",
|
||||||
|
|
@ -107,9 +155,11 @@
|
||||||
"email": "อีเมล",
|
"email": "อีเมล",
|
||||||
"phone": "เบอร์โทรศัพท์",
|
"phone": "เบอร์โทรศัพท์",
|
||||||
"joinedAt": "สมัครสมาชิกเมื่อ",
|
"joinedAt": "สมัครสมาชิกเมื่อ",
|
||||||
|
"generalInfo": "ข้อมูลทั่วไป",
|
||||||
|
"accountDetails": "รายละเอียดบัญชี",
|
||||||
"editPersonalDesc": "แก้ไขข้อมูลส่วนตัว",
|
"editPersonalDesc": "แก้ไขข้อมูลส่วนตัว",
|
||||||
"yourAvatar": "รูปโปรไฟล์ของคุณ",
|
"yourAvatar": "รูปโปรไฟล์ของคุณ",
|
||||||
"avatarHint": "เฉพาะไฟล์ png , jpg",
|
"avatarHint": "เฉพาะไฟล์ JPG, PNG",
|
||||||
"uploadNew": "อัพโหลดรูปโปรไฟล์",
|
"uploadNew": "อัพโหลดรูปโปรไฟล์",
|
||||||
"changeAvatar": "เปลี่ยนรูปโปรไฟล์",
|
"changeAvatar": "เปลี่ยนรูปโปรไฟล์",
|
||||||
"removeAvatar": "ลบรูปโปรไฟล์",
|
"removeAvatar": "ลบรูปโปรไฟล์",
|
||||||
|
|
@ -140,7 +190,15 @@
|
||||||
"emailVerified": "ยืนยันอีเมลเสร็จสิ้น",
|
"emailVerified": "ยืนยันอีเมลเสร็จสิ้น",
|
||||||
"myCertificates": "ประกาศนียบัตรของฉัน",
|
"myCertificates": "ประกาศนียบัตรของฉัน",
|
||||||
"viewCertificate": "ดูประกาศนียบัตร",
|
"viewCertificate": "ดูประกาศนียบัตร",
|
||||||
"issuedAt": "ออกเมื่อ"
|
"issuedAt": "ออกเมื่อ",
|
||||||
|
"publicInfo": "ข้อมูลที่แสดงต่อสาธารณะบนแพลตฟอร์ม",
|
||||||
|
"uploading": "กำลังอัปโหลด...",
|
||||||
|
"selectPrefix": "เลือกคำนำหน้า",
|
||||||
|
"verifyNow": "คลิกเพื่อยืนยันอีเมล",
|
||||||
|
"verifying": "กำลังส่ง...",
|
||||||
|
"saving": "กำลังบันทึก...",
|
||||||
|
"securitySubtitle": "จัดการรหัสผ่านและการเข้าถึงบัญชี",
|
||||||
|
"password": "รหัสผ่าน"
|
||||||
},
|
},
|
||||||
"userMenu": {
|
"userMenu": {
|
||||||
"home": "หน้าหลัก",
|
"home": "หน้าหลัก",
|
||||||
|
|
@ -151,7 +209,7 @@
|
||||||
"logout": "ออกจากระบบ"
|
"logout": "ออกจากระบบ"
|
||||||
},
|
},
|
||||||
"landing": {
|
"landing": {
|
||||||
"allCourses": "คอร์สทั้งหมด",
|
"allCourses": "คอร์สเรียนทั้งหมด",
|
||||||
"discovery": "ค้นพบ",
|
"discovery": "ค้นพบ",
|
||||||
"goToDashboard": "เข้าสู่หน้าจัดการเรียน"
|
"goToDashboard": "เข้าสู่หน้าจัดการเรียน"
|
||||||
},
|
},
|
||||||
|
|
@ -163,7 +221,9 @@
|
||||||
"emailVerifiedDesc": "บัญชีของคุณได้รับการยืนยันเรียบร้อยแล้ว",
|
"emailVerifiedDesc": "บัญชีของคุณได้รับการยืนยันเรียบร้อยแล้ว",
|
||||||
"invalidToken": "Token ยืนยันตัวตนไม่ถูกต้อง",
|
"invalidToken": "Token ยืนยันตัวตนไม่ถูกต้อง",
|
||||||
"tokenExpired": "Token หมดอายุหรือล้มเหลว",
|
"tokenExpired": "Token หมดอายุหรือล้มเหลว",
|
||||||
"logout": "ออกจากระบบ"
|
"logout": "ออกจากระบบ",
|
||||||
|
"logoutConfirmTitle": "ยืนยันการออกจากระบบ",
|
||||||
|
"logoutConfirmMessage": "คุณแน่ใจหรือไม่ว่าต้องการออกจากระบบ?"
|
||||||
},
|
},
|
||||||
"language": {
|
"language": {
|
||||||
"label": "ภาษา / Language",
|
"label": "ภาษา / Language",
|
||||||
|
|
@ -174,6 +234,7 @@
|
||||||
"newBadge": "ใหม่",
|
"newBadge": "ใหม่",
|
||||||
"popularBadge": "ยอดนิยม",
|
"popularBadge": "ยอดนิยม",
|
||||||
"save": "บันทึก",
|
"save": "บันทึก",
|
||||||
|
"saveChanges": "บันทึกการเปลี่ยนแปลง",
|
||||||
"ok": "ตกลง",
|
"ok": "ตกลง",
|
||||||
"close": "ปิด",
|
"close": "ปิด",
|
||||||
"cancel": "ยกเลิก",
|
"cancel": "ยกเลิก",
|
||||||
|
|
@ -187,7 +248,9 @@
|
||||||
"backToHome": "กลับสู่หน้าหลัก",
|
"backToHome": "กลับสู่หน้าหลัก",
|
||||||
"error": "เกิดข้อผิดพลาด",
|
"error": "เกิดข้อผิดพลาด",
|
||||||
"loading": "กำลังโหลด",
|
"loading": "กำลังโหลด",
|
||||||
"items": "รายการ"
|
"items": "รายการ",
|
||||||
|
"student": "นักเรียน",
|
||||||
|
"latest": "ล่าสุด"
|
||||||
},
|
},
|
||||||
"classroom": {
|
"classroom": {
|
||||||
"backToDashboard": "กลับไปคอร์สของฉัน",
|
"backToDashboard": "กลับไปคอร์สของฉัน",
|
||||||
|
|
@ -256,5 +319,16 @@
|
||||||
"statusNotStarted": "ยังไม่ทำ",
|
"statusNotStarted": "ยังไม่ทำ",
|
||||||
"alertIncomplete": "กรุณาเลือกคำตอบให้ครบทุกข้อ",
|
"alertIncomplete": "กรุณาเลือกคำตอบให้ครบทุกข้อ",
|
||||||
"yourAnswer": "คำตอบของคุณ"
|
"yourAnswer": "คำตอบของคุณ"
|
||||||
|
},
|
||||||
|
"footer": {
|
||||||
|
"location": "สถานที่ตั้ง",
|
||||||
|
"connectWithUs": "ติดต่อเรา",
|
||||||
|
"broncoHorse": "Bronco Hourse",
|
||||||
|
"address": "123 อาคารสยามทาวเวอร์ ชั้น 15 เขตปทุมวัน กรุงเทพฯ 10330",
|
||||||
|
"emailLabel": "อีเมล",
|
||||||
|
"emailValue": "info{'@'}chamomind.com",
|
||||||
|
"telLabel": "เบอร์โทรศัพท์",
|
||||||
|
"telValue": "02-123-4567",
|
||||||
|
"copyright": "© 2026 E-Learning Platform. All rights reserved."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ onMounted(() => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<!-- Auth Shell: Wrapper for authentication pages (Login, Register, etc.) -->
|
<!-- Auth Shell: ครอบคลุมการแสดงผลหน้าสำหรับเข้าสู่ระบบหรือสมัครสมาชิก -->
|
||||||
<div class="auth-shell bg-white w-full min-h-screen">
|
<div class="auth-shell bg-white w-full min-h-screen">
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
165
Frontend-Learner/layouts/dashboard-index.vue
Normal file
165
Frontend-Learner/layouts/dashboard-index.vue
Normal file
|
|
@ -0,0 +1,165 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* @file dashboard-index.vue
|
||||||
|
* @description เลย์เอาต์สำหรับหน้าแรกของ Dashboard (ไม่มีแผงเมนูด้านข้างเพื่อเน้นพื้นที่เนื้อหา)
|
||||||
|
* ใช้โครงสร้างจาก Quasar QLayout เพื่อให้รองรับ Responsive
|
||||||
|
*/
|
||||||
|
|
||||||
|
// เปิดใช้คอมโพสซิเบิลจัดการธีมแบบ Global
|
||||||
|
useThemeMode()
|
||||||
|
|
||||||
|
const { currentUser, logout } = useAuth()
|
||||||
|
const { isDark, set: setTheme } = useThemeMode()
|
||||||
|
const rightDrawerOpen = ref(false)
|
||||||
|
const toggleRightDrawer = () => {
|
||||||
|
rightDrawerOpen.value = !rightDrawerOpen.value
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<q-layout view="hHh lpR fFf" class="bg-slate-50 dark:!bg-[#020617] text-slate-900 dark:!text-slate-50">
|
||||||
|
<!-- แถบด้านบนของโครงสร้าง (Header) -->
|
||||||
|
<q-header
|
||||||
|
class="bg-white/80 dark:!bg-[#0f172a]/80 backdrop-blur-md text-slate-900 dark:!text-white"
|
||||||
|
>
|
||||||
|
<AppHeader
|
||||||
|
@toggleRightDrawer="toggleRightDrawer"
|
||||||
|
:showSidebarToggle="false"
|
||||||
|
navType="learner"
|
||||||
|
/>
|
||||||
|
</q-header>
|
||||||
|
|
||||||
|
<!-- แถบลิ้นชักมือถือหลัก (เมนูรวมทุกอย่างเมื่อปัดหน้าจอ/กดไอคอนบนสัดส่วนเล็ก) -->
|
||||||
|
<q-drawer
|
||||||
|
v-model="rightDrawerOpen"
|
||||||
|
side="right"
|
||||||
|
overlay
|
||||||
|
bordered
|
||||||
|
class="bg-white dark:!bg-[#0f172a]"
|
||||||
|
:width="300"
|
||||||
|
>
|
||||||
|
<div class="flex flex-col h-full bg-white dark:bg-[#0f172a]">
|
||||||
|
<!-- 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">
|
||||||
|
<div class="w-8 h-8 rounded-lg bg-blue-600 flex items-center justify-center text-white font-black">E</div>
|
||||||
|
<span class="font-black text-lg text-slate-900 dark:text-white">E-Learning</span>
|
||||||
|
</div>
|
||||||
|
<q-btn flat round dense icon="close" class="text-slate-400" @click="rightDrawerOpen = false" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-4 py-2">
|
||||||
|
<q-avatar size="64px" class="shadow-lg border-2 border-white dark:border-slate-700">
|
||||||
|
<img :src="currentUser?.photoURL || 'https://cdn.quasar.dev/img/avatar.png'" />
|
||||||
|
</q-avatar>
|
||||||
|
<div class="overflow-hidden">
|
||||||
|
<p class="font-bold text-slate-900 dark:text-white mb-0 truncate text-lg">
|
||||||
|
{{ currentUser?.firstName || 'Guest' }} {{ currentUser?.lastName || '' }}
|
||||||
|
</p>
|
||||||
|
<p class="text-xs text-slate-500 dark:text-slate-400 truncate">{{ currentUser?.email || 'e-learning@platform.com' }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 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) -->
|
||||||
|
<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">
|
||||||
|
<q-item-section avatar><q-icon name="dashboard" size="24px" /></q-item-section>
|
||||||
|
<q-item-section><span class="text-[15px] font-bold">{{ $t("sidebar.overview") }}</span></q-item-section>
|
||||||
|
</q-item>
|
||||||
|
|
||||||
|
<q-item to="/browse/discovery" 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">
|
||||||
|
<q-item-section avatar><q-icon name="explore" size="24px" /></q-item-section>
|
||||||
|
<q-item-section><span class="text-[15px] font-bold">{{ $t("landing.allCourses") }}</span></q-item-section>
|
||||||
|
</q-item>
|
||||||
|
|
||||||
|
<q-item to="/dashboard/my-courses" 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">
|
||||||
|
<q-item-section avatar><q-icon name="school" size="24px" /></q-item-section>
|
||||||
|
<q-item-section><span class="text-[15px] font-bold">{{ $t("sidebar.myCourses") || 'คอร์สเรียนของฉัน' }}</span></q-item-section>
|
||||||
|
</q-item>
|
||||||
|
|
||||||
|
<q-separator class="my-4 mx-6 opacity-50" />
|
||||||
|
|
||||||
|
<!-- เครื่องมือทั่วไปและการตั้งค่าระบบ -->
|
||||||
|
<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 class="px-6 py-2">
|
||||||
|
<q-item-section avatar><q-icon name="language" size="22px" /></q-item-section>
|
||||||
|
<q-item-section>
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span class="font-bold text-[14px]">ภาษา</span>
|
||||||
|
<LanguageSwitcher dense />
|
||||||
|
</div>
|
||||||
|
</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
|
||||||
|
<!-- เปิดปิดโหมดมืด (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>
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span class="font-bold text-[14px]">โหมดกลางคืน</span>
|
||||||
|
<q-toggle
|
||||||
|
:model-value="isDark"
|
||||||
|
@update:model-value="setTheme"
|
||||||
|
color="blue"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
|
||||||
|
<q-item clickable v-ripple @click="navigateTo('/dashboard/profile'); rightDrawerOpen = false" class="px-6 py-4">
|
||||||
|
<q-item-section avatar><q-icon name="person_outline" size="24px" /></q-item-section>
|
||||||
|
<q-item-section><span class="font-bold text-[15px]">จัดการโปรไฟล์</span></q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</q-list>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 3. ส่วนล่างสุด เช่น ล็อกเอาต์ หรือระบุเวอร์ชันระบบ -->
|
||||||
|
<div class="p-6 mt-auto border-t border-slate-100 dark:border-slate-800">
|
||||||
|
<q-btn
|
||||||
|
unelevated
|
||||||
|
class="full-width rounded-xl bg-red-50 text-red-600 dark:bg-red-900/20 dark:text-red-400 font-bold py-3 no-caps transition-all active:scale-95"
|
||||||
|
@click="logout"
|
||||||
|
>
|
||||||
|
<q-icon name="logout" size="20px" class="mr-2" />
|
||||||
|
ออกจากระบบ
|
||||||
|
</q-btn>
|
||||||
|
<div class="text-center mt-6">
|
||||||
|
<span class="text-[10px] font-bold uppercase tracking-[0.2em] text-slate-300 dark:text-slate-600">E-Learning Platform v1.0</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</q-drawer>
|
||||||
|
|
||||||
|
<!-- หมายเหตุ: สำหรับหน้านี้ จะไม่ได้มีการโชว์ Sidebar ที่เป็นลิ้นชักซ้าย -->
|
||||||
|
|
||||||
|
<!-- พื้นที่แสดงเนื้อหาหลัก -->
|
||||||
|
<q-page-container>
|
||||||
|
<q-page class="relative">
|
||||||
|
<slot />
|
||||||
|
</q-page>
|
||||||
|
</q-page-container>
|
||||||
|
|
||||||
|
<!-- เมนูปุ่มกดล่างหน้าจอบนมือถือ (สำหรับช่วยให้เข้าถึงหน้าหลักได้ไวขึ้น) -->
|
||||||
|
<q-footer
|
||||||
|
v-if="$q.screen.lt.md"
|
||||||
|
class="!bg-white dark:!bg-[#1e293b] text-primary"
|
||||||
|
>
|
||||||
|
<MobileNav />
|
||||||
|
</q-footer>
|
||||||
|
</q-layout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* Ensure fonts are applied */
|
||||||
|
.font-inter {
|
||||||
|
font-family: var(--font-main);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -1,61 +1,66 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/**
|
/**
|
||||||
* @file default.vue
|
* @file default.vue
|
||||||
* @description Layout หลักสำหรับหน้าเว็บของผู้ใช้ (Authenticated Users)
|
* @description เลย์เอาต์หลัก (Master Layout) สำหรับผู้ใช้งานที่เข้าสู่ระบบแล้ว
|
||||||
* Uses Quasar QLayout for responsive structure.
|
* ประกอบด้วยแถบเมนูด้านบน (Header), แถบเมนูด้านข้าง (Sidebar) และพื้นที่เนื้อหา
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Initialize global theme management
|
|
||||||
useThemeMode()
|
useThemeMode()
|
||||||
|
|
||||||
const leftDrawerOpen = ref(false)
|
const leftDrawerOpen = ref(true)
|
||||||
|
|
||||||
const toggleLeftDrawer = () => {
|
const toggleLeftDrawer = () => {
|
||||||
leftDrawerOpen.value = !leftDrawerOpen.value
|
leftDrawerOpen.value = !leftDrawerOpen.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
// ระบุว่า path ไหนบ้างที่ให้แสดงแถบเมนูด้านข้าง (Sidebar)
|
||||||
|
const isDashboardRoute = computed(() => {
|
||||||
|
const routes = ['/dashboard', '/browse', '/classroom', '/course']
|
||||||
|
return routes.some(r => route.path.startsWith(r))
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<q-layout view="hHh LpR lFf" class="bg-slate-50 dark:!bg-[#020617] text-slate-900 dark:!text-slate-50 font-sans">
|
<q-layout view="lHh Lpr lFf" class="bg-[#F8FAFC] dark:!bg-[#020617] text-slate-900 dark:!text-slate-50">
|
||||||
<!-- Header -->
|
|
||||||
|
<!-- ส่วนหัว (Header) -->
|
||||||
<q-header
|
<q-header
|
||||||
bordered
|
class="bg-transparent text-slate-900 dark:!text-white border-none shadow-none"
|
||||||
class="bg-white/80 dark:!bg-[#0f172a]/80 backdrop-blur-md text-slate-900 dark:!text-white border-b border-slate-200 dark:border-slate-800"
|
|
||||||
>
|
>
|
||||||
<AppHeader @toggleSidebar="toggleLeftDrawer" />
|
<AppHeader @toggleSidebar="toggleLeftDrawer" />
|
||||||
</q-header>
|
</q-header>
|
||||||
|
|
||||||
<!-- Sidebar (Drawer) -->
|
<!-- แถบเมนูด้านข้าง (Navigation Sidebar) -->
|
||||||
<q-drawer
|
<q-drawer
|
||||||
v-model="leftDrawerOpen"
|
v-model="leftDrawerOpen"
|
||||||
show-if-above
|
show-if-above
|
||||||
bordered
|
|
||||||
:width="280"
|
:width="280"
|
||||||
class="bg-white dark:!bg-[#0f172a] border-r border-slate-200 dark:border-slate-800"
|
side="left"
|
||||||
|
bordered
|
||||||
|
class="bg-white dark:!bg-[#0f172a] border-none"
|
||||||
>
|
>
|
||||||
<AppSidebar />
|
<AppSidebar />
|
||||||
</q-drawer>
|
</q-drawer>
|
||||||
|
|
||||||
<!-- Main Content -->
|
<!-- พื้นที่แสดงเนื้อหาหลัก (Main Content Area) -->
|
||||||
<q-page-container>
|
<q-page-container>
|
||||||
<q-page class="relative">
|
<q-page class="px-3 py-6 md:p-8">
|
||||||
|
<div class="max-w-[1600px] mx-auto">
|
||||||
<slot />
|
<slot />
|
||||||
|
</div>
|
||||||
</q-page>
|
</q-page>
|
||||||
</q-page-container>
|
</q-page-container>
|
||||||
|
|
||||||
<!-- Mobile Bottom Nav -->
|
|
||||||
<q-footer
|
|
||||||
v-if="$q.screen.lt.md"
|
|
||||||
bordered
|
|
||||||
class="!bg-white dark:!bg-[#1e293b] text-primary border-t border-slate-200 dark:border-slate-700"
|
|
||||||
>
|
|
||||||
<MobileNav />
|
|
||||||
</q-footer>
|
|
||||||
</q-layout>
|
</q-layout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Ensure fonts are applied */
|
/* Global Layout Adjustments */
|
||||||
.font-inter {
|
.q-drawer--bordered {
|
||||||
font-family: 'Inter', sans-serif;
|
border-right: 1px solid rgba(0,0,0,0.05) !important;
|
||||||
|
}
|
||||||
|
.dark .q-drawer--bordered {
|
||||||
|
border-right: 1px solid rgba(255,255,255,0.05) !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -20,28 +20,25 @@ onMounted(() => {
|
||||||
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<q-layout view="lHh LpR lFf" class="bg-white text-slate-900 font-inter">
|
<q-layout view="lHh LpR lFf" class="bg-white text-slate-900">
|
||||||
|
|
||||||
|
|
||||||
<!-- Header (Transparent & Overlay) -->
|
<!-- ส่วนหัวของเพจ (แบบโปร่งใส และซ้อนทับให้โชว์เนื้อหาพื้นหลังได้) -->
|
||||||
<q-header class="bg-transparent" style="height: auto;">
|
<q-header class="bg-transparent" style="height: auto;">
|
||||||
<LandingHeader />
|
<LandingHeader />
|
||||||
</q-header>
|
</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-container style="padding-top: 0 !important;">
|
||||||
<q-page>
|
<q-page>
|
||||||
<slot />
|
<slot />
|
||||||
</q-page>
|
</q-page>
|
||||||
</q-page-container>
|
</q-page-container>
|
||||||
|
|
||||||
|
<!-- ส่วนท้ายของเพจ -->
|
||||||
|
<LandingFooter />
|
||||||
|
|
||||||
|
|
||||||
</q-layout>
|
</q-layout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
|
||||||
.font-inter {
|
|
||||||
font-family: 'Inter', sans-serif;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,11 @@ export default defineNuxtConfig({
|
||||||
|
|
||||||
// การตั้งค่า Quasar Framework
|
// การตั้งค่า Quasar Framework
|
||||||
quasar: {
|
quasar: {
|
||||||
|
iconSet: 'material-icons-outlined',
|
||||||
extras: {
|
extras: {
|
||||||
fontIcons: ["material-icons"],
|
fontIcons: [
|
||||||
|
"material-icons",
|
||||||
|
"material-icons-outlined"] // ใช้ไอคอน Material Icons, material-icons-outlined
|
||||||
},
|
},
|
||||||
plugins: ["Notify", "Dialog"], // เปิดใช้ Plugin Notify และ Dialog
|
plugins: ["Notify", "Dialog"], // เปิดใช้ Plugin Notify และ Dialog
|
||||||
config: {
|
config: {
|
||||||
|
|
@ -66,10 +69,11 @@ export default defineNuxtConfig({
|
||||||
{ name: "viewport", content: "width=device-width, initial-scale=1" },
|
{ name: "viewport", content: "width=device-width, initial-scale=1" },
|
||||||
],
|
],
|
||||||
link: [
|
link: [
|
||||||
|
{ rel: 'icon', type: 'image/png', href: '/img/logo.png' },
|
||||||
{
|
{
|
||||||
rel: "stylesheet",
|
rel: "stylesheet",
|
||||||
// โหลด Font: Inter, Prompt, Sarabun
|
// โหลด Font: Inter, Prompt, Sarabun
|
||||||
href: "https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Prompt:wght@300;400;500;600;700;800;900&family=Sarabun:wght@300;400;500;600;700;800&display=swap",
|
href: "https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Prompt:wght@300;400;500;600;700;800;900&family=Sarabun:wght@300;400;500;600;700;800&family=Poppins:wght@300;400;500;600;700;800;900&display=swap",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
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