nestia 3.1.0 → 3.1.1-dev.20221016
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/.eslintrc.cjs +33 -0
- package/.prettierignore +5 -0
- package/.vscode/settings.json +10 -0
- package/demo/encrypted/src/Backend.ts +27 -0
- package/demo/encrypted/src/Configuration.ts +7 -0
- package/demo/encrypted/src/api/HttpError.ts +1 -0
- package/demo/encrypted/src/api/IConnection.ts +1 -0
- package/demo/encrypted/src/api/Primitive.ts +1 -0
- package/demo/encrypted/src/api/__internal/AesPkcs5.ts +1 -0
- package/demo/encrypted/src/api/__internal/Fetcher.ts +1 -0
- package/demo/encrypted/src/api/functional/index.ts +7 -0
- package/demo/encrypted/src/api/functional/sellers/authenticate/index.ts +136 -0
- package/demo/encrypted/src/api/functional/sellers/authenticate/password/index.ts +53 -0
- package/demo/encrypted/src/api/functional/sellers/index.ts +7 -0
- package/demo/encrypted/src/api/index.ts +9 -0
- package/demo/encrypted/src/api/module.ts +10 -0
- package/demo/encrypted/src/api/structures/ISeller.ts +56 -0
- package/demo/encrypted/src/controllers/SellerAuthenticateController.ts +70 -0
- package/demo/encrypted/src/test/features/test_seller_exit.ts +18 -0
- package/demo/encrypted/src/test/features/test_seller_join.ts +19 -0
- package/demo/encrypted/src/test/features/test_seller_login.ts +16 -0
- package/demo/encrypted/src/test/features/test_seller_password_change.ts +18 -0
- package/demo/encrypted/src/test/index.ts +24 -0
- package/demo/encrypted/src/test/internal/DynamicImportIterator.ts +109 -0
- package/demo/encrypted/src/test/internal/StopWatch.ts +15 -0
- package/demo/encrypted/swagger.json +257 -0
- package/demo/encrypted/tsconfig.json +8 -0
- package/demo/generic/nestia.config.ts +10 -0
- package/demo/generic/src/Backend.ts +27 -0
- package/demo/generic/src/Configuration.ts +7 -0
- package/demo/generic/src/api/HttpError.ts +1 -0
- package/demo/generic/src/api/IConnection.ts +1 -0
- package/demo/generic/src/api/Primitive.ts +1 -0
- package/demo/generic/src/api/__internal/AesPkcs5.ts +1 -0
- package/demo/generic/src/api/__internal/Fetcher.ts +1 -0
- package/demo/generic/src/api/functional/consumers/index.ts +7 -0
- package/demo/generic/src/api/functional/consumers/sales/index.ts +8 -0
- package/demo/generic/src/api/functional/consumers/sales/questions/index.ts +136 -0
- package/demo/generic/src/api/functional/consumers/sales/reviews/index.ts +136 -0
- package/demo/generic/src/api/functional/index.ts +7 -0
- package/demo/generic/src/api/index.ts +9 -0
- package/demo/generic/src/api/module.ts +10 -0
- package/demo/generic/src/api/structures/IAttachmentFile.ts +21 -0
- package/demo/generic/src/api/structures/ISaleArticle.ts +79 -0
- package/demo/generic/src/api/structures/ISaleInquiry.ts +34 -0
- package/demo/generic/src/api/structures/ISaleInquiryAnswer.ts +23 -0
- package/demo/generic/src/api/structures/ISaleQuestion.ts +22 -0
- package/demo/generic/src/api/structures/ISaleReview.ts +32 -0
- package/demo/generic/src/controllers/ConsumerSaleQuestionsController.ts +33 -0
- package/demo/generic/src/controllers/ConsumerSaleReviewsController.ts +34 -0
- package/demo/generic/src/controllers/SaleInquiriesController.ts +87 -0
- package/demo/generic/src/test/features/test_question_store.ts +21 -0
- package/demo/generic/src/test/features/test_question_update.ts +42 -0
- package/demo/generic/src/test/features/test_review_store.ts +22 -0
- package/demo/generic/src/test/features/test_review_update.ts +44 -0
- package/demo/generic/src/test/index.ts +24 -0
- package/demo/generic/src/test/internal/DynamicImportIterator.ts +109 -0
- package/demo/generic/src/test/internal/StopWatch.ts +15 -0
- package/demo/generic/swagger.json +736 -0
- package/demo/generic/tsconfig.json +9 -0
- package/demo/multiple-paths/src/Backend.ts +27 -0
- package/demo/multiple-paths/src/Configuration.ts +7 -0
- package/demo/multiple-paths/src/api/HttpError.ts +1 -0
- package/demo/multiple-paths/src/api/IConnection.ts +1 -0
- package/demo/multiple-paths/src/api/Primitive.ts +1 -0
- package/demo/multiple-paths/src/api/__internal/AesPkcs5.ts +1 -0
- package/demo/multiple-paths/src/api/__internal/Fetcher.ts +1 -0
- package/demo/multiple-paths/src/api/functional/consumers/index.ts +7 -0
- package/demo/multiple-paths/src/api/functional/consumers/sales/articles/comments/index.ts +65 -0
- package/demo/multiple-paths/src/api/functional/consumers/sales/articles/index.ts +7 -0
- package/demo/multiple-paths/src/api/functional/consumers/sales/index.ts +7 -0
- package/demo/multiple-paths/src/api/functional/health/alive/index.ts +42 -0
- package/demo/multiple-paths/src/api/functional/health/index.ts +44 -0
- package/demo/multiple-paths/src/api/functional/healthy/alive/index.ts +42 -0
- package/demo/multiple-paths/src/api/functional/healthy/index.ts +44 -0
- package/demo/multiple-paths/src/api/functional/index.ts +10 -0
- package/demo/multiple-paths/src/api/functional/sellers/index.ts +7 -0
- package/demo/multiple-paths/src/api/functional/sellers/sales/articles/comments/index.ts +65 -0
- package/demo/multiple-paths/src/api/functional/sellers/sales/articles/index.ts +7 -0
- package/demo/multiple-paths/src/api/functional/sellers/sales/index.ts +7 -0
- package/demo/multiple-paths/src/api/index.ts +9 -0
- package/demo/multiple-paths/src/api/module.ts +10 -0
- package/demo/multiple-paths/src/api/structures/ISaleArticleComment.ts +93 -0
- package/demo/multiple-paths/src/controllers/HealthController.ts +7 -0
- package/demo/multiple-paths/src/controllers/MultipleController.ts +56 -0
- package/demo/multiple-paths/src/test/features/test_consumer_sale_article_comment_store.ts +21 -0
- package/demo/multiple-paths/src/test/features/test_health_checks.ts +10 -0
- package/demo/multiple-paths/src/test/features/test_seller_sale_article_store.ts +21 -0
- package/demo/multiple-paths/src/test/index.ts +24 -0
- package/demo/multiple-paths/src/test/internal/DynamicImportIterator.ts +109 -0
- package/demo/multiple-paths/src/test/internal/StopWatch.ts +15 -0
- package/demo/multiple-paths/swagger.json +338 -0
- package/demo/multiple-paths/tsconfig.json +3 -0
- package/demo/recursive/src/Backend.ts +27 -0
- package/demo/recursive/src/Configuration.ts +7 -0
- package/demo/recursive/src/api/HttpError.ts +1 -0
- package/demo/recursive/src/api/IConnection.ts +1 -0
- package/demo/recursive/src/api/Primitive.ts +1 -0
- package/demo/recursive/src/api/__internal/AesPkcs5.ts +1 -0
- package/demo/recursive/src/api/__internal/Fetcher.ts +1 -0
- package/demo/recursive/src/api/functional/consumers/index.ts +7 -0
- package/demo/recursive/src/api/functional/consumers/systematic/categories/index.ts +117 -0
- package/demo/recursive/src/api/functional/consumers/systematic/index.ts +7 -0
- package/demo/recursive/src/api/functional/index.ts +7 -0
- package/demo/recursive/src/api/index.ts +9 -0
- package/demo/recursive/src/api/module.ts +10 -0
- package/demo/recursive/src/api/structures/ICategory.ts +49 -0
- package/demo/recursive/src/consumer.categories.controller.ts +59 -0
- package/demo/recursive/src/test/features/test_category_at.ts +11 -0
- package/demo/recursive/src/test/features/test_category_invert.ts +14 -0
- package/demo/recursive/src/test/features/test_category_top.ts +11 -0
- package/demo/recursive/src/test/index.ts +24 -0
- package/demo/recursive/src/test/internal/DynamicImportIterator.ts +109 -0
- package/demo/recursive/src/test/internal/StopWatch.ts +15 -0
- package/demo/recursive/swagger.json +216 -0
- package/demo/recursive/tsconfig.json +3 -0
- package/demo/safe/nestia.config.ts +13 -0
- package/demo/safe/src/Backend.ts +27 -0
- package/demo/safe/src/Configuration.ts +7 -0
- package/demo/safe/src/api/HttpError.ts +1 -0
- package/demo/safe/src/api/IConnection.ts +1 -0
- package/demo/safe/src/api/Primitive.ts +1 -0
- package/demo/safe/src/api/__internal/AesPkcs5.ts +1 -0
- package/demo/safe/src/api/__internal/Fetcher.ts +1 -0
- package/demo/safe/src/api/functional/consumers/index.ts +7 -0
- package/demo/safe/src/api/functional/consumers/sales/articles/comments/index.ts +69 -0
- package/demo/safe/src/api/functional/consumers/sales/articles/index.ts +7 -0
- package/demo/safe/src/api/functional/consumers/sales/index.ts +7 -0
- package/demo/safe/src/api/functional/index.ts +7 -0
- package/demo/safe/src/api/index.ts +9 -0
- package/demo/safe/src/api/module.ts +10 -0
- package/demo/safe/src/api/structures/ISaleArticleComment.ts +93 -0
- package/demo/safe/src/controllers/ConsumerSaleArticleCommentsController.ts +63 -0
- package/demo/safe/src/test/features/test_comment_store.ts +23 -0
- package/demo/safe/src/test/index.ts +24 -0
- package/demo/safe/src/test/internal/DynamicImportIterator.ts +109 -0
- package/demo/safe/src/test/internal/StopWatch.ts +15 -0
- package/demo/safe/swagger.json +217 -0
- package/demo/safe/tsconfig.json +3 -0
- package/demo/tsconfig.base.json +70 -0
- package/demo/union/nestia.config.ts +9 -0
- package/demo/union/src/Backend.ts +27 -0
- package/demo/union/src/Configuration.ts +7 -0
- package/demo/union/src/api/HttpError.ts +1 -0
- package/demo/union/src/api/IConnection.ts +1 -0
- package/demo/union/src/api/Primitive.ts +1 -0
- package/demo/union/src/api/__internal/AesPkcs5.ts +1 -0
- package/demo/union/src/api/__internal/Fetcher.ts +1 -0
- package/demo/union/src/api/functional/consumers/index.ts +7 -0
- package/demo/union/src/api/functional/consumers/sales/entire_articles/index.ts +121 -0
- package/demo/union/src/api/functional/consumers/sales/index.ts +9 -0
- package/demo/union/src/api/functional/consumers/sales/questions/index.ts +57 -0
- package/demo/union/src/api/functional/consumers/sales/reviews/index.ts +54 -0
- package/demo/union/src/api/functional/index.ts +7 -0
- package/demo/union/src/api/index.ts +9 -0
- package/demo/union/src/api/module.ts +10 -0
- package/demo/union/src/api/structures/IAttachmentFile.ts +26 -0
- package/demo/union/src/api/structures/IPage.ts +80 -0
- package/demo/union/src/api/structures/ISaleArticle.ts +107 -0
- package/demo/union/src/api/structures/ISaleEntireArticle.ts +22 -0
- package/demo/union/src/api/structures/ISaleInquiry.ts +56 -0
- package/demo/union/src/api/structures/ISaleInquiryAnswer.ts +23 -0
- package/demo/union/src/api/structures/ISaleQuestion.ts +27 -0
- package/demo/union/src/api/structures/ISaleReview.ts +42 -0
- package/demo/union/src/controllers/ConsumerSaleEntireArticlesController.ts +109 -0
- package/demo/union/src/controllers/ConsumerSaleQuestionsController.ts +45 -0
- package/demo/union/src/controllers/ConsumerSaleReviewsController.ts +44 -0
- package/demo/union/src/test/features/test_sale_entire_articles_at.ts +16 -0
- package/demo/union/src/test/features/test_sale_entire_articles_index.ts +27 -0
- package/demo/union/src/test/index.ts +24 -0
- package/demo/union/src/test/internal/DynamicImportIterator.ts +109 -0
- package/demo/union/src/test/internal/StopWatch.ts +15 -0
- package/demo/union/swagger.json +991 -0
- package/demo/union/tsconfig.json +3 -0
- package/lib/test/TestBuilder.d.ts +4 -0
- package/lib/test/TestBuilder.js +60 -0
- package/lib/test/TestBuilder.js.map +1 -0
- package/lib/test/index.d.ts +1 -0
- package/lib/test/index.js +61 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/test.builder.executor.d.ts +1 -0
- package/lib/test/test.builder.executor.js +24 -0
- package/lib/test/test.builder.executor.js.map +1 -0
- package/package.json +1 -1
- package/prettier.config.js +7 -0
- package/src/IConfiguration.ts +119 -0
- package/src/NestiaApplication.ts +185 -0
- package/src/analyses/ControllerAnalyzer.ts +204 -0
- package/src/analyses/GenericAnalyzer.ts +53 -0
- package/src/analyses/ImportAnalyzer.ts +144 -0
- package/src/analyses/PathAnalyzer.ts +58 -0
- package/src/analyses/ReflectAnalyzer.ts +280 -0
- package/src/analyses/SourceFinder.ts +59 -0
- package/src/executable/internal/CompilerOptions.ts +18 -0
- package/src/executable/internal/NestiaCommand.ts +174 -0
- package/src/executable/internal/NestiaConfig.ts +36 -0
- package/src/executable/internal/NestiaStarter.ts +45 -0
- package/src/executable/internal/nestia.config.getter.ts +11 -0
- package/src/executable/nestia.ts +55 -0
- package/src/generates/FileGenerator.ts +156 -0
- package/src/generates/FunctionGenerator.ts +287 -0
- package/src/generates/SdkGenerator.ts +49 -0
- package/src/generates/SwaggerGenerator.ts +381 -0
- package/src/index.ts +2 -0
- package/src/module.ts +2 -0
- package/src/structures/IController.ts +27 -0
- package/src/structures/IRoute.ts +28 -0
- package/src/structures/ISwagger.ts +55 -0
- package/src/structures/ITypeTuple.ts +6 -0
- package/src/structures/MethodType.ts +11 -0
- package/src/structures/ParamCategory.ts +1 -0
- package/src/structures/TypeEntry.ts +22 -0
- package/src/test/TestBuilder.ts +49 -0
- package/src/test/index.ts +59 -0
- package/src/test/test.builder.executor.ts +11 -0
- package/src/utils/ArrayUtil.ts +26 -0
- package/src/utils/DirectoryUtil.ts +44 -0
- package/src/utils/ImportDictionary.ts +57 -0
- package/src/utils/MapUtil.ts +14 -0
- package/src/utils/StripEnums.ts +10 -0
- package/template/.eslintrc.cjs +22 -0
- package/template/.prettierignore +6 -0
- package/template/prettier.config.js +18 -0
- package/template/tsconfig.json +118 -0
- package/tsconfig.json +82 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module api.functional.consumers.sales.articles.comments
|
|
4
|
+
* @nestia Generated by Nestia - https://github.com/samchon/nestia
|
|
5
|
+
*/
|
|
6
|
+
//================================================================
|
|
7
|
+
import { Fetcher, Primitive } from "nestia-fetcher";
|
|
8
|
+
import type { IConnection } from "nestia-fetcher";
|
|
9
|
+
|
|
10
|
+
import type { ISaleArticleComment } from "./../../../../../structures/ISaleArticleComment";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Store a new comment.
|
|
14
|
+
*
|
|
15
|
+
* Write a comment on a sale article. If you configure the comment to be
|
|
16
|
+
* `anonymous`, only administrator, you and seller of the sale can read
|
|
17
|
+
* the content.
|
|
18
|
+
*
|
|
19
|
+
* @param connection connection Information of the remote HTTP(s) server with headers (+encryption password)
|
|
20
|
+
* @param request Instance of the Express.Request
|
|
21
|
+
* @param sectionCode Code of the target section
|
|
22
|
+
* @param saleId ID of the target sale
|
|
23
|
+
* @param articleId ID of the target article
|
|
24
|
+
* @param input Content to write
|
|
25
|
+
* @return Newly archived comment
|
|
26
|
+
* @throw 400 bad request error when type of the input data is not valid
|
|
27
|
+
* @throw 401 unauthorized error when you've not logged in yet
|
|
28
|
+
* @throw 403 forbidden error when you're a seller and the sale is not yours
|
|
29
|
+
* @throw 404 not found error when unable to find the matched record
|
|
30
|
+
*
|
|
31
|
+
* @controller ConsumerSaleArticleCommentsController.store()
|
|
32
|
+
* @path POST /consumers/:section/sales/:saleId/articles/:articleId/comments
|
|
33
|
+
* @nestia Generated by Nestia - https://github.com/samchon/nestia
|
|
34
|
+
*/
|
|
35
|
+
export function store
|
|
36
|
+
(
|
|
37
|
+
connection: IConnection,
|
|
38
|
+
sectionCode: string,
|
|
39
|
+
saleId: string,
|
|
40
|
+
articleId: string,
|
|
41
|
+
input: Primitive<store.Input>
|
|
42
|
+
): Promise<store.Output>
|
|
43
|
+
{
|
|
44
|
+
return Fetcher.fetch
|
|
45
|
+
(
|
|
46
|
+
connection,
|
|
47
|
+
store.ENCRYPTED,
|
|
48
|
+
store.METHOD,
|
|
49
|
+
store.path(sectionCode, saleId, articleId),
|
|
50
|
+
input
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
export namespace store
|
|
54
|
+
{
|
|
55
|
+
export type Input = Primitive<ISaleArticleComment.IStore>;
|
|
56
|
+
export type Output = Primitive<ISaleArticleComment>;
|
|
57
|
+
|
|
58
|
+
export const METHOD = "POST" as const;
|
|
59
|
+
export const PATH: string = "/consumers/:section/sales/:saleId/articles/:articleId/comments";
|
|
60
|
+
export const ENCRYPTED: Fetcher.IEncrypted = {
|
|
61
|
+
request: false,
|
|
62
|
+
response: false,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export function path(sectionCode: string, saleId: string, articleId: string): string
|
|
66
|
+
{
|
|
67
|
+
return `/consumers/${encodeURIComponent(sectionCode)}/sales/${encodeURIComponent(saleId)}/articles/${encodeURIComponent(articleId)}/comments`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module api
|
|
4
|
+
*/
|
|
5
|
+
//================================================================
|
|
6
|
+
export * from "./IConnection";
|
|
7
|
+
export * from "./Primitive";
|
|
8
|
+
export * from "./HttpError";
|
|
9
|
+
|
|
10
|
+
export * as functional from "./functional";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comment wrote on a sale related article.
|
|
3
|
+
*
|
|
4
|
+
* When an article of a sale has been enrolled, all of the participants like consumers and
|
|
5
|
+
* sellers can write a comment on that article. However, when the writer is a consumer, the
|
|
6
|
+
* consumer can hide its name through the annoymous option.
|
|
7
|
+
*
|
|
8
|
+
* Also, writing a reply comment for a specific comment is possible and in that case, the
|
|
9
|
+
* {@link ISaleArticleComment.parent_id} property would be activated.
|
|
10
|
+
*
|
|
11
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
+
*/
|
|
13
|
+
export interface ISaleArticleComment {
|
|
14
|
+
/**
|
|
15
|
+
* Primary Key.
|
|
16
|
+
*/
|
|
17
|
+
id: number;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Parent comment ID.
|
|
21
|
+
*
|
|
22
|
+
* Only When this comment has been written as a reply.
|
|
23
|
+
*/
|
|
24
|
+
parent_id: number | null;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Type of the writer.
|
|
28
|
+
*/
|
|
29
|
+
writer_type: "seller" | "consumer";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Name of the writer.
|
|
33
|
+
*
|
|
34
|
+
* When this is a type of anonymous comment, writer name would be hidden.
|
|
35
|
+
*/
|
|
36
|
+
writer_name: string | null;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Contents of the comments.
|
|
40
|
+
*
|
|
41
|
+
* When the comment writer tries to modify content, it would not modify the comment
|
|
42
|
+
* content but would be accumulated. Therefore, all of the people can read how
|
|
43
|
+
* the content has been changed.
|
|
44
|
+
*/
|
|
45
|
+
contents: ISaleArticleComment.IContent[];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creation time.
|
|
49
|
+
*/
|
|
50
|
+
created_at: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export namespace ISaleArticleComment {
|
|
54
|
+
/**
|
|
55
|
+
* Store info.
|
|
56
|
+
*/
|
|
57
|
+
export interface IStore {
|
|
58
|
+
/**
|
|
59
|
+
* Body of the content.
|
|
60
|
+
*/
|
|
61
|
+
body: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Extension, content type (format).
|
|
65
|
+
*/
|
|
66
|
+
extension: "html" | "md" | "txt";
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Whether to hide the writer name or not.
|
|
70
|
+
*/
|
|
71
|
+
annonymous: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Content info.
|
|
76
|
+
*/
|
|
77
|
+
export interface IContent {
|
|
78
|
+
/**
|
|
79
|
+
* Primary Key.
|
|
80
|
+
*/
|
|
81
|
+
id: string;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Body of the content.
|
|
85
|
+
*/
|
|
86
|
+
body: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Creation time.
|
|
90
|
+
*/
|
|
91
|
+
created_at: string;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { Controller, Param, Request } from "@nestjs/common";
|
|
3
|
+
import { TypedBody, TypedRoute } from "nestia-helper";
|
|
4
|
+
import { v4 } from "uuid";
|
|
5
|
+
|
|
6
|
+
import { ISaleArticleComment } from "../api/structures/ISaleArticleComment";
|
|
7
|
+
|
|
8
|
+
const CODE_REGEX = "[0-9a-f]{7}";
|
|
9
|
+
const UUID_REGEX =
|
|
10
|
+
"[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}";
|
|
11
|
+
|
|
12
|
+
@Controller(
|
|
13
|
+
`consumers/:section(${CODE_REGEX})/sales/:saleId(${UUID_REGEX})/articles/:articleId(${UUID_REGEX})/comments`,
|
|
14
|
+
)
|
|
15
|
+
export class ConsumerSaleArticleCommentsController {
|
|
16
|
+
/**
|
|
17
|
+
* Store a new comment.
|
|
18
|
+
*
|
|
19
|
+
* Write a comment on a sale article. If you configure the comment to be
|
|
20
|
+
* `anonymous`, only administrator, you and seller of the sale can read
|
|
21
|
+
* the content.
|
|
22
|
+
*
|
|
23
|
+
* @param request Instance of the Express.Request
|
|
24
|
+
* @param sectionCode Code of the target section
|
|
25
|
+
* @param saleId ID of the target sale
|
|
26
|
+
* @param articleId ID of the target article
|
|
27
|
+
* @param input Content to write
|
|
28
|
+
* @return Newly archived comment
|
|
29
|
+
*
|
|
30
|
+
* @throw 400 bad request error when type of the input data is not valid
|
|
31
|
+
* @throw 401 unauthorized error when you've not logged in yet
|
|
32
|
+
* @throw 403 forbidden error when you're a seller and the sale is not yours
|
|
33
|
+
* @throw 404 not found error when unable to find the matched record
|
|
34
|
+
*/
|
|
35
|
+
@TypedRoute.Post()
|
|
36
|
+
public async store(
|
|
37
|
+
@Request() request: express.Request,
|
|
38
|
+
@Param("section") sectionCode: string,
|
|
39
|
+
@Param("saleId") saleId: string,
|
|
40
|
+
@Param("articleId") articleId: string,
|
|
41
|
+
@TypedBody() input: ISaleArticleComment.IStore,
|
|
42
|
+
): Promise<ISaleArticleComment> {
|
|
43
|
+
request;
|
|
44
|
+
sectionCode;
|
|
45
|
+
saleId;
|
|
46
|
+
articleId;
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
id: 0,
|
|
50
|
+
parent_id: null,
|
|
51
|
+
writer_type: "consumer",
|
|
52
|
+
writer_name: input.annonymous ? null : "someone",
|
|
53
|
+
created_at: new Date().toString(),
|
|
54
|
+
contents: [
|
|
55
|
+
{
|
|
56
|
+
id: v4(),
|
|
57
|
+
body: input.body,
|
|
58
|
+
created_at: new Date().toString(),
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import TSON from "typescript-json";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
|
|
4
|
+
import api from "../../api";
|
|
5
|
+
import { ISaleArticleComment } from "../../api/structures/ISaleArticleComment";
|
|
6
|
+
|
|
7
|
+
export async function test_comment_store(
|
|
8
|
+
connection: api.IConnection,
|
|
9
|
+
): Promise<void> {
|
|
10
|
+
const comment: ISaleArticleComment =
|
|
11
|
+
await api.functional.consumers.sales.articles.comments.store(
|
|
12
|
+
connection,
|
|
13
|
+
"abcdef0",
|
|
14
|
+
v4(),
|
|
15
|
+
v4(),
|
|
16
|
+
{
|
|
17
|
+
body: "content-body",
|
|
18
|
+
extension: "md",
|
|
19
|
+
annonymous: true,
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
TSON.assertType(comment);
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import api from "../api";
|
|
2
|
+
import { Backend } from "../Backend";
|
|
3
|
+
import { Configuration } from "../Configuration";
|
|
4
|
+
import { DynamicImportIterator } from "./internal/DynamicImportIterator";
|
|
5
|
+
|
|
6
|
+
async function main(): Promise<void> {
|
|
7
|
+
const server: Backend = new Backend();
|
|
8
|
+
await server.open();
|
|
9
|
+
|
|
10
|
+
const connection: api.IConnection = {
|
|
11
|
+
host: `http://127.0.0.1:${Configuration.PORT}`,
|
|
12
|
+
encryption: Configuration.ENCRYPTION_PASSWORD,
|
|
13
|
+
};
|
|
14
|
+
await DynamicImportIterator.main(__dirname, {
|
|
15
|
+
prefix: "test",
|
|
16
|
+
parameters: () => [connection],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await server.close();
|
|
20
|
+
}
|
|
21
|
+
main().catch((exp) => {
|
|
22
|
+
console.log(exp);
|
|
23
|
+
process.exit(-1);
|
|
24
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const EXTENSION = __filename.substr(-2);
|
|
2
|
+
|
|
3
|
+
import cli from "cli";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import { IPointer } from "tstl/functional/IPointer";
|
|
6
|
+
|
|
7
|
+
import { StopWatch } from "./StopWatch";
|
|
8
|
+
|
|
9
|
+
interface ICommand {
|
|
10
|
+
include?: string;
|
|
11
|
+
exclude?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export namespace DynamicImportIterator {
|
|
15
|
+
export type Closure<Arguments extends any[]> = (
|
|
16
|
+
...args: Arguments
|
|
17
|
+
) => Promise<any>;
|
|
18
|
+
type Module<Arguments extends any[]> = {
|
|
19
|
+
[key: string]: Closure<Arguments>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface IOptions<Parameters extends any[]> {
|
|
23
|
+
prefix: string;
|
|
24
|
+
parameters: () => Parameters;
|
|
25
|
+
wrapper?: (name: string, output: any) => Promise<any>;
|
|
26
|
+
counter?: IPointer<number>;
|
|
27
|
+
showElapsedTime?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function main<Arguments extends any[]>(
|
|
31
|
+
path: string,
|
|
32
|
+
options: IOptions<Arguments>,
|
|
33
|
+
): Promise<void> {
|
|
34
|
+
const command: ICommand = cli.parse();
|
|
35
|
+
await iterate(options, command, path);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function force<Arguments extends any[]>(
|
|
39
|
+
path: string,
|
|
40
|
+
options: IOptions<Arguments>,
|
|
41
|
+
): Promise<Error[]> {
|
|
42
|
+
const command: ICommand = cli.parse();
|
|
43
|
+
const exceptions: Error[] = [];
|
|
44
|
+
|
|
45
|
+
await iterate(options, command, path, exceptions);
|
|
46
|
+
return exceptions;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function iterate<Arguments extends any[]>(
|
|
50
|
+
options: IOptions<Arguments>,
|
|
51
|
+
command: ICommand,
|
|
52
|
+
path: string,
|
|
53
|
+
exceptions?: Error[],
|
|
54
|
+
): Promise<void> {
|
|
55
|
+
const directory: string[] = await fs.promises.readdir(path);
|
|
56
|
+
for (const file of directory) {
|
|
57
|
+
const current: string = `${path}/${file}`;
|
|
58
|
+
const stats: fs.Stats = await fs.promises.lstat(current);
|
|
59
|
+
|
|
60
|
+
if (stats.isDirectory() === true) {
|
|
61
|
+
await iterate(options, command, current, exceptions);
|
|
62
|
+
continue;
|
|
63
|
+
} else if (file.substr(-3) !== `.${EXTENSION}`) continue;
|
|
64
|
+
|
|
65
|
+
const external: Module<Arguments> = await import(current);
|
|
66
|
+
await execute(options, command, external, exceptions);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function execute<Arguments extends any[]>(
|
|
71
|
+
options: IOptions<Arguments>,
|
|
72
|
+
command: ICommand,
|
|
73
|
+
external: Module<Arguments>,
|
|
74
|
+
exceptions?: Error[],
|
|
75
|
+
): Promise<void> {
|
|
76
|
+
for (const key in external) {
|
|
77
|
+
if (command.exclude && key.indexOf(command.exclude) !== -1)
|
|
78
|
+
continue;
|
|
79
|
+
else if (command.include && key.indexOf(command.include) === -1)
|
|
80
|
+
continue;
|
|
81
|
+
else if (key.substr(0, options.prefix.length) !== options.prefix)
|
|
82
|
+
continue;
|
|
83
|
+
else if (external[key] instanceof Function) {
|
|
84
|
+
const closure: Closure<Arguments> = external[key];
|
|
85
|
+
const func = async () => {
|
|
86
|
+
const output = await closure(...options.parameters());
|
|
87
|
+
if (options.wrapper) await options.wrapper(key, output);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
if (options.counter) ++options.counter.value;
|
|
92
|
+
if (options.showElapsedTime === false) {
|
|
93
|
+
await func();
|
|
94
|
+
console.log(` - ${key}`);
|
|
95
|
+
} else {
|
|
96
|
+
const time: number = await StopWatch.measure(func);
|
|
97
|
+
console.log(` - ${key}: ${time.toLocaleString()} ms`);
|
|
98
|
+
}
|
|
99
|
+
} catch (exp) {
|
|
100
|
+
if (!(exp instanceof Error)) return;
|
|
101
|
+
|
|
102
|
+
console.log(` - ${key} -> ${exp.name}`);
|
|
103
|
+
if (exceptions !== undefined) exceptions.push(exp);
|
|
104
|
+
else throw exp;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export namespace StopWatch {
|
|
2
|
+
export type Task = () => Promise<void>;
|
|
3
|
+
|
|
4
|
+
export async function measure(task: Task): Promise<number> {
|
|
5
|
+
const time: number = Date.now();
|
|
6
|
+
await task();
|
|
7
|
+
return Date.now() - time;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function trace(title: string, task: Task): Promise<void> {
|
|
11
|
+
process.stdout.write(title);
|
|
12
|
+
const time: number = await measure(task);
|
|
13
|
+
console.log(`: ${time.toLocaleString()} ms`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.1",
|
|
3
|
+
"servers": [
|
|
4
|
+
{
|
|
5
|
+
"url": "https://github.com/samchon/nestia",
|
|
6
|
+
"description": "insert your server url"
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
"info": {
|
|
10
|
+
"version": "0.1.0",
|
|
11
|
+
"title": "Generated by nestia - https://github.com/samchon/nestia"
|
|
12
|
+
},
|
|
13
|
+
"paths": {
|
|
14
|
+
"/consumers/{section}/sales/{saleId}/articles/{articleId}/comments": {
|
|
15
|
+
"post": {
|
|
16
|
+
"tags": [],
|
|
17
|
+
"parameters": [
|
|
18
|
+
{
|
|
19
|
+
"name": "section",
|
|
20
|
+
"in": "path",
|
|
21
|
+
"description": "Code of the target section",
|
|
22
|
+
"schema": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"nullable": false
|
|
25
|
+
},
|
|
26
|
+
"required": true
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "saleId",
|
|
30
|
+
"in": "path",
|
|
31
|
+
"description": "ID of the target sale",
|
|
32
|
+
"schema": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"nullable": false
|
|
35
|
+
},
|
|
36
|
+
"required": true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "articleId",
|
|
40
|
+
"in": "path",
|
|
41
|
+
"description": "ID of the target article",
|
|
42
|
+
"schema": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"nullable": false
|
|
45
|
+
},
|
|
46
|
+
"required": true
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"requestBody": {
|
|
50
|
+
"description": "Content to write",
|
|
51
|
+
"content": {
|
|
52
|
+
"application/json": {
|
|
53
|
+
"schema": {
|
|
54
|
+
"$ref": "#/components/schemas/ISaleArticleComment.IStore"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"required": true
|
|
59
|
+
},
|
|
60
|
+
"responses": {
|
|
61
|
+
"201": {
|
|
62
|
+
"description": "Newly archived comment",
|
|
63
|
+
"content": {
|
|
64
|
+
"application/json": {
|
|
65
|
+
"schema": {
|
|
66
|
+
"$ref": "#/components/schemas/ISaleArticleComment"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"400": {
|
|
72
|
+
"description": "bad request error when type of the input data is not valid"
|
|
73
|
+
},
|
|
74
|
+
"401": {
|
|
75
|
+
"description": "unauthorized error when you've not logged in yet"
|
|
76
|
+
},
|
|
77
|
+
"403": {
|
|
78
|
+
"description": "forbidden error when you're a seller and the sale is not yours"
|
|
79
|
+
},
|
|
80
|
+
"404": {
|
|
81
|
+
"description": "not found error when unable to find the matched record"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"description": "Store a new comment.\n\nWrite a comment on a sale article. If you configure the comment to be\n`anonymous`, only administrator, you and seller of the sale can read\nthe content."
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"components": {
|
|
89
|
+
"schemas": {
|
|
90
|
+
"ISaleArticleComment.IStore": {
|
|
91
|
+
"type": "object",
|
|
92
|
+
"properties": {
|
|
93
|
+
"body": {
|
|
94
|
+
"type": "string",
|
|
95
|
+
"nullable": false,
|
|
96
|
+
"description": "Body of the content."
|
|
97
|
+
},
|
|
98
|
+
"extension": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"enum": [
|
|
101
|
+
"html",
|
|
102
|
+
"md",
|
|
103
|
+
"txt"
|
|
104
|
+
],
|
|
105
|
+
"nullable": false,
|
|
106
|
+
"description": "Extension, content type (format)."
|
|
107
|
+
},
|
|
108
|
+
"annonymous": {
|
|
109
|
+
"type": "boolean",
|
|
110
|
+
"nullable": false,
|
|
111
|
+
"description": "Whether to hide the writer name or not."
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"nullable": false,
|
|
115
|
+
"required": [
|
|
116
|
+
"body",
|
|
117
|
+
"extension",
|
|
118
|
+
"annonymous"
|
|
119
|
+
],
|
|
120
|
+
"description": "Store info.",
|
|
121
|
+
"jsDocTags": []
|
|
122
|
+
},
|
|
123
|
+
"ISaleArticleComment": {
|
|
124
|
+
"type": "object",
|
|
125
|
+
"properties": {
|
|
126
|
+
"id": {
|
|
127
|
+
"type": "number",
|
|
128
|
+
"nullable": false,
|
|
129
|
+
"description": "Primary Key."
|
|
130
|
+
},
|
|
131
|
+
"parent_id": {
|
|
132
|
+
"type": "number",
|
|
133
|
+
"nullable": true,
|
|
134
|
+
"description": "Parent comment ID.\n\nOnly When this comment has been written as a reply."
|
|
135
|
+
},
|
|
136
|
+
"writer_type": {
|
|
137
|
+
"type": "string",
|
|
138
|
+
"enum": [
|
|
139
|
+
"seller",
|
|
140
|
+
"consumer"
|
|
141
|
+
],
|
|
142
|
+
"nullable": false,
|
|
143
|
+
"description": "Type of the writer."
|
|
144
|
+
},
|
|
145
|
+
"writer_name": {
|
|
146
|
+
"type": "string",
|
|
147
|
+
"nullable": true,
|
|
148
|
+
"description": "Name of the writer.\n\nWhen this is a type of anonymous comment, writer name would be hidden."
|
|
149
|
+
},
|
|
150
|
+
"contents": {
|
|
151
|
+
"type": "array",
|
|
152
|
+
"items": {
|
|
153
|
+
"$ref": "#/components/schemas/ISaleArticleComment.IContent",
|
|
154
|
+
"description": "Contents of the comments.\n\nWhen the comment writer tries to modify content, it would not modify the comment\ncontent but would be accumulated. Therefore, all of the people can read how\nthe content has been changed."
|
|
155
|
+
},
|
|
156
|
+
"nullable": false,
|
|
157
|
+
"description": "Contents of the comments.\n\nWhen the comment writer tries to modify content, it would not modify the comment\ncontent but would be accumulated. Therefore, all of the people can read how\nthe content has been changed."
|
|
158
|
+
},
|
|
159
|
+
"created_at": {
|
|
160
|
+
"type": "string",
|
|
161
|
+
"nullable": false,
|
|
162
|
+
"description": "Creation time."
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"nullable": false,
|
|
166
|
+
"required": [
|
|
167
|
+
"id",
|
|
168
|
+
"parent_id",
|
|
169
|
+
"writer_type",
|
|
170
|
+
"writer_name",
|
|
171
|
+
"contents",
|
|
172
|
+
"created_at"
|
|
173
|
+
],
|
|
174
|
+
"description": "Comment wrote on a sale related article.\n\nWhen an article of a sale has been enrolled, all of the participants like consumers and\nsellers can write a comment on that article. However, when the writer is a consumer, the\nconsumer can hide its name through the annoymous option.\n\nAlso, writing a reply comment for a specific comment is possible and in that case, the\n{@link ISaleArticleComment.parent_id} property would be activated.",
|
|
175
|
+
"jsDocTags": [
|
|
176
|
+
{
|
|
177
|
+
"name": "author",
|
|
178
|
+
"text": [
|
|
179
|
+
{
|
|
180
|
+
"text": "Jeongho Nam - https://github.com/samchon",
|
|
181
|
+
"kind": "text"
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
"ISaleArticleComment.IContent": {
|
|
188
|
+
"type": "object",
|
|
189
|
+
"properties": {
|
|
190
|
+
"id": {
|
|
191
|
+
"type": "string",
|
|
192
|
+
"nullable": false,
|
|
193
|
+
"description": "Primary Key."
|
|
194
|
+
},
|
|
195
|
+
"body": {
|
|
196
|
+
"type": "string",
|
|
197
|
+
"nullable": false,
|
|
198
|
+
"description": "Body of the content."
|
|
199
|
+
},
|
|
200
|
+
"created_at": {
|
|
201
|
+
"type": "string",
|
|
202
|
+
"nullable": false,
|
|
203
|
+
"description": "Creation time."
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
"nullable": false,
|
|
207
|
+
"required": [
|
|
208
|
+
"id",
|
|
209
|
+
"body",
|
|
210
|
+
"created_at"
|
|
211
|
+
],
|
|
212
|
+
"description": "Content info.",
|
|
213
|
+
"jsDocTags": []
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|