@common_ch/common 1.0.225 → 1.0.227

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.
@@ -0,0 +1,8 @@
1
+ import { Subjects } from "../../subjects";
2
+ export interface AiSetDefaultShowEvent {
3
+ subject: Subjects.AiSetDefaultShow;
4
+ data: {
5
+ id: string;
6
+ version: number;
7
+ };
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { Subjects } from "../../subjects";
2
+ export interface AiUnSetDefaultShowEvent {
3
+ subject: Subjects.AiUnSetDefaultShow;
4
+ data: {
5
+ id: string;
6
+ version: number;
7
+ };
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -24,6 +24,8 @@ export declare enum Subjects {
24
24
  AiOptionCreated = "ai-option:created",
25
25
  AiOptionUpdated = "ai-option:updated",
26
26
  AiChangeStatus = "ai:changeStatus",
27
+ AiSetDefaultShow = "ai:set-default-show",
28
+ AiUnSetDefaultShow = "ai:unset-default-show",
27
29
  BlogCreated = "blog:created",
28
30
  BlogUpdated = "blog:updated",
29
31
  BlogChangeStatus = "blog:change-status",
@@ -28,6 +28,8 @@ var Subjects;
28
28
  Subjects["AiOptionCreated"] = "ai-option:created";
29
29
  Subjects["AiOptionUpdated"] = "ai-option:updated";
30
30
  Subjects["AiChangeStatus"] = "ai:changeStatus";
31
+ Subjects["AiSetDefaultShow"] = "ai:set-default-show";
32
+ Subjects["AiUnSetDefaultShow"] = "ai:unset-default-show";
31
33
  Subjects["BlogCreated"] = "blog:created";
32
34
  Subjects["BlogUpdated"] = "blog:updated";
33
35
  Subjects["BlogChangeStatus"] = "blog:change-status";
package/build/index.d.ts CHANGED
@@ -26,6 +26,8 @@ export * from './events/portal/org/org-updated-event';
26
26
  export * from './events/portal/ai/ai-created-event';
27
27
  export * from './events/portal/ai/ai-changeStatus-event';
28
28
  export * from './events/portal/ai/ai-update-event';
29
+ export * from './events/portal/ai/ai-set-default-show-event';
30
+ export * from './events/portal/ai/ai-unset-defaultShow-event';
29
31
  export * from './events/portal/ai-option/ai-created-event';
30
32
  export * from './events/portal/ai-option/ai-option-changeStatus-event';
31
33
  export * from './events/portal/ai-option/ai-updated-event';
package/build/index.js CHANGED
@@ -52,6 +52,8 @@ __exportStar(require("./events/portal/org/org-updated-event"), exports);
52
52
  __exportStar(require("./events/portal/ai/ai-created-event"), exports);
53
53
  __exportStar(require("./events/portal/ai/ai-changeStatus-event"), exports);
54
54
  __exportStar(require("./events/portal/ai/ai-update-event"), exports);
55
+ __exportStar(require("./events/portal/ai/ai-set-default-show-event"), exports);
56
+ __exportStar(require("./events/portal/ai/ai-unset-defaultShow-event"), exports);
55
57
  __exportStar(require("./events/portal/ai-option/ai-created-event"), exports);
56
58
  __exportStar(require("./events/portal/ai-option/ai-option-changeStatus-event"), exports);
57
59
  __exportStar(require("./events/portal/ai-option/ai-updated-event"), exports);
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.currentUser = void 0;
7
7
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const redis_service_1 = require("../services/redis/redis.service");
8
9
  const currentUser = (req, res, next) => {
9
10
  const authHeader = req.headers['authorization'];
10
11
  if (!authHeader || !authHeader.startsWith('Bearer')) {
@@ -12,8 +13,16 @@ const currentUser = (req, res, next) => {
12
13
  }
13
14
  try {
14
15
  const token = authHeader.split(' ')[1];
15
- const payload = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY);
16
- req.currentUser = payload;
16
+ (0, redis_service_1.getCache)(token).then((result) => {
17
+ if (result) {
18
+ console.log('user blocked.');
19
+ next();
20
+ }
21
+ else {
22
+ const payload = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY);
23
+ req.currentUser = payload;
24
+ }
25
+ });
17
26
  }
18
27
  catch (err) { }
19
28
  next();
@@ -4,6 +4,7 @@ export interface AiAttrs {
4
4
  _id: string;
5
5
  name: string;
6
6
  status?: AiStatusEnum;
7
+ defaultShow?: boolean;
7
8
  description?: string;
8
9
  description2?: string;
9
10
  image?: string;
@@ -16,6 +17,7 @@ export interface AiDoc extends mongoose.Document {
16
17
  status: AiStatusEnum;
17
18
  version: number;
18
19
  image?: string;
20
+ defaultShow?: boolean;
19
21
  description?: string;
20
22
  description2?: string;
21
23
  createdAt?: number;
@@ -15,6 +15,11 @@ const aiSchema = new mongoose_1.default.Schema({
15
15
  type: String,
16
16
  required: false,
17
17
  },
18
+ defaultShow: {
19
+ type: Boolean,
20
+ required: false,
21
+ default: false,
22
+ },
18
23
  description: {
19
24
  type: String,
20
25
  required: false,
@@ -0,0 +1,3 @@
1
+ export declare function setCache(key: string, value: any, ttlInSeconds?: number): Promise<void>;
2
+ export declare function getCache(key: string): Promise<string | null>;
3
+ export declare function delCache(key: string): Promise<void>;
@@ -0,0 +1,33 @@
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.setCache = setCache;
13
+ exports.getCache = getCache;
14
+ exports.delCache = delCache;
15
+ const redisClient_1 = require("./redisClient");
16
+ function setCache(key_1, value_1) {
17
+ return __awaiter(this, arguments, void 0, function* (key, value, ttlInSeconds = 60 * 60 * 24) {
18
+ yield redisClient_1.redisClient.set(key, value, {
19
+ EX: ttlInSeconds,
20
+ });
21
+ });
22
+ }
23
+ function getCache(key) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const data = yield redisClient_1.redisClient.get(key);
26
+ return data;
27
+ });
28
+ }
29
+ function delCache(key) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ yield redisClient_1.redisClient.del(key);
32
+ });
33
+ }