@candlerip/shared3 0.0.159 → 0.0.160

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/package.json +1 -1
  2. package/src/backend/database/aggregate/index.d.ts +2 -0
  3. package/src/backend/database/aggregate/index.js +2 -0
  4. package/src/backend/database/aggregate/person-birth-place-country/config.d.ts +2 -0
  5. package/src/backend/database/aggregate/person-birth-place-country/config.js +16 -0
  6. package/src/backend/database/aggregate/person-birth-place-country/index.d.ts +1 -0
  7. package/src/backend/database/aggregate/person-birth-place-country/index.js +1 -0
  8. package/src/backend/database/aggregate/person-candles-count/config.d.ts +2 -0
  9. package/src/backend/database/aggregate/person-candles-count/config.js +47 -0
  10. package/src/backend/database/aggregate/person-candles-count/index.d.ts +1 -0
  11. package/src/backend/database/aggregate/person-candles-count/index.js +1 -0
  12. package/src/backend/database/model/index.d.ts +1 -0
  13. package/src/backend/database/model/index.js +1 -0
  14. package/src/backend/database/model/person/get-person-db-model.d.ts +2 -0
  15. package/src/backend/database/model/person/get-person-db-model.js +3 -0
  16. package/src/backend/database/model/person/index.d.ts +2 -0
  17. package/src/backend/database/model/person/index.js +2 -0
  18. package/src/backend/database/model/person/person-db-schema.d.ts +102 -0
  19. package/src/backend/database/model/person/person-db-schema.js +71 -0
  20. package/src/backend/database/mutation/index.d.ts +1 -0
  21. package/src/backend/database/mutation/index.js +1 -0
  22. package/src/backend/database/mutation/person/get-person/index.d.ts +2 -0
  23. package/src/backend/database/mutation/person/get-person/index.js +35 -0
  24. package/src/backend/database/mutation/person/get-person/type.d.ts +25 -0
  25. package/src/backend/database/mutation/person/get-person/type.js +1 -0
  26. package/src/backend/database/mutation/person/index.d.ts +1 -0
  27. package/src/backend/database/mutation/person/index.js +1 -0
  28. package/src/backend/page/page-data/index.d.ts +1 -0
  29. package/src/backend/page/page-data/index.js +1 -0
  30. package/src/backend/page/page-data/light-candle/compose-light-candle-page-data/index.d.ts +2 -0
  31. package/src/backend/page/page-data/light-candle/compose-light-candle-page-data/index.js +22 -0
  32. package/src/backend/page/page-data/light-candle/compose-light-candle-page-data/type.d.ts +8 -0
  33. package/src/backend/page/page-data/light-candle/compose-light-candle-page-data/type.js +1 -0
  34. package/src/backend/page/page-data/light-candle/index.d.ts +2 -0
  35. package/src/backend/page/page-data/light-candle/index.js +2 -0
  36. package/src/backend/page/page-data/light-candle/type.d.ts +6 -0
  37. package/src/backend/page/page-data/light-candle/type.js +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candlerip/shared3",
3
- "version": "0.0.159",
3
+ "version": "0.0.160",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.js",
@@ -1,2 +1,4 @@
1
1
  export * from './candle-person/index.js';
2
2
  export * from './country-persons-count-aggregate/index.js';
3
+ export * from './person-birth-place-country/index.js';
4
+ export * from './person-candles-count/index.js';
@@ -1,2 +1,4 @@
1
1
  export * from './candle-person/index.js';
2
2
  export * from './country-persons-count-aggregate/index.js';
3
+ export * from './person-birth-place-country/index.js';
4
+ export * from './person-candles-count/index.js';
@@ -0,0 +1,2 @@
1
+ import { PipelineStage } from 'mongoose';
2
+ export declare const PERSON_BIRTH_PLACE_COUNTRY_AGGREGATE: PipelineStage[];
@@ -0,0 +1,16 @@
1
+ export const PERSON_BIRTH_PLACE_COUNTRY_AGGREGATE = [
2
+ {
3
+ $lookup: {
4
+ from: 'countries',
5
+ localField: 'birth.place.countryCode',
6
+ foreignField: 'code',
7
+ as: 'countries',
8
+ },
9
+ },
10
+ {
11
+ $unwind: {
12
+ path: '$countries',
13
+ preserveNullAndEmptyArrays: true,
14
+ },
15
+ },
16
+ ];
@@ -0,0 +1 @@
1
+ export * from './config.js';
@@ -0,0 +1 @@
1
+ export * from './config.js';
@@ -0,0 +1,2 @@
1
+ import { PipelineStage } from 'mongoose';
2
+ export declare const PERSON_CANDLES_COUNT_AGGREGATE: PipelineStage[];
@@ -0,0 +1,47 @@
1
+ export const PERSON_CANDLES_COUNT_AGGREGATE = [
2
+ {
3
+ $lookup: {
4
+ from: 'candles',
5
+ localField: '_id',
6
+ foreignField: 'personId',
7
+ as: 'candles',
8
+ },
9
+ },
10
+ {
11
+ $addFields: {
12
+ candlesCount: {
13
+ burning: {
14
+ $size: {
15
+ $filter: {
16
+ input: '$candles',
17
+ as: 'candles',
18
+ cond: {
19
+ $gte: ['$$candles.burningEndsAt', new Date()],
20
+ },
21
+ },
22
+ },
23
+ },
24
+ },
25
+ },
26
+ },
27
+ {
28
+ $addFields: {
29
+ candlesCount: {
30
+ burned: {
31
+ $size: {
32
+ $filter: {
33
+ input: '$candles',
34
+ as: 'candles',
35
+ cond: {
36
+ $lte: ['$$candles.burningEndsAt', new Date()],
37
+ },
38
+ },
39
+ },
40
+ },
41
+ },
42
+ },
43
+ },
44
+ {
45
+ $unset: 'candles',
46
+ },
47
+ ];
@@ -0,0 +1 @@
1
+ export * from './config.js';
@@ -0,0 +1 @@
1
+ export * from './config.js';
@@ -1,4 +1,5 @@
1
1
  export * from './candle/index.js';
2
2
  export * from './country/index.js';
3
3
  export * from './error-log/index.js';
4
+ export * from './person/index.js';
4
5
  export * from './translation/index.js';
@@ -1,4 +1,5 @@
1
1
  export * from './candle/index.js';
2
2
  export * from './country/index.js';
3
3
  export * from './error-log/index.js';
4
+ export * from './person/index.js';
4
5
  export * from './translation/index.js';
@@ -0,0 +1,2 @@
1
+ import * as mongoose from 'mongoose';
2
+ export declare const getPersonDbModel: () => mongoose.Model<any, {}, {}, {}, any, any>;
@@ -0,0 +1,3 @@
1
+ import * as mongoose from 'mongoose';
2
+ import { PersonDbSchema } from './person-db-schema.js';
3
+ export const getPersonDbModel = () => mongoose.models?.persons || mongoose.model('persons', PersonDbSchema);
@@ -0,0 +1,2 @@
1
+ export * from './get-person-db-model.js';
2
+ export * from './person-db-schema.js';
@@ -0,0 +1,2 @@
1
+ export * from './get-person-db-model.js';
2
+ export * from './person-db-schema.js';
@@ -0,0 +1,102 @@
1
+ import * as mongoose from 'mongoose';
2
+ export declare const PersonDbSchema: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
3
+ timestamps: true;
4
+ versionKey: false;
5
+ }, {
6
+ createdAt: NativeDate;
7
+ updatedAt: NativeDate;
8
+ } & {
9
+ name?: string | null | undefined;
10
+ images?: mongoose.Types.DocumentArray<{
11
+ name?: string | null | undefined;
12
+ dimensions?: {
13
+ original?: {
14
+ width?: number | null | undefined;
15
+ height?: number | null | undefined;
16
+ } | null | undefined;
17
+ resized?: mongoose.Types.DocumentArray<{
18
+ width?: number | null | undefined;
19
+ height?: number | null | undefined;
20
+ }> | null | undefined;
21
+ } | null | undefined;
22
+ extension?: string | null | undefined;
23
+ }> | null | undefined;
24
+ description?: string | null | undefined;
25
+ userId?: string | null | undefined;
26
+ birth?: {
27
+ date?: string | null | undefined;
28
+ place?: {
29
+ countryCode?: string | null | undefined;
30
+ } | null | undefined;
31
+ } | null | undefined;
32
+ death?: {
33
+ date?: string | null | undefined;
34
+ } | null | undefined;
35
+ isProposable?: boolean | null | undefined;
36
+ }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
37
+ createdAt: NativeDate;
38
+ updatedAt: NativeDate;
39
+ } & {
40
+ name?: string | null | undefined;
41
+ images?: mongoose.Types.DocumentArray<{
42
+ name?: string | null | undefined;
43
+ dimensions?: {
44
+ original?: {
45
+ width?: number | null | undefined;
46
+ height?: number | null | undefined;
47
+ } | null | undefined;
48
+ resized?: mongoose.Types.DocumentArray<{
49
+ width?: number | null | undefined;
50
+ height?: number | null | undefined;
51
+ }> | null | undefined;
52
+ } | null | undefined;
53
+ extension?: string | null | undefined;
54
+ }> | null | undefined;
55
+ description?: string | null | undefined;
56
+ userId?: string | null | undefined;
57
+ birth?: {
58
+ date?: string | null | undefined;
59
+ place?: {
60
+ countryCode?: string | null | undefined;
61
+ } | null | undefined;
62
+ } | null | undefined;
63
+ death?: {
64
+ date?: string | null | undefined;
65
+ } | null | undefined;
66
+ isProposable?: boolean | null | undefined;
67
+ }>> & mongoose.FlatRecord<{
68
+ createdAt: NativeDate;
69
+ updatedAt: NativeDate;
70
+ } & {
71
+ name?: string | null | undefined;
72
+ images?: mongoose.Types.DocumentArray<{
73
+ name?: string | null | undefined;
74
+ dimensions?: {
75
+ original?: {
76
+ width?: number | null | undefined;
77
+ height?: number | null | undefined;
78
+ } | null | undefined;
79
+ resized?: mongoose.Types.DocumentArray<{
80
+ width?: number | null | undefined;
81
+ height?: number | null | undefined;
82
+ }> | null | undefined;
83
+ } | null | undefined;
84
+ extension?: string | null | undefined;
85
+ }> | null | undefined;
86
+ description?: string | null | undefined;
87
+ userId?: string | null | undefined;
88
+ birth?: {
89
+ date?: string | null | undefined;
90
+ place?: {
91
+ countryCode?: string | null | undefined;
92
+ } | null | undefined;
93
+ } | null | undefined;
94
+ death?: {
95
+ date?: string | null | undefined;
96
+ } | null | undefined;
97
+ isProposable?: boolean | null | undefined;
98
+ }> & {
99
+ _id: mongoose.Types.ObjectId;
100
+ } & {
101
+ __v: number;
102
+ }>;
@@ -0,0 +1,71 @@
1
+ import * as mongoose from 'mongoose';
2
+ export const PersonDbSchema = new mongoose.Schema({
3
+ birth: {
4
+ date: {
5
+ type: String,
6
+ },
7
+ place: {
8
+ countryCode: {
9
+ type: String,
10
+ },
11
+ },
12
+ },
13
+ death: {
14
+ date: {
15
+ type: String,
16
+ },
17
+ },
18
+ description: {
19
+ type: String,
20
+ },
21
+ images: {
22
+ _id: false,
23
+ default: undefined,
24
+ type: [
25
+ {
26
+ dimensions: {
27
+ original: {
28
+ height: {
29
+ type: Number,
30
+ },
31
+ width: {
32
+ type: Number,
33
+ },
34
+ },
35
+ resized: {
36
+ _id: false,
37
+ default: undefined,
38
+ type: [
39
+ {
40
+ height: {
41
+ type: Number,
42
+ },
43
+ width: {
44
+ type: Number,
45
+ },
46
+ },
47
+ ],
48
+ },
49
+ },
50
+ extension: {
51
+ type: String,
52
+ },
53
+ name: {
54
+ type: String,
55
+ },
56
+ },
57
+ ],
58
+ },
59
+ isProposable: {
60
+ type: Boolean,
61
+ },
62
+ name: {
63
+ type: String,
64
+ },
65
+ userId: {
66
+ type: String,
67
+ },
68
+ }, {
69
+ timestamps: true,
70
+ versionKey: false,
71
+ });
@@ -1,4 +1,5 @@
1
1
  export * from './candle/index.js';
2
2
  export * from './country/index.js';
3
3
  export * from './error-log/index.js';
4
+ export * from './person/index.js';
4
5
  export * from './translation/index.js';
@@ -1,4 +1,5 @@
1
1
  export * from './candle/index.js';
2
2
  export * from './country/index.js';
3
3
  export * from './error-log/index.js';
4
+ export * from './person/index.js';
4
5
  export * from './translation/index.js';
@@ -0,0 +1,2 @@
1
+ import { GetPerson } from './type.js';
2
+ export declare const getPerson: GetPerson;
@@ -0,0 +1,35 @@
1
+ import { customErrorWorker } from '@candlerip/shared3';
2
+ import { Types } from 'mongoose';
3
+ import { PERSON_BIRTH_PLACE_COUNTRY_AGGREGATE, PERSON_CANDLES_COUNT_AGGREGATE } from '../../../aggregate/index.js';
4
+ import { getPersonDbModel } from '../../../model/index.js';
5
+ export const getPerson = async (props) => {
6
+ const { _id, withCandlesCount, withBirthPlaceCountry } = props;
7
+ if (!Types.ObjectId.isValid(_id)) {
8
+ return { data: null };
9
+ }
10
+ const aggregates = [{ $match: { _id: new Types.ObjectId(_id) } }];
11
+ const { composeCustomError } = customErrorWorker(props);
12
+ if (withCandlesCount) {
13
+ aggregates.push(...PERSON_CANDLES_COUNT_AGGREGATE);
14
+ }
15
+ if (withBirthPlaceCountry) {
16
+ aggregates.push(...PERSON_BIRTH_PLACE_COUNTRY_AGGREGATE);
17
+ }
18
+ let data;
19
+ try {
20
+ data = await getPersonDbModel().aggregate(aggregates);
21
+ }
22
+ catch (err) {
23
+ return {
24
+ customError: composeCustomError('Get person failed', { err }),
25
+ };
26
+ }
27
+ if (!data || data.length === 0) {
28
+ return {
29
+ data: null,
30
+ };
31
+ }
32
+ return {
33
+ data: data[0],
34
+ };
35
+ };
@@ -0,0 +1,25 @@
1
+ import { CustomError } from '../../../../../error/index.js';
2
+ import { Country } from '../../../../../geographical/index.js';
3
+ import { Person } from '../../../../../person/index.js';
4
+ export type GetPerson = <T extends keyof TypeMap = never>(props: {
5
+ _id: string;
6
+ withCandlesCount?: boolean;
7
+ withBirthPlaceCountry?: boolean;
8
+ }) => Promise<{
9
+ data: TypeMap[T] | null;
10
+ } | {
11
+ customError: CustomError;
12
+ }>;
13
+ type TypeMap = {
14
+ person: Person;
15
+ personWithCandlesCount: Person & {
16
+ candlesCount: {
17
+ burning: number;
18
+ burned: number;
19
+ };
20
+ };
21
+ personWithBirthPlaceCountry: Person & {
22
+ birthPlaceCountry: Country;
23
+ };
24
+ };
25
+ export {};
@@ -0,0 +1 @@
1
+ export * from './get-person/index.js';
@@ -0,0 +1 @@
1
+ export * from './get-person/index.js';
@@ -1,2 +1,3 @@
1
1
  export * from './candles/index.js';
2
+ export * from './light-candle/index.js';
2
3
  export * from './persons-map/index.js';
@@ -1,2 +1,3 @@
1
1
  export * from './candles/index.js';
2
+ export * from './light-candle/index.js';
2
3
  export * from './persons-map/index.js';
@@ -0,0 +1,2 @@
1
+ import { ComposeLightCandlePageData } from './type.js';
2
+ export declare const composeLightCandlePageData: ComposeLightCandlePageData;
@@ -0,0 +1,22 @@
1
+ import { composeCustomError } from '../../../../../error/index.js';
2
+ import { getPerson } from '../../../../database/index.js';
3
+ export const composeLightCandlePageData = async (personId) => {
4
+ const resp = await getPerson({ _id: personId });
5
+ if ('customError' in resp) {
6
+ return resp;
7
+ }
8
+ const { data: person } = resp;
9
+ if (!person) {
10
+ return {
11
+ customError: composeCustomError('Person not found'),
12
+ personNotFoundError: true,
13
+ };
14
+ }
15
+ return {
16
+ data: {
17
+ maintenance: {
18
+ person,
19
+ },
20
+ },
21
+ };
22
+ };
@@ -0,0 +1,8 @@
1
+ import { CustomError } from '../../../../../error/index.js';
2
+ import { LightCandlePageData } from '../type.js';
3
+ export type ComposeLightCandlePageData = (personId: string) => Promise<{
4
+ data: LightCandlePageData;
5
+ } | {
6
+ customError: CustomError;
7
+ personNotFoundError?: boolean;
8
+ }>;
@@ -0,0 +1,2 @@
1
+ export * from './compose-light-candle-page-data/index.js';
2
+ export * from './type.js';
@@ -0,0 +1,2 @@
1
+ export * from './compose-light-candle-page-data/index.js';
2
+ export * from './type.js';
@@ -0,0 +1,6 @@
1
+ import { Person } from '../../../../person/index.js';
2
+ export interface LightCandlePageData {
3
+ maintenance: {
4
+ person: Person;
5
+ };
6
+ }
@@ -0,0 +1 @@
1
+ export {};