@comasoft/nestjs 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/decorators/api-custom-params.decorator.d.ts +7 -0
- package/dist/decorators/api-custom-params.decorator.js +35 -0
- package/dist/decorators/auth.decorator.factory.d.ts +1 -0
- package/dist/decorators/auth.decorator.factory.js +12 -0
- package/dist/decorators/cookies.decorator.d.ts +1 -0
- package/dist/decorators/cookies.decorator.js +9 -0
- package/dist/decorators/custom-params.decorator.d.ts +1 -0
- package/dist/decorators/custom-params.decorator.js +16 -0
- package/dist/decorators/index.d.ts +6 -0
- package/dist/decorators/index.js +22 -0
- package/dist/decorators/patch-body.decorator.d.ts +1 -0
- package/dist/decorators/patch-body.decorator.js +30 -0
- package/dist/decorators/user.decorator.d.ts +1 -0
- package/dist/decorators/user.decorator.js +8 -0
- package/dist/dto/auth-user-local.dto.d.ts +4 -0
- package/dist/dto/auth-user-local.dto.js +26 -0
- package/dist/dto/custom-params.dto.d.ts +7 -0
- package/dist/dto/custom-params.dto.js +46 -0
- package/dist/dto/index.d.ts +6 -0
- package/dist/dto/index.js +22 -0
- package/dist/dto/jwt-user.dto.d.ts +6 -0
- package/dist/dto/jwt-user.dto.js +6 -0
- package/dist/dto/pagination.dto.d.ts +8 -0
- package/dist/dto/pagination.dto.js +36 -0
- package/dist/dto/response-access-token.dto.d.ts +3 -0
- package/dist/dto/response-access-token.dto.js +24 -0
- package/dist/dto/response-id.dto.d.ts +6 -0
- package/dist/dto/response-id.dto.js +27 -0
- package/dist/enums.common.d.ts +29 -0
- package/dist/enums.common.js +35 -0
- package/dist/filters/http-exception.filter.d.ts +4 -0
- package/dist/filters/http-exception.filter.js +53 -0
- package/dist/filters/index.d.ts +1 -0
- package/dist/filters/index.js +17 -0
- package/dist/guards/auth.guard.d.ts +8 -0
- package/dist/guards/auth.guard.js +38 -0
- package/dist/guards/jwt.guard.d.ts +4 -0
- package/dist/guards/jwt.guard.js +17 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +24 -0
- package/dist/interceptors/error.interceptor.d.ts +5 -0
- package/dist/interceptors/error.interceptor.js +26 -0
- package/dist/interceptors/index.d.ts +2 -0
- package/dist/interceptors/index.js +18 -0
- package/dist/interceptors/success.interceptor.d.ts +5 -0
- package/dist/interceptors/success.interceptor.js +30 -0
- package/dist/passport/jwt.strategy.d.ts +6 -0
- package/dist/passport/jwt.strategy.js +55 -0
- package/dist/passport/kakao.strategy.d.ts +12 -0
- package/dist/passport/kakao.strategy.js +36 -0
- package/dist/passport/local.strategy.d.ts +6 -0
- package/dist/passport/local.strategy.js +41 -0
- package/dist/setup-swagger.d.ts +9 -0
- package/dist/setup-swagger.js +32 -0
- package/dist/utils/common.utils.d.ts +2 -0
- package/dist/utils/common.utils.js +28 -0
- package/dist/utils/enum.utils.d.ts +1 -0
- package/dist/utils/enum.utils.js +8 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/pagination-qb.utils.d.ts +8 -0
- package/dist/utils/pagination-qb.utils.js +52 -0
- package/dist/utils/pagination.utils.d.ts +21 -0
- package/dist/utils/pagination.utils.js +32 -0
- package/eslint.config.js +31 -0
- package/package.json +45 -0
- package/tsconfig.build.json +19 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.JwtAuthGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const passport_1 = require("@nestjs/passport");
|
|
12
|
+
let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)('jwt') {
|
|
13
|
+
};
|
|
14
|
+
exports.JwtAuthGuard = JwtAuthGuard;
|
|
15
|
+
exports.JwtAuthGuard = JwtAuthGuard = __decorate([
|
|
16
|
+
(0, common_1.Injectable)()
|
|
17
|
+
], JwtAuthGuard);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./enums.common"), exports);
|
|
18
|
+
__exportStar(require("./decorators"), exports);
|
|
19
|
+
__exportStar(require("./dto"), exports);
|
|
20
|
+
__exportStar(require("./filters"), exports);
|
|
21
|
+
__exportStar(require("./interceptors"), exports);
|
|
22
|
+
__exportStar(require("./utils"), exports);
|
|
23
|
+
__exportStar(require("./setup-swagger"), exports);
|
|
24
|
+
__exportStar(require("./passport/jwt.strategy"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ErrorInterceptor = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const rxjs_1 = require("rxjs");
|
|
12
|
+
const operators_1 = require("rxjs/operators");
|
|
13
|
+
let ErrorInterceptor = class ErrorInterceptor {
|
|
14
|
+
intercept(context, next) {
|
|
15
|
+
return next.handle().pipe((0, operators_1.catchError)((error) => {
|
|
16
|
+
if (error instanceof common_1.NotFoundException) {
|
|
17
|
+
return (0, rxjs_1.throwError)(() => error);
|
|
18
|
+
}
|
|
19
|
+
return (0, rxjs_1.throwError)(() => new common_1.InternalServerErrorException('An unexpected error occurred'));
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.ErrorInterceptor = ErrorInterceptor;
|
|
24
|
+
exports.ErrorInterceptor = ErrorInterceptor = __decorate([
|
|
25
|
+
(0, common_1.Injectable)()
|
|
26
|
+
], ErrorInterceptor);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./error.interceptor"), exports);
|
|
18
|
+
__exportStar(require("./success.interceptor"), exports);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SuccessInterceptor = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const operators_1 = require("rxjs/operators");
|
|
12
|
+
let SuccessInterceptor = class SuccessInterceptor {
|
|
13
|
+
intercept(context, next) {
|
|
14
|
+
return next.handle().pipe((0, operators_1.map)((v) => {
|
|
15
|
+
if (v && (v.access_token || v.refresh_token)) {
|
|
16
|
+
return Object.assign({ success: true }, v);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return {
|
|
20
|
+
success: true,
|
|
21
|
+
data: v,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.SuccessInterceptor = SuccessInterceptor;
|
|
28
|
+
exports.SuccessInterceptor = SuccessInterceptor = __decorate([
|
|
29
|
+
(0, common_1.Injectable)()
|
|
30
|
+
], SuccessInterceptor);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
21
|
+
var t = {};
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
23
|
+
t[p] = s[p];
|
|
24
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
25
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
26
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
27
|
+
t[p[i]] = s[p[i]];
|
|
28
|
+
}
|
|
29
|
+
return t;
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.JwtStrategy = void 0;
|
|
33
|
+
const passport_jwt_1 = require("passport-jwt");
|
|
34
|
+
const passport_1 = require("@nestjs/passport");
|
|
35
|
+
const common_1 = require("@nestjs/common");
|
|
36
|
+
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
|
37
|
+
constructor(secretKey) {
|
|
38
|
+
super({
|
|
39
|
+
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
40
|
+
ignoreExpiration: false,
|
|
41
|
+
secretOrKey: secretKey,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
validate(payload) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const { sub } = payload, rest = __rest(payload, ["sub"]);
|
|
47
|
+
return Object.assign({ id: sub }, rest);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.JwtStrategy = JwtStrategy;
|
|
52
|
+
exports.JwtStrategy = JwtStrategy = __decorate([
|
|
53
|
+
(0, common_1.Injectable)(),
|
|
54
|
+
__metadata("design:paramtypes", [String])
|
|
55
|
+
], JwtStrategy);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const KakaoStrategy_base: new (...args: any[]) => any;
|
|
2
|
+
export declare class KakaoStrategy extends KakaoStrategy_base {
|
|
3
|
+
constructor();
|
|
4
|
+
validate(accessToken: string, refreshToken: string, profile: any): Promise<{
|
|
5
|
+
vendor_id: any;
|
|
6
|
+
name: any;
|
|
7
|
+
nickname: any;
|
|
8
|
+
email: any;
|
|
9
|
+
profile_image: any;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.KakaoStrategy = void 0;
|
|
13
|
+
const passport_1 = require("@nestjs/passport");
|
|
14
|
+
const passport_kakao_1 = require("passport-kakao");
|
|
15
|
+
class KakaoStrategy extends (0, passport_1.PassportStrategy)(passport_kakao_1.Strategy, "kakao") {
|
|
16
|
+
constructor() {
|
|
17
|
+
super({
|
|
18
|
+
clientID: process.env.KAKAO_CLIENT_ID,
|
|
19
|
+
clientSecret: process.env.KAKAO_CLIENT_SECRET,
|
|
20
|
+
callbackURL: process.env.KAKAO_CALLBACK_URL,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
validate(accessToken, refreshToken, profile) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const { properties, kakao_account } = profile._json;
|
|
26
|
+
return {
|
|
27
|
+
vendor_id: profile.id,
|
|
28
|
+
name: profile.displayName,
|
|
29
|
+
nickname: properties === null || properties === void 0 ? void 0 : properties.nickname,
|
|
30
|
+
email: kakao_account === null || kakao_account === void 0 ? void 0 : kakao_account.email,
|
|
31
|
+
profile_image: properties === null || properties === void 0 ? void 0 : properties.profile_image,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.KakaoStrategy = KakaoStrategy;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.LocalStrategy = void 0;
|
|
22
|
+
const passport_local_1 = require("passport-local");
|
|
23
|
+
const passport_1 = require("@nestjs/passport");
|
|
24
|
+
const common_1 = require("@nestjs/common");
|
|
25
|
+
let LocalStrategy = class LocalStrategy extends (0, passport_1.PassportStrategy)(passport_local_1.Strategy) {
|
|
26
|
+
constructor() {
|
|
27
|
+
super({
|
|
28
|
+
usernameField: 'userid',
|
|
29
|
+
passwordField: 'password',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
validate(userid, password) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.LocalStrategy = LocalStrategy;
|
|
38
|
+
exports.LocalStrategy = LocalStrategy = __decorate([
|
|
39
|
+
(0, common_1.Injectable)(),
|
|
40
|
+
__metadata("design:paramtypes", [])
|
|
41
|
+
], LocalStrategy);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { INestApplication } from '@nestjs/common';
|
|
2
|
+
export interface SwaggerConfig {
|
|
3
|
+
title: string;
|
|
4
|
+
description: string;
|
|
5
|
+
version: string;
|
|
6
|
+
uri: string;
|
|
7
|
+
}
|
|
8
|
+
declare function setupSwagger(app: INestApplication, config: SwaggerConfig): void;
|
|
9
|
+
export { setupSwagger };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupSwagger = setupSwagger;
|
|
4
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
5
|
+
function setupSwagger(app, config) {
|
|
6
|
+
const swaggerConfig = new swagger_1.DocumentBuilder()
|
|
7
|
+
.setTitle(config.title)
|
|
8
|
+
.setDescription(config.description)
|
|
9
|
+
.setVersion(config.version)
|
|
10
|
+
.addBearerAuth({
|
|
11
|
+
type: 'http',
|
|
12
|
+
bearerFormat: 'Bearer',
|
|
13
|
+
scheme: 'Bearer',
|
|
14
|
+
name: 'Authorization',
|
|
15
|
+
in: 'header',
|
|
16
|
+
}, 'access_token')
|
|
17
|
+
.addCookieAuth('refresh_token', {
|
|
18
|
+
type: 'apiKey',
|
|
19
|
+
in: 'cookie',
|
|
20
|
+
name: 'refresh_token',
|
|
21
|
+
})
|
|
22
|
+
.build();
|
|
23
|
+
const document = swagger_1.SwaggerModule.createDocument(app, swaggerConfig);
|
|
24
|
+
swagger_1.SwaggerModule.setup(config.uri, app, document, {
|
|
25
|
+
swaggerOptions: {
|
|
26
|
+
persistAuthorization: true,
|
|
27
|
+
defaultModelsExpandDepth: -1,
|
|
28
|
+
defaultModelExpandDepth: -1,
|
|
29
|
+
docExpansion: 'none',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertExpirationToSeconds = exports.generateOrderId = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
const generateOrderId = () => {
|
|
6
|
+
const date_part = (0, date_fns_1.format)(new Date(), 'yyMMdd');
|
|
7
|
+
const full_timestamp = Date.now().toString();
|
|
8
|
+
const short_timestamp = full_timestamp.slice(-7);
|
|
9
|
+
return `${date_part}-${short_timestamp}`;
|
|
10
|
+
};
|
|
11
|
+
exports.generateOrderId = generateOrderId;
|
|
12
|
+
const convertExpirationToSeconds = (expiration) => {
|
|
13
|
+
const unit = expiration.slice(-1);
|
|
14
|
+
const value = parseInt(expiration.slice(0, -1), 10);
|
|
15
|
+
switch (unit) {
|
|
16
|
+
case 'd':
|
|
17
|
+
return value * 24 * 60 * 60;
|
|
18
|
+
case 'h':
|
|
19
|
+
return value * 60 * 60;
|
|
20
|
+
case 'm':
|
|
21
|
+
return value * 60;
|
|
22
|
+
case 's':
|
|
23
|
+
return value;
|
|
24
|
+
default:
|
|
25
|
+
throw new Error('Invalid expiration format');
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.convertExpirationToSeconds = convertExpirationToSeconds;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const valueToEnum: <T>(enumObj: T, value: string) => T[keyof T] | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.valueToEnum = void 0;
|
|
4
|
+
const valueToEnum = (enumObj, value) => {
|
|
5
|
+
const enumKey = Object.keys(enumObj).find((key) => enumObj[key] === value);
|
|
6
|
+
return enumKey ? enumObj[enumKey] : undefined;
|
|
7
|
+
};
|
|
8
|
+
exports.valueToEnum = valueToEnum;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common.utils"), exports);
|
|
18
|
+
__exportStar(require("./enum.utils"), exports);
|
|
19
|
+
__exportStar(require("./pagination.utils"), exports);
|
|
20
|
+
__exportStar(require("./pagination-qb.utils"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SelectQueryBuilder } from 'typeorm';
|
|
2
|
+
export declare function applyFiltersAndSorting<T>(queryBuilder: SelectQueryBuilder<T>, options: {
|
|
3
|
+
_keyword?: string;
|
|
4
|
+
_group?: string;
|
|
5
|
+
_sort?: string;
|
|
6
|
+
aliasName?: string;
|
|
7
|
+
keywordFields?: string[];
|
|
8
|
+
}): SelectQueryBuilder<T>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyFiltersAndSorting = applyFiltersAndSorting;
|
|
4
|
+
function applyFiltersAndSorting(queryBuilder, options) {
|
|
5
|
+
const { _keyword, _group, _sort, aliasName = 'a', keywordFields = ['name'], } = options;
|
|
6
|
+
applyKeywordFilter(queryBuilder, _keyword, aliasName, keywordFields);
|
|
7
|
+
applyGroupFilter(queryBuilder, _group, aliasName);
|
|
8
|
+
applySorting(queryBuilder, _sort, aliasName);
|
|
9
|
+
return queryBuilder;
|
|
10
|
+
}
|
|
11
|
+
function applyKeywordFilter(queryBuilder, keyword, aliasName, keywordFields) {
|
|
12
|
+
if (keyword) {
|
|
13
|
+
const keywordConditions = keywordFields.map((field) => `${aliasName}.${field} LIKE :keyword`);
|
|
14
|
+
queryBuilder.andWhere(`(${keywordConditions.join(' OR ')})`, {
|
|
15
|
+
keyword: `%${keyword}%`,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function applyGroupFilter(queryBuilder, group, aliasName) {
|
|
20
|
+
if (group) {
|
|
21
|
+
const groups = group.split('|');
|
|
22
|
+
const conditions = [];
|
|
23
|
+
const parameters = {};
|
|
24
|
+
groups.forEach((g, index) => {
|
|
25
|
+
const [field, value] = g.split('-');
|
|
26
|
+
conditions.push(`${aliasName}.${field} = :${field}${index}`);
|
|
27
|
+
parameters[`${field}${index}`] = value;
|
|
28
|
+
});
|
|
29
|
+
queryBuilder.andWhere(`(${conditions.join(' AND ')})`, parameters);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function applySorting(queryBuilder, sort, aliasName) {
|
|
33
|
+
if (sort) {
|
|
34
|
+
const sorts = sort.split('|');
|
|
35
|
+
sorts.forEach((s, index) => {
|
|
36
|
+
const [field, order] = s.split('-');
|
|
37
|
+
const normalizedOrder = order.toUpperCase();
|
|
38
|
+
if (normalizedOrder !== 'ASC' && normalizedOrder !== 'DESC') {
|
|
39
|
+
throw new Error(`Invalid sort order: ${order}`);
|
|
40
|
+
}
|
|
41
|
+
if (index === 0) {
|
|
42
|
+
queryBuilder.orderBy(`${aliasName}.${field}`, normalizedOrder);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
queryBuilder.addOrderBy(`${aliasName}.${field}`, normalizedOrder);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
queryBuilder.orderBy(`${aliasName}.id`, 'DESC');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SelectQueryBuilder } from 'typeorm';
|
|
2
|
+
export interface CustomPaginationMeta {
|
|
3
|
+
page: number;
|
|
4
|
+
limit: number;
|
|
5
|
+
count: number;
|
|
6
|
+
count_total: number;
|
|
7
|
+
count_page: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function paginate<T>(queryBuilder: SelectQueryBuilder<T>, options: {
|
|
10
|
+
page: number;
|
|
11
|
+
limit: number;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
items: T[];
|
|
14
|
+
pagination: {
|
|
15
|
+
page: number;
|
|
16
|
+
limit: number;
|
|
17
|
+
count: number;
|
|
18
|
+
count_total: number;
|
|
19
|
+
count_page: number;
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.paginate = paginate;
|
|
13
|
+
function paginate(queryBuilder, options) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { page, limit } = options;
|
|
16
|
+
const [items, total] = yield queryBuilder
|
|
17
|
+
.skip((page - 1) * limit)
|
|
18
|
+
.take(limit)
|
|
19
|
+
.getManyAndCount();
|
|
20
|
+
const totalPages = Math.ceil(total / limit);
|
|
21
|
+
return {
|
|
22
|
+
items,
|
|
23
|
+
pagination: {
|
|
24
|
+
page,
|
|
25
|
+
limit,
|
|
26
|
+
count: items.length,
|
|
27
|
+
count_total: total,
|
|
28
|
+
count_page: totalPages,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const typescript = require("@typescript-eslint/eslint-plugin");
|
|
2
|
+
const typescriptParser = require("@typescript-eslint/parser");
|
|
3
|
+
|
|
4
|
+
module.exports = [
|
|
5
|
+
{
|
|
6
|
+
files: ["lib/**/*.ts"],
|
|
7
|
+
languageOptions: {
|
|
8
|
+
parser: typescriptParser,
|
|
9
|
+
parserOptions: {
|
|
10
|
+
project: "./tsconfig.json",
|
|
11
|
+
sourceType: "module",
|
|
12
|
+
},
|
|
13
|
+
globals: {
|
|
14
|
+
node: true,
|
|
15
|
+
jest: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
plugins: {
|
|
19
|
+
"@typescript-eslint": typescript,
|
|
20
|
+
},
|
|
21
|
+
rules: {
|
|
22
|
+
"@typescript-eslint/interface-name-prefix": "off",
|
|
23
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
24
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
25
|
+
"@typescript-eslint/no-use-before-define": "off",
|
|
26
|
+
"@typescript-eslint/no-unused-vars": "off",
|
|
27
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
28
|
+
"@typescript-eslint/ban-types": "off",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@comasoft/nestjs",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"private": false,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc -p tsconfig.build.json",
|
|
8
|
+
"lint": "eslint 'lib/**/*.ts' --fix"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@nestjs/common": "10.4.15",
|
|
15
|
+
"@nestjs/core": "10.4.15",
|
|
16
|
+
"@nestjs/passport": "10.0.3",
|
|
17
|
+
"@nestjs/swagger": "8.1.0",
|
|
18
|
+
"class-transformer": "0.5.1",
|
|
19
|
+
"class-validator": "0.14.1",
|
|
20
|
+
"date-fns": "4.1.0",
|
|
21
|
+
"express": "4.21.2",
|
|
22
|
+
"passport-jwt": "4.0.1",
|
|
23
|
+
"passport-kakao": "1.0.1",
|
|
24
|
+
"passport-local": "1.0.0",
|
|
25
|
+
"rxjs": "7.8.1",
|
|
26
|
+
"typeorm": "0.3.20"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"eslint": "9.16.0",
|
|
30
|
+
"eslint-config-prettier": "9.1.0",
|
|
31
|
+
"eslint-plugin-import": "2.31.0",
|
|
32
|
+
"@types/node": "22.10.2",
|
|
33
|
+
"typescript": "5.7.2",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "8.18.0",
|
|
35
|
+
"@typescript-eslint/parser": "8.18.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@nestjs/common": "10.4.15",
|
|
39
|
+
"@nestjs/core": "10.4.15",
|
|
40
|
+
"@nestjs/passport": "10.0.3",
|
|
41
|
+
"@nestjs/swagger": "8.1.0",
|
|
42
|
+
"class-transformer": "0.5.1",
|
|
43
|
+
"class-validator": "0.14.1"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"noImplicitAny": false,
|
|
7
|
+
"removeComments": true,
|
|
8
|
+
"noLib": false,
|
|
9
|
+
"emitDecoratorMetadata": true,
|
|
10
|
+
"experimentalDecorators": true,
|
|
11
|
+
"target": "es6",
|
|
12
|
+
"sourceMap": false,
|
|
13
|
+
"outDir": "./dist",
|
|
14
|
+
"rootDir": "./lib",
|
|
15
|
+
"skipLibCheck": true
|
|
16
|
+
},
|
|
17
|
+
"include": ["lib/**/*"],
|
|
18
|
+
"exclude": ["node_modules", "test", "dist", "**/*spec.ts", "e2e"]
|
|
19
|
+
}
|