@venturialstd/social-network 0.0.1
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/constants/content-element.constant.d.ts +14 -0
- package/dist/constants/content-element.constant.d.ts.map +1 -0
- package/dist/constants/content-element.constant.js +18 -0
- package/dist/constants/content-element.constant.js.map +1 -0
- package/dist/constants/feed.constant.d.ts +6 -0
- package/dist/constants/feed.constant.d.ts.map +1 -0
- package/dist/constants/feed.constant.js +9 -0
- package/dist/constants/feed.constant.js.map +1 -0
- package/dist/constants/social-network.constant.d.ts +32 -0
- package/dist/constants/social-network.constant.d.ts.map +1 -0
- package/dist/constants/social-network.constant.js +41 -0
- package/dist/constants/social-network.constant.js.map +1 -0
- package/dist/entities/comment.entity.d.ts +13 -0
- package/dist/entities/comment.entity.d.ts.map +1 -0
- package/dist/entities/comment.entity.js +93 -0
- package/dist/entities/comment.entity.js.map +1 -0
- package/dist/entities/content-hashtag.entity.d.ts +9 -0
- package/dist/entities/content-hashtag.entity.d.ts.map +1 -0
- package/dist/entities/content-hashtag.entity.js +63 -0
- package/dist/entities/content-hashtag.entity.js.map +1 -0
- package/dist/entities/content-music.entity.d.ts +13 -0
- package/dist/entities/content-music.entity.d.ts.map +1 -0
- package/dist/entities/content-music.entity.js +95 -0
- package/dist/entities/content-music.entity.js.map +1 -0
- package/dist/entities/content-tagged-place.entity.d.ts +9 -0
- package/dist/entities/content-tagged-place.entity.d.ts.map +1 -0
- package/dist/entities/content-tagged-place.entity.js +62 -0
- package/dist/entities/content-tagged-place.entity.js.map +1 -0
- package/dist/entities/content-tagged-user.entity.d.ts +9 -0
- package/dist/entities/content-tagged-user.entity.d.ts.map +1 -0
- package/dist/entities/content-tagged-user.entity.js +62 -0
- package/dist/entities/content-tagged-user.entity.js.map +1 -0
- package/dist/entities/follow.entity.d.ts +8 -0
- package/dist/entities/follow.entity.d.ts.map +1 -0
- package/dist/entities/follow.entity.js +55 -0
- package/dist/entities/follow.entity.js.map +1 -0
- package/dist/entities/friend-request.entity.d.ts +12 -0
- package/dist/entities/friend-request.entity.d.ts.map +1 -0
- package/dist/entities/friend-request.entity.js +87 -0
- package/dist/entities/friend-request.entity.js.map +1 -0
- package/dist/entities/friendship.entity.d.ts +12 -0
- package/dist/entities/friendship.entity.d.ts.map +1 -0
- package/dist/entities/friendship.entity.js +88 -0
- package/dist/entities/friendship.entity.js.map +1 -0
- package/dist/entities/post.entity.d.ts +14 -0
- package/dist/entities/post.entity.d.ts.map +1 -0
- package/dist/entities/post.entity.js +99 -0
- package/dist/entities/post.entity.js.map +1 -0
- package/dist/entities/reaction.entity.d.ts +11 -0
- package/dist/entities/reaction.entity.d.ts.map +1 -0
- package/dist/entities/reaction.entity.js +79 -0
- package/dist/entities/reaction.entity.js.map +1 -0
- package/dist/entities/reel.entity.d.ts +13 -0
- package/dist/entities/reel.entity.d.ts.map +1 -0
- package/dist/entities/reel.entity.js +94 -0
- package/dist/entities/reel.entity.js.map +1 -0
- package/dist/entities/save.entity.d.ts +10 -0
- package/dist/entities/save.entity.d.ts.map +1 -0
- package/dist/entities/save.entity.js +64 -0
- package/dist/entities/save.entity.js.map +1 -0
- package/dist/entities/story.entity.d.ts +13 -0
- package/dist/entities/story.entity.d.ts.map +1 -0
- package/dist/entities/story.entity.js +87 -0
- package/dist/entities/story.entity.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/services/comment.service.d.ts +20 -0
- package/dist/services/comment.service.d.ts.map +1 -0
- package/dist/services/comment.service.js +74 -0
- package/dist/services/comment.service.js.map +1 -0
- package/dist/services/content-hashtag.service.d.ts +23 -0
- package/dist/services/content-hashtag.service.d.ts.map +1 -0
- package/dist/services/content-hashtag.service.js +84 -0
- package/dist/services/content-hashtag.service.js.map +1 -0
- package/dist/services/content-music.service.d.ts +26 -0
- package/dist/services/content-music.service.d.ts.map +1 -0
- package/dist/services/content-music.service.js +100 -0
- package/dist/services/content-music.service.js.map +1 -0
- package/dist/services/content-tagged-place.service.d.ts +16 -0
- package/dist/services/content-tagged-place.service.d.ts.map +1 -0
- package/dist/services/content-tagged-place.service.js +66 -0
- package/dist/services/content-tagged-place.service.js.map +1 -0
- package/dist/services/content-tagged-user.service.d.ts +16 -0
- package/dist/services/content-tagged-user.service.d.ts.map +1 -0
- package/dist/services/content-tagged-user.service.js +66 -0
- package/dist/services/content-tagged-user.service.js.map +1 -0
- package/dist/services/feed.service.d.ts +14 -0
- package/dist/services/feed.service.d.ts.map +1 -0
- package/dist/services/feed.service.js +135 -0
- package/dist/services/feed.service.js.map +1 -0
- package/dist/services/follow.service.d.ts +21 -0
- package/dist/services/follow.service.d.ts.map +1 -0
- package/dist/services/follow.service.js +78 -0
- package/dist/services/follow.service.js.map +1 -0
- package/dist/services/friend-request.service.d.ts +16 -0
- package/dist/services/friend-request.service.d.ts.map +1 -0
- package/dist/services/friend-request.service.js +106 -0
- package/dist/services/friend-request.service.js.map +1 -0
- package/dist/services/friendship.service.d.ts +17 -0
- package/dist/services/friendship.service.d.ts.map +1 -0
- package/dist/services/friendship.service.js +79 -0
- package/dist/services/friendship.service.js.map +1 -0
- package/dist/services/post.service.d.ts +10 -0
- package/dist/services/post.service.d.ts.map +1 -0
- package/dist/services/post.service.js +48 -0
- package/dist/services/post.service.js.map +1 -0
- package/dist/services/reaction.service.d.ts +19 -0
- package/dist/services/reaction.service.d.ts.map +1 -0
- package/dist/services/reaction.service.js +88 -0
- package/dist/services/reaction.service.js.map +1 -0
- package/dist/services/reel.service.d.ts +8 -0
- package/dist/services/reel.service.d.ts.map +1 -0
- package/dist/services/reel.service.js +34 -0
- package/dist/services/reel.service.js.map +1 -0
- package/dist/services/save.service.d.ts +17 -0
- package/dist/services/save.service.d.ts.map +1 -0
- package/dist/services/save.service.js +65 -0
- package/dist/services/save.service.js.map +1 -0
- package/dist/services/story.service.d.ts +14 -0
- package/dist/services/story.service.d.ts.map +1 -0
- package/dist/services/story.service.js +50 -0
- package/dist/services/story.service.js.map +1 -0
- package/dist/social-network.module.d.ts +3 -0
- package/dist/social-network.module.d.ts.map +1 -0
- package/dist/social-network.module.js +80 -0
- package/dist/social-network.module.js.map +1 -0
- package/dist/types/content-element.types.d.ts +84 -0
- package/dist/types/content-element.types.d.ts.map +1 -0
- package/dist/types/content-element.types.js +3 -0
- package/dist/types/content-element.types.js.map +1 -0
- package/dist/types/content-music.types.d.ts +8 -0
- package/dist/types/content-music.types.d.ts.map +1 -0
- package/dist/types/content-music.types.js +3 -0
- package/dist/types/content-music.types.js.map +1 -0
- package/dist/types/feed.types.d.ts +28 -0
- package/dist/types/feed.types.d.ts.map +1 -0
- package/dist/types/feed.types.js +3 -0
- package/dist/types/feed.types.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-music.service.js","sourceRoot":"","sources":["../../src/services/content-music.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA0D;AAC1D,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAqC;AAGrC,2EAAgE;AAIzD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,iCAAgC;IAGrD;IAFlB,YAEkB,IAA8B;QAE9C,KAAK,CAAC,IAAI,CAAC,CAAC;QAFI,SAAI,GAAJ,IAAI,CAA0B;IAGhD,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,WAAgC,EAChC,SAAiB,EACjB,IAAmB;QAEnB,IAAI,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;YAChC,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;SACzD,CAAC,CAAC;QACH,IAAI,GAAG,EAAE,CAAC;YACR,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC;YACpC,GAAG,CAA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CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACtB,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,SAAS;YAC3B,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,SAAS;YAC7B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;SAC7B,CAAC,CAAC,CAAC;IACN,CAAC;CACF,CAAA;AA5FY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,mCAAY,CAAC,CAAA;qCACT,oBAAU;GAHvB,mBAAmB,CA4F/B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TypeOrmCrudService } from '@dataui/crud-typeorm';
|
|
2
|
+
import { Repository } from 'typeorm';
|
|
3
|
+
import { TaggableContentType } from '../constants/social-network.constant';
|
|
4
|
+
import { ContentTaggedPlace } from '../entities/content-tagged-place.entity';
|
|
5
|
+
export declare class ContentTaggedPlaceService extends TypeOrmCrudService<ContentTaggedPlace> {
|
|
6
|
+
readonly repo: Repository<ContentTaggedPlace>;
|
|
7
|
+
constructor(repo: Repository<ContentTaggedPlace>);
|
|
8
|
+
tagPlace(contentType: TaggableContentType, contentId: string, placeId: string): Promise<ContentTaggedPlace>;
|
|
9
|
+
untagPlace(contentType: TaggableContentType, contentId: string, placeId: string): Promise<void>;
|
|
10
|
+
getTaggedPlaceIds(contentType: TaggableContentType, contentId: string): Promise<string[]>;
|
|
11
|
+
getContentIdsWherePlaceTagged(placeId: string, contentType: TaggableContentType, options?: {
|
|
12
|
+
take?: number;
|
|
13
|
+
skip?: number;
|
|
14
|
+
}): Promise<string[]>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=content-tagged-place.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-tagged-place.service.d.ts","sourceRoot":"","sources":["../../src/services/content-tagged-place.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAE7E,qBACa,yBAA0B,SAAQ,kBAAkB,CAAC,kBAAkB,CAAC;aAGjE,IAAI,EAAE,UAAU,CAAC,kBAAkB,CAAC;gBAApC,IAAI,EAAE,UAAU,CAAC,kBAAkB,CAAC;IAKhD,QAAQ,CACZ,WAAW,EAAE,mBAAmB,EAChC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,kBAAkB,CAAC;IASxB,UAAU,CACd,WAAW,EAAE,mBAAmB,EAChC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC;IAIV,iBAAiB,CAAC,WAAW,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAQzF,6BAA6B,CACjC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,mBAAmB,EAChC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GACzC,OAAO,CAAC,MAAM,EAAE,CAAC;CAWrB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ContentTaggedPlaceService = void 0;
|
|
16
|
+
const crud_typeorm_1 = require("@dataui/crud-typeorm");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
19
|
+
const typeorm_2 = require("typeorm");
|
|
20
|
+
const content_tagged_place_entity_1 = require("../entities/content-tagged-place.entity");
|
|
21
|
+
let ContentTaggedPlaceService = class ContentTaggedPlaceService extends crud_typeorm_1.TypeOrmCrudService {
|
|
22
|
+
repo;
|
|
23
|
+
constructor(repo) {
|
|
24
|
+
super(repo);
|
|
25
|
+
this.repo = repo;
|
|
26
|
+
}
|
|
27
|
+
async tagPlace(contentType, contentId, placeId) {
|
|
28
|
+
let row = await this.repo.findOne({
|
|
29
|
+
where: { contentType, contentId, placeId },
|
|
30
|
+
});
|
|
31
|
+
if (row)
|
|
32
|
+
return row;
|
|
33
|
+
row = this.repo.create({ contentType, contentId, placeId });
|
|
34
|
+
return this.repo.save(row);
|
|
35
|
+
}
|
|
36
|
+
async untagPlace(contentType, contentId, placeId) {
|
|
37
|
+
await this.repo.delete({ contentType, contentId, placeId });
|
|
38
|
+
}
|
|
39
|
+
async getTaggedPlaceIds(contentType, contentId) {
|
|
40
|
+
const rows = await this.repo.find({
|
|
41
|
+
where: { contentType, contentId },
|
|
42
|
+
select: ['placeId'],
|
|
43
|
+
});
|
|
44
|
+
return rows.map((r) => r.placeId);
|
|
45
|
+
}
|
|
46
|
+
async getContentIdsWherePlaceTagged(placeId, contentType, options) {
|
|
47
|
+
const qb = this.repo
|
|
48
|
+
.createQueryBuilder('t')
|
|
49
|
+
.select('t.contentId')
|
|
50
|
+
.where('t.placeId = :placeId', { placeId })
|
|
51
|
+
.andWhere('t.contentType = :contentType', { contentType });
|
|
52
|
+
if (options?.take)
|
|
53
|
+
qb.take(options.take);
|
|
54
|
+
if (options?.skip)
|
|
55
|
+
qb.skip(options.skip);
|
|
56
|
+
const rows = await qb.orderBy('t.createdAt', 'DESC').getRawMany();
|
|
57
|
+
return rows.map((r) => r.contentId);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.ContentTaggedPlaceService = ContentTaggedPlaceService;
|
|
61
|
+
exports.ContentTaggedPlaceService = ContentTaggedPlaceService = __decorate([
|
|
62
|
+
(0, common_1.Injectable)(),
|
|
63
|
+
__param(0, (0, typeorm_1.InjectRepository)(content_tagged_place_entity_1.ContentTaggedPlace)),
|
|
64
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
65
|
+
], ContentTaggedPlaceService);
|
|
66
|
+
//# sourceMappingURL=content-tagged-place.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-tagged-place.service.js","sourceRoot":"","sources":["../../src/services/content-tagged-place.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA0D;AAC1D,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAqC;AAGrC,yFAA6E;AAGtE,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,iCAAsC;IAGjE;IAFlB,YAEkB,IAAoC;QAEpD,KAAK,CAAC,IAAI,CAAC,CAAC;QAFI,SAAI,GAAJ,IAAI,CAAgC;IAGtD,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,WAAgC,EAChC,SAAiB,EACjB,OAAe;QAEf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AAC,IAAI,CAAC,CAAC;QACzC,IAAI,OAAO,EAAE,IAAI;YAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,UAAU,EAAyB,CAAC;QACzF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;AApDY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,gDAAkB,CAAC,CAAA;qCACf,oBAAU;GAHvB,yBAAyB,CAoDrC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TypeOrmCrudService } from '@dataui/crud-typeorm';
|
|
2
|
+
import { Repository } from 'typeorm';
|
|
3
|
+
import { TaggableContentType } from '../constants/social-network.constant';
|
|
4
|
+
import { ContentTaggedUser } from '../entities/content-tagged-user.entity';
|
|
5
|
+
export declare class ContentTaggedUserService extends TypeOrmCrudService<ContentTaggedUser> {
|
|
6
|
+
readonly repo: Repository<ContentTaggedUser>;
|
|
7
|
+
constructor(repo: Repository<ContentTaggedUser>);
|
|
8
|
+
tagUser(contentType: TaggableContentType, contentId: string, userId: string): Promise<ContentTaggedUser>;
|
|
9
|
+
untagUser(contentType: TaggableContentType, contentId: string, userId: string): Promise<void>;
|
|
10
|
+
getTaggedUserIds(contentType: TaggableContentType, contentId: string): Promise<string[]>;
|
|
11
|
+
getContentIdsWhereUserTagged(userId: string, contentType: TaggableContentType, options?: {
|
|
12
|
+
take?: number;
|
|
13
|
+
skip?: number;
|
|
14
|
+
}): Promise<string[]>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=content-tagged-user.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-tagged-user.service.d.ts","sourceRoot":"","sources":["../../src/services/content-tagged-user.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E,qBACa,wBAAyB,SAAQ,kBAAkB,CAAC,iBAAiB,CAAC;aAG/D,IAAI,EAAE,UAAU,CAAC,iBAAiB,CAAC;gBAAnC,IAAI,EAAE,UAAU,CAAC,iBAAiB,CAAC;IAK/C,OAAO,CACX,WAAW,EAAE,mBAAmB,EAChC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,iBAAiB,CAAC;IASvB,SAAS,CACb,WAAW,EAAE,mBAAmB,EAChC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;IAIV,gBAAgB,CAAC,WAAW,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAQxF,4BAA4B,CAChC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,mBAAmB,EAChC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GACzC,OAAO,CAAC,MAAM,EAAE,CAAC;CAWrB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ContentTaggedUserService = void 0;
|
|
16
|
+
const crud_typeorm_1 = require("@dataui/crud-typeorm");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
19
|
+
const typeorm_2 = require("typeorm");
|
|
20
|
+
const content_tagged_user_entity_1 = require("../entities/content-tagged-user.entity");
|
|
21
|
+
let ContentTaggedUserService = class ContentTaggedUserService extends crud_typeorm_1.TypeOrmCrudService {
|
|
22
|
+
repo;
|
|
23
|
+
constructor(repo) {
|
|
24
|
+
super(repo);
|
|
25
|
+
this.repo = repo;
|
|
26
|
+
}
|
|
27
|
+
async tagUser(contentType, contentId, userId) {
|
|
28
|
+
let row = await this.repo.findOne({
|
|
29
|
+
where: { contentType, contentId, userId },
|
|
30
|
+
});
|
|
31
|
+
if (row)
|
|
32
|
+
return row;
|
|
33
|
+
row = this.repo.create({ contentType, contentId, userId });
|
|
34
|
+
return this.repo.save(row);
|
|
35
|
+
}
|
|
36
|
+
async untagUser(contentType, contentId, userId) {
|
|
37
|
+
await this.repo.delete({ contentType, contentId, userId });
|
|
38
|
+
}
|
|
39
|
+
async getTaggedUserIds(contentType, contentId) {
|
|
40
|
+
const rows = await this.repo.find({
|
|
41
|
+
where: { contentType, contentId },
|
|
42
|
+
select: ['userId'],
|
|
43
|
+
});
|
|
44
|
+
return rows.map((r) => r.userId);
|
|
45
|
+
}
|
|
46
|
+
async getContentIdsWhereUserTagged(userId, contentType, options) {
|
|
47
|
+
const qb = this.repo
|
|
48
|
+
.createQueryBuilder('t')
|
|
49
|
+
.select('t.contentId')
|
|
50
|
+
.where('t.userId = :userId', { userId })
|
|
51
|
+
.andWhere('t.contentType = :contentType', { contentType });
|
|
52
|
+
if (options?.take)
|
|
53
|
+
qb.take(options.take);
|
|
54
|
+
if (options?.skip)
|
|
55
|
+
qb.skip(options.skip);
|
|
56
|
+
const rows = await qb.orderBy('t.createdAt', 'DESC').getRawMany();
|
|
57
|
+
return rows.map((r) => r.contentId);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.ContentTaggedUserService = ContentTaggedUserService;
|
|
61
|
+
exports.ContentTaggedUserService = ContentTaggedUserService = __decorate([
|
|
62
|
+
(0, common_1.Injectable)(),
|
|
63
|
+
__param(0, (0, typeorm_1.InjectRepository)(content_tagged_user_entity_1.ContentTaggedUser)),
|
|
64
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
65
|
+
], ContentTaggedUserService);
|
|
66
|
+
//# sourceMappingURL=content-tagged-user.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-tagged-user.service.js","sourceRoot":"","sources":["../../src/services/content-tagged-user.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA0D;AAC1D,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAqC;AAGrC,uFAA2E;AAGpE,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,iCAAqC;IAG/D;IAFlB,YAEkB,IAAmC;QAEnD,KAAK,CAAC,IAAI,CAAC,CAAC;QAFI,SAAI,GAAJ,IAAI,CAA+B;IAGrD,CAAC;IAED,KAAK,CAAC,OAAO,CACX,WAAgC,EAChC,SAAiB,EACjB,MAAc;QAEd,IAAI,GAAG,GAAG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AAC;QACzC,IAAI,OAAO,EAAE,IAAI;YAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,UAAU,EAAyB,CAAC;QACzF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;AApDY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,8CAAiB,CAAC,CAAA;qCACd,oBAAU;GAHvB,wBAAwB,CAoDpC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { Post } from '../entities/post.entity';
|
|
3
|
+
import { Reel } from '../entities/reel.entity';
|
|
4
|
+
import { FeedOptions, PostFeedItem, ReelFeedItem } from '../types/feed.types';
|
|
5
|
+
export declare class FeedService {
|
|
6
|
+
private readonly postRepo;
|
|
7
|
+
private readonly reelRepo;
|
|
8
|
+
constructor(postRepo: Repository<Post>, reelRepo: Repository<Reel>);
|
|
9
|
+
getFeed(options?: FeedOptions): Promise<PostFeedItem[]>;
|
|
10
|
+
getFeedPostIds(options?: FeedOptions): Promise<string[]>;
|
|
11
|
+
getFeedReels(options?: FeedOptions): Promise<ReelFeedItem[]>;
|
|
12
|
+
getFeedReelIds(options?: FeedOptions): Promise<string[]>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=feed.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feed.service.d.ts","sourceRoot":"","sources":["../../src/services/feed.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIrC,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EACL,WAAW,EAEX,YAAY,EACZ,YAAY,EACb,MAAM,qBAAqB,CAAC;AAE7B,qBACa,WAAW;IAGpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAEzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,EAE1B,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC;IAOvC,OAAO,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAkE3D,cAAc,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAS5D,YAAY,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IA6DhE,cAAc,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAInE"}
|
|
@@ -0,0 +1,135 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.FeedService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
|
+
const typeorm_2 = require("typeorm");
|
|
19
|
+
const social_network_constant_1 = require("../constants/social-network.constant");
|
|
20
|
+
const feed_constant_1 = require("../constants/feed.constant");
|
|
21
|
+
const post_entity_1 = require("../entities/post.entity");
|
|
22
|
+
const reel_entity_1 = require("../entities/reel.entity");
|
|
23
|
+
let FeedService = class FeedService {
|
|
24
|
+
postRepo;
|
|
25
|
+
reelRepo;
|
|
26
|
+
constructor(postRepo, reelRepo) {
|
|
27
|
+
this.postRepo = postRepo;
|
|
28
|
+
this.reelRepo = reelRepo;
|
|
29
|
+
}
|
|
30
|
+
async getFeed(options = {}) {
|
|
31
|
+
const limit = Math.min(options.limit ?? 20, 100);
|
|
32
|
+
const offset = options.offset ?? 0;
|
|
33
|
+
const includeArchived = options.includeArchived ?? false;
|
|
34
|
+
const randomizeTies = options.randomizeTies ?? true;
|
|
35
|
+
const weights = {
|
|
36
|
+
commentWeight: feed_constant_1.DEFAULT_IMPORTANCE_WEIGHTS.commentWeight,
|
|
37
|
+
reactionWeight: feed_constant_1.DEFAULT_IMPORTANCE_WEIGHTS.reactionWeight,
|
|
38
|
+
recencyWeight: feed_constant_1.DEFAULT_IMPORTANCE_WEIGHTS.recencyWeight,
|
|
39
|
+
...options.weights,
|
|
40
|
+
};
|
|
41
|
+
const qb = this.postRepo
|
|
42
|
+
.createQueryBuilder('p')
|
|
43
|
+
.addSelect(`(SELECT COUNT(*)::int FROM social_comment c WHERE c."targetType" = :postType AND c."targetId" = p.id)`, 'comment_count')
|
|
44
|
+
.addSelect(`(SELECT COUNT(*)::int FROM social_reaction r WHERE r."targetType" = :postType AND r."targetId" = p.id)`, 'reaction_count')
|
|
45
|
+
.addSelect(`(1.0 / (1.0 + EXTRACT(EPOCH FROM (NOW() - p."createdAt")) / 86400.0))`, 'recency_factor')
|
|
46
|
+
.setParameter('postType', social_network_constant_1.ContentTargetType.POST);
|
|
47
|
+
if (!includeArchived) {
|
|
48
|
+
qb.andWhere('p.isArchived = :archived', { archived: false });
|
|
49
|
+
}
|
|
50
|
+
if (options.userId) {
|
|
51
|
+
qb.andWhere('p.userId = :userId', { userId: options.userId });
|
|
52
|
+
}
|
|
53
|
+
const scoreExpr = `(
|
|
54
|
+
(SELECT COUNT(*) FROM social_comment c WHERE c."targetType" = 'POST' AND c."targetId" = p.id) * :commentWeight +
|
|
55
|
+
(SELECT COUNT(*) FROM social_reaction r WHERE r."targetType" = 'POST' AND r."targetId" = p.id) * :reactionWeight +
|
|
56
|
+
(1.0 / (1.0 + EXTRACT(EPOCH FROM (NOW() - p."createdAt")) / 86400.0)) * :recencyWeight
|
|
57
|
+
)`;
|
|
58
|
+
qb.addSelect(scoreExpr, 'importance_score')
|
|
59
|
+
.setParameter('commentWeight', weights.commentWeight)
|
|
60
|
+
.setParameter('reactionWeight', weights.reactionWeight)
|
|
61
|
+
.setParameter('recencyWeight', weights.recencyWeight);
|
|
62
|
+
qb.orderBy('importance_score', 'DESC');
|
|
63
|
+
if (randomizeTies) {
|
|
64
|
+
qb.addOrderBy('RANDOM()');
|
|
65
|
+
}
|
|
66
|
+
qb.take(limit).skip(offset);
|
|
67
|
+
const raw = await qb.getRawAndEntities();
|
|
68
|
+
const results = raw.entities.map((post, i) => ({
|
|
69
|
+
post,
|
|
70
|
+
importanceScore: parseFloat(raw.raw[i].importance_score) ?? 0,
|
|
71
|
+
commentCount: parseInt(raw.raw[i].comment_count, 10) ?? 0,
|
|
72
|
+
reactionCount: parseInt(raw.raw[i].reaction_count, 10) ?? 0,
|
|
73
|
+
}));
|
|
74
|
+
return results;
|
|
75
|
+
}
|
|
76
|
+
async getFeedPostIds(options = {}) {
|
|
77
|
+
const items = await this.getFeed({ ...options, limit: options.limit ?? 50 });
|
|
78
|
+
return items.map((item) => item.post.id);
|
|
79
|
+
}
|
|
80
|
+
async getFeedReels(options = {}) {
|
|
81
|
+
const limit = Math.min(options.limit ?? 20, 100);
|
|
82
|
+
const offset = options.offset ?? 0;
|
|
83
|
+
const randomizeTies = options.randomizeTies ?? true;
|
|
84
|
+
const weights = {
|
|
85
|
+
commentWeight: feed_constant_1.DEFAULT_IMPORTANCE_WEIGHTS.commentWeight,
|
|
86
|
+
reactionWeight: feed_constant_1.DEFAULT_IMPORTANCE_WEIGHTS.reactionWeight,
|
|
87
|
+
recencyWeight: feed_constant_1.DEFAULT_IMPORTANCE_WEIGHTS.recencyWeight,
|
|
88
|
+
...options.weights,
|
|
89
|
+
};
|
|
90
|
+
const qb = this.reelRepo
|
|
91
|
+
.createQueryBuilder('r')
|
|
92
|
+
.addSelect(`(SELECT COUNT(*)::int FROM social_comment c WHERE c."targetType" = :reelType AND c."targetId" = r.id)`, 'comment_count')
|
|
93
|
+
.addSelect(`(SELECT COUNT(*)::int FROM social_reaction r2 WHERE r2."targetType" = :reelType AND r2."targetId" = r.id)`, 'reaction_count')
|
|
94
|
+
.addSelect(`(1.0 / (1.0 + EXTRACT(EPOCH FROM (NOW() - r."createdAt")) / 86400.0))`, 'recency_factor')
|
|
95
|
+
.setParameter('reelType', social_network_constant_1.ContentTargetType.REEL);
|
|
96
|
+
if (options.userId) {
|
|
97
|
+
qb.andWhere('r.userId = :userId', { userId: options.userId });
|
|
98
|
+
}
|
|
99
|
+
const scoreExpr = `(
|
|
100
|
+
(SELECT COUNT(*) FROM social_comment c WHERE c."targetType" = 'REEL' AND c."targetId" = r.id) * :commentWeight +
|
|
101
|
+
(SELECT COUNT(*) FROM social_reaction r2 WHERE r2."targetType" = 'REEL' AND r2."targetId" = r.id) * :reactionWeight +
|
|
102
|
+
(1.0 / (1.0 + EXTRACT(EPOCH FROM (NOW() - r."createdAt")) / 86400.0)) * :recencyWeight
|
|
103
|
+
)`;
|
|
104
|
+
qb.addSelect(scoreExpr, 'importance_score')
|
|
105
|
+
.setParameter('commentWeight', weights.commentWeight)
|
|
106
|
+
.setParameter('reactionWeight', weights.reactionWeight)
|
|
107
|
+
.setParameter('recencyWeight', weights.recencyWeight);
|
|
108
|
+
qb.orderBy('importance_score', 'DESC');
|
|
109
|
+
if (randomizeTies) {
|
|
110
|
+
qb.addOrderBy('RANDOM()');
|
|
111
|
+
}
|
|
112
|
+
qb.take(limit).skip(offset);
|
|
113
|
+
const raw = await qb.getRawAndEntities();
|
|
114
|
+
const results = raw.entities.map((reel, i) => ({
|
|
115
|
+
reel,
|
|
116
|
+
importanceScore: parseFloat(raw.raw[i].importance_score) ?? 0,
|
|
117
|
+
commentCount: parseInt(raw.raw[i].comment_count, 10) ?? 0,
|
|
118
|
+
reactionCount: parseInt(raw.raw[i].reaction_count, 10) ?? 0,
|
|
119
|
+
}));
|
|
120
|
+
return results;
|
|
121
|
+
}
|
|
122
|
+
async getFeedReelIds(options = {}) {
|
|
123
|
+
const items = await this.getFeedReels({ ...options, limit: options.limit ?? 50 });
|
|
124
|
+
return items.map((item) => item.reel.id);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
exports.FeedService = FeedService;
|
|
128
|
+
exports.FeedService = FeedService = __decorate([
|
|
129
|
+
(0, common_1.Injectable)(),
|
|
130
|
+
__param(0, (0, typeorm_1.InjectRepository)(post_entity_1.Post)),
|
|
131
|
+
__param(1, (0, typeorm_1.InjectRepository)(reel_entity_1.Reel)),
|
|
132
|
+
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
133
|
+
typeorm_2.Repository])
|
|
134
|
+
], FeedService);
|
|
135
|
+
//# sourceMappingURL=feed.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feed.service.js","sourceRoot":"","sources":["../../src/services/feed.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAqC;AAErC,kFAAyE;AACzE,8DAAwE;AAC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AAW;IADvB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,kBAAI,CAAC,CAAA;IAEtB,WAAA,IAAA,0BAAgB,EAAC,kBAAI,CAAC,CAAA;qCADI,oBAAU;QAEV,oBAAU;GAL5B,WAAW,CAwJvB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TypeOrmCrudService } from '@dataui/crud-typeorm';
|
|
2
|
+
import { Repository } from 'typeorm';
|
|
3
|
+
import { Follow } from '../entities/follow.entity';
|
|
4
|
+
export declare class FollowService extends TypeOrmCrudService<Follow> {
|
|
5
|
+
readonly repo: Repository<Follow>;
|
|
6
|
+
constructor(repo: Repository<Follow>);
|
|
7
|
+
follow(followerId: string, followingId: string): Promise<Follow>;
|
|
8
|
+
unfollow(followerId: string, followingId: string): Promise<void>;
|
|
9
|
+
isFollowing(followerId: string, followingId: string): Promise<boolean>;
|
|
10
|
+
getFollowers(followingId: string, options?: {
|
|
11
|
+
take?: number;
|
|
12
|
+
skip?: number;
|
|
13
|
+
}): Promise<Follow[]>;
|
|
14
|
+
getFollowing(followerId: string, options?: {
|
|
15
|
+
take?: number;
|
|
16
|
+
skip?: number;
|
|
17
|
+
}): Promise<Follow[]>;
|
|
18
|
+
getFollowerCount(followingId: string): Promise<number>;
|
|
19
|
+
getFollowingCount(followerId: string): Promise<number>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=follow.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"follow.service.d.ts","sourceRoot":"","sources":["../../src/services/follow.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAEnD,qBACa,aAAc,SAAQ,kBAAkB,CAAC,MAAM,CAAC;aAGzC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC;gBAAxB,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC;IAKpC,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUhE,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhE,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKtE,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAShG,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAS/F,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAItD,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAG7D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.FollowService = void 0;
|
|
16
|
+
const crud_typeorm_1 = require("@dataui/crud-typeorm");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
19
|
+
const typeorm_2 = require("typeorm");
|
|
20
|
+
const follow_entity_1 = require("../entities/follow.entity");
|
|
21
|
+
let FollowService = class FollowService extends crud_typeorm_1.TypeOrmCrudService {
|
|
22
|
+
repo;
|
|
23
|
+
constructor(repo) {
|
|
24
|
+
super(repo);
|
|
25
|
+
this.repo = repo;
|
|
26
|
+
}
|
|
27
|
+
async follow(followerId, followingId) {
|
|
28
|
+
if (followerId === followingId)
|
|
29
|
+
throw new Error('Cannot follow yourself');
|
|
30
|
+
let follow = await this.repo.findOne({
|
|
31
|
+
where: { followerId, followingId },
|
|
32
|
+
});
|
|
33
|
+
if (follow)
|
|
34
|
+
return follow;
|
|
35
|
+
follow = this.repo.create({ followerId, followingId });
|
|
36
|
+
return this.repo.save(follow);
|
|
37
|
+
}
|
|
38
|
+
async unfollow(followerId, followingId) {
|
|
39
|
+
await this.repo.delete({ followerId, followingId });
|
|
40
|
+
}
|
|
41
|
+
async isFollowing(followerId, followingId) {
|
|
42
|
+
const count = await this.repo.count({ where: { followerId, followingId } });
|
|
43
|
+
return count > 0;
|
|
44
|
+
}
|
|
45
|
+
async getFollowers(followingId, options) {
|
|
46
|
+
const qb = this.repo
|
|
47
|
+
.createQueryBuilder('f')
|
|
48
|
+
.where('f.followingId = :followingId', { followingId });
|
|
49
|
+
if (options?.take)
|
|
50
|
+
qb.take(options.take);
|
|
51
|
+
if (options?.skip)
|
|
52
|
+
qb.skip(options.skip);
|
|
53
|
+
return qb.orderBy('f.createdAt', 'DESC').getMany();
|
|
54
|
+
}
|
|
55
|
+
async getFollowing(followerId, options) {
|
|
56
|
+
const qb = this.repo
|
|
57
|
+
.createQueryBuilder('f')
|
|
58
|
+
.where('f.followerId = :followerId', { followerId });
|
|
59
|
+
if (options?.take)
|
|
60
|
+
qb.take(options.take);
|
|
61
|
+
if (options?.skip)
|
|
62
|
+
qb.skip(options.skip);
|
|
63
|
+
return qb.orderBy('f.createdAt', 'DESC').getMany();
|
|
64
|
+
}
|
|
65
|
+
async getFollowerCount(followingId) {
|
|
66
|
+
return this.repo.count({ where: { followingId } });
|
|
67
|
+
}
|
|
68
|
+
async getFollowingCount(followerId) {
|
|
69
|
+
return this.repo.count({ where: { followerId } });
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
exports.FollowService = FollowService;
|
|
73
|
+
exports.FollowService = FollowService = __decorate([
|
|
74
|
+
(0, common_1.Injectable)(),
|
|
75
|
+
__param(0, (0, typeorm_1.InjectRepository)(follow_entity_1.Follow)),
|
|
76
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
77
|
+
], FollowService);
|
|
78
|
+
//# sourceMappingURL=follow.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"follow.service.js","sourceRoot":"","sources":["../../src/services/follow.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA0D;AAC1D,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAqC;AAErC,6DAAmD;AAG5C,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,iCAA0B;IAGzC;IAFlB,YAEkB,IAAwB;QAExC,KAAK,CAAC,IAAI,CAAC,CAAC;QAFI,SAAI,GAAJ,IAAI,CAAoB;IAG1C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,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,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,UAAkB,EAAE,OAA0C;QAC/E,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI;aACjB,kBAAkB,CAAC,GAAG,CAAC;aACvB,KAAK,CAAC,4BAA4B,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QACvD,IAAI,OAAO,EAAE,IAAI;YAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,OAAO,EAAE,IAAI;YAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,WAAmB;QACxC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,UAAkB;QACxC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC;CACF,CAAA;AApDY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,0BAAgB,EAAC,sBAAM,CAAC,CAAA;qCACH,oBAAU;GAHvB,aAAa,CAoDzB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TypeOrmCrudService } from '@dataui/crud-typeorm';
|
|
2
|
+
import { Repository } from 'typeorm';
|
|
3
|
+
import { FriendRequest } from '../entities/friend-request.entity';
|
|
4
|
+
import { Friendship } from '../entities/friendship.entity';
|
|
5
|
+
export declare class FriendRequestService extends TypeOrmCrudService<FriendRequest> {
|
|
6
|
+
readonly repo: Repository<FriendRequest>;
|
|
7
|
+
private readonly friendshipRepo;
|
|
8
|
+
constructor(repo: Repository<FriendRequest>, friendshipRepo: Repository<Friendship>);
|
|
9
|
+
accept(requestId: string, acceptedByUserId: string): Promise<FriendRequest>;
|
|
10
|
+
reject(requestId: string, rejectedByUserId: string): Promise<FriendRequest>;
|
|
11
|
+
cancel(requestId: string, cancelledByUserId: string): Promise<void>;
|
|
12
|
+
getPendingReceived(userId: string): Promise<FriendRequest[]>;
|
|
13
|
+
getPendingSent(userId: string): Promise<FriendRequest[]>;
|
|
14
|
+
private ensureFriendship;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=friend-request.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"friend-request.service.d.ts","sourceRoot":"","sources":["../../src/services/friend-request.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAMrC,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,qBACa,oBAAqB,SAAQ,kBAAkB,CAAC,aAAa,CAAC;aAGvD,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC;IAE/C,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAFf,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,EAE9B,cAAc,EAAE,UAAU,CAAC,UAAU,CAAC;IAKnD,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAe3E,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAa3E,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYnE,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAO5D,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YAOhD,gBAAgB;CAa/B"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.FriendRequestService = void 0;
|
|
16
|
+
const crud_typeorm_1 = require("@dataui/crud-typeorm");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
19
|
+
const typeorm_2 = require("typeorm");
|
|
20
|
+
const social_network_constant_1 = require("../constants/social-network.constant");
|
|
21
|
+
const friend_request_entity_1 = require("../entities/friend-request.entity");
|
|
22
|
+
const friendship_entity_1 = require("../entities/friendship.entity");
|
|
23
|
+
let FriendRequestService = class FriendRequestService extends crud_typeorm_1.TypeOrmCrudService {
|
|
24
|
+
repo;
|
|
25
|
+
friendshipRepo;
|
|
26
|
+
constructor(repo, friendshipRepo) {
|
|
27
|
+
super(repo);
|
|
28
|
+
this.repo = repo;
|
|
29
|
+
this.friendshipRepo = friendshipRepo;
|
|
30
|
+
}
|
|
31
|
+
async accept(requestId, acceptedByUserId) {
|
|
32
|
+
const request = await this.repo.findOne({ where: { id: requestId } });
|
|
33
|
+
if (!request)
|
|
34
|
+
throw new common_1.NotFoundException(`Friend request ${requestId} not found`);
|
|
35
|
+
if (request.toUserId !== acceptedByUserId) {
|
|
36
|
+
throw new common_1.BadRequestException('Only the recipient can accept this request');
|
|
37
|
+
}
|
|
38
|
+
if (request.status !== social_network_constant_1.FriendRequestStatus.PENDING) {
|
|
39
|
+
throw new common_1.BadRequestException('Request is no longer pending');
|
|
40
|
+
}
|
|
41
|
+
request.status = social_network_constant_1.FriendRequestStatus.ACCEPTED;
|
|
42
|
+
await this.repo.save(request);
|
|
43
|
+
await this.ensureFriendship(request.fromUserId, request.toUserId);
|
|
44
|
+
return request;
|
|
45
|
+
}
|
|
46
|
+
async reject(requestId, rejectedByUserId) {
|
|
47
|
+
const request = await this.repo.findOne({ where: { id: requestId } });
|
|
48
|
+
if (!request)
|
|
49
|
+
throw new common_1.NotFoundException(`Friend request ${requestId} not found`);
|
|
50
|
+
if (request.toUserId !== rejectedByUserId) {
|
|
51
|
+
throw new common_1.BadRequestException('Only the recipient can reject this request');
|
|
52
|
+
}
|
|
53
|
+
if (request.status !== social_network_constant_1.FriendRequestStatus.PENDING) {
|
|
54
|
+
throw new common_1.BadRequestException('Request is no longer pending');
|
|
55
|
+
}
|
|
56
|
+
request.status = social_network_constant_1.FriendRequestStatus.REJECTED;
|
|
57
|
+
return this.repo.save(request);
|
|
58
|
+
}
|
|
59
|
+
async cancel(requestId, cancelledByUserId) {
|
|
60
|
+
const request = await this.repo.findOne({ where: { id: requestId } });
|
|
61
|
+
if (!request)
|
|
62
|
+
throw new common_1.NotFoundException(`Friend request ${requestId} not found`);
|
|
63
|
+
if (request.fromUserId !== cancelledByUserId) {
|
|
64
|
+
throw new common_1.BadRequestException('Only the sender can cancel this request');
|
|
65
|
+
}
|
|
66
|
+
if (request.status !== social_network_constant_1.FriendRequestStatus.PENDING) {
|
|
67
|
+
throw new common_1.BadRequestException('Only pending requests can be cancelled');
|
|
68
|
+
}
|
|
69
|
+
await this.repo.remove(request);
|
|
70
|
+
}
|
|
71
|
+
async getPendingReceived(userId) {
|
|
72
|
+
return this.repo.find({
|
|
73
|
+
where: { toUserId: userId, status: social_network_constant_1.FriendRequestStatus.PENDING },
|
|
74
|
+
order: { createdAt: 'DESC' },
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async getPendingSent(userId) {
|
|
78
|
+
return this.repo.find({
|
|
79
|
+
where: { fromUserId: userId, status: social_network_constant_1.FriendRequestStatus.PENDING },
|
|
80
|
+
order: { createdAt: 'DESC' },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async ensureFriendship(userIdA, userIdB) {
|
|
84
|
+
const [id1, id2] = userIdA < userIdB ? [userIdA, userIdB] : [userIdB, userIdA];
|
|
85
|
+
const existing = await this.friendshipRepo.findOne({
|
|
86
|
+
where: { userId: id1, friendUserId: id2 },
|
|
87
|
+
});
|
|
88
|
+
if (existing)
|
|
89
|
+
return;
|
|
90
|
+
const friendship = this.friendshipRepo.create({
|
|
91
|
+
userId: id1,
|
|
92
|
+
friendUserId: id2,
|
|
93
|
+
status: social_network_constant_1.FriendshipStatus.ACTIVE,
|
|
94
|
+
});
|
|
95
|
+
await this.friendshipRepo.save(friendship);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.FriendRequestService = FriendRequestService;
|
|
99
|
+
exports.FriendRequestService = FriendRequestService = __decorate([
|
|
100
|
+
(0, common_1.Injectable)(),
|
|
101
|
+
__param(0, (0, typeorm_1.InjectRepository)(friend_request_entity_1.FriendRequest)),
|
|
102
|
+
__param(1, (0, typeorm_1.InjectRepository)(friendship_entity_1.Friendship)),
|
|
103
|
+
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
104
|
+
typeorm_2.Repository])
|
|
105
|
+
], FriendRequestService);
|
|
106
|
+
//# sourceMappingURL=friend-request.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"friend-request.service.js","sourceRoot":"","sources":["../../src/services/friend-request.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA0D;AAC1D,2CAAoF;AACpF,6CAAmD;AACnD,qCAAqC;AAErC,kFAG8C;AAC9C,6EAAkE;AAClE,qEAA2D;AAGpD,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,iCAAiC;IAGvD;IAEC;IAJnB,YAEkB,IAA+B,EAE9B,cAAsC;QAEvD,KAAK,CAAC,IAAI,CAAC,CAAC;QAJI,SAAI,GAAJ,IAAI,CAA2B;QAE9B,mBAAc,GAAd,cAAc,CAAwB;IAGzD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,SAAiB,EAAE,gBAAwB;QACtD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,0BAAiB,CAAC,kBAAkB,SAAS,YAAY,CAAC,CAAC;QACnF,IAAI,OAAO,CAAC,QAAQ,KAAK,gBAAgB,EAAE,CAAC;YAC1C,MAAM,IAAI,4BAAmB,CAAC,4CAA4C,CAAC,CAAC;QAC9E,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,6CAAmB,CAAC,OAAO,EAAE,CAAC;YACnD,MAAM,IAAI,4BAAmB,CAAC,8BAA8B,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,CAAC,MAAM,GAAG,6CAAmB,CAAC,QAAQ,CAAC;QAC9C,MAAM,IAAI,CAA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