@memberjunction/server 1.0.6 → 1.0.7-next.0
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/.eslintignore +4 -4
- package/.eslintrc +24 -24
- package/CHANGELOG.json +92 -0
- package/CHANGELOG.md +25 -0
- package/README.md +141 -141
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -1
- package/dist/config.js.map +1 -1
- package/dist/entitySubclasses/entityPermissions.server.d.ts +23 -0
- package/dist/entitySubclasses/entityPermissions.server.d.ts.map +1 -0
- package/dist/entitySubclasses/entityPermissions.server.js +99 -0
- package/dist/entitySubclasses/entityPermissions.server.js.map +1 -0
- package/dist/entitySubclasses/userViewEntity.server.js +17 -17
- package/dist/generated/generated.d.ts.map +1 -1
- package/dist/generated/generated.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/resolvers/AskSkipResolver.js +10 -10
- package/dist/resolvers/FileCategoryResolver.js +2 -2
- package/dist/resolvers/ReportResolver.js +4 -4
- package/package.json +80 -80
- package/src/apolloServer/TransactionPlugin.ts +57 -57
- package/src/apolloServer/index.ts +33 -33
- package/src/auth/exampleNewUserSubClass.ts +73 -73
- package/src/auth/index.ts +151 -151
- package/src/auth/newUsers.ts +56 -56
- package/src/auth/tokenExpiredError.ts +12 -12
- package/src/cache.ts +10 -10
- package/src/config.ts +89 -84
- package/src/context.ts +119 -119
- package/src/directives/Public.ts +42 -42
- package/src/directives/index.ts +1 -1
- package/src/entitySubclasses/entityPermissions.server.ts +111 -0
- package/src/entitySubclasses/userViewEntity.server.ts +187 -187
- package/src/generated/generated.ts +2573 -2573
- package/src/generic/PushStatusResolver.ts +40 -40
- package/src/generic/ResolverBase.ts +331 -331
- package/src/generic/RunViewResolver.ts +350 -350
- package/src/index.ts +133 -137
- package/src/orm.ts +36 -36
- package/src/resolvers/AskSkipResolver.ts +782 -782
- package/src/resolvers/ColorResolver.ts +72 -72
- package/src/resolvers/DatasetResolver.ts +115 -115
- package/src/resolvers/EntityRecordNameResolver.ts +77 -77
- package/src/resolvers/EntityResolver.ts +37 -37
- package/src/resolvers/FileCategoryResolver.ts +38 -38
- package/src/resolvers/FileResolver.ts +110 -110
- package/src/resolvers/MergeRecordsResolver.ts +198 -198
- package/src/resolvers/PotentialDuplicateRecordResolver.ts +59 -59
- package/src/resolvers/QueryResolver.ts +42 -42
- package/src/resolvers/ReportResolver.ts +131 -131
- package/src/resolvers/UserFavoriteResolver.ts +102 -102
- package/src/resolvers/UserResolver.ts +29 -29
- package/src/resolvers/UserViewResolver.ts +64 -64
- package/src/types.ts +19 -19
- package/src/util.ts +106 -106
- package/tsconfig.json +31 -31
- package/typedoc.json +4 -4
- package/build.log.json +0 -47
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
import { Metadata, RunReport } from '@memberjunction/core';
|
|
2
|
-
import { Arg, Ctx, Field, Int, Mutation, ObjectType, Query, Resolver } from 'type-graphql';
|
|
3
|
-
import { AppContext } from '../types';
|
|
4
|
-
import { ConversationDetailEntity, ReportEntity } from '@memberjunction/core-entities';
|
|
5
|
-
import { SkipAPIAnalysisCompleteResponse } from '@memberjunction/skip-types';
|
|
6
|
-
import { DataContext } from '@memberjunction/data-context';
|
|
7
|
-
import { UserCache } from '@memberjunction/sqlserver-dataprovider';
|
|
8
|
-
|
|
9
|
-
@ObjectType()
|
|
10
|
-
export class RunReportResultType {
|
|
11
|
-
@Field()
|
|
12
|
-
ReportID: number;
|
|
13
|
-
|
|
14
|
-
@Field()
|
|
15
|
-
Success: boolean;
|
|
16
|
-
|
|
17
|
-
@Field()
|
|
18
|
-
Results: string;
|
|
19
|
-
|
|
20
|
-
@Field()
|
|
21
|
-
RowCount: number;
|
|
22
|
-
|
|
23
|
-
@Field()
|
|
24
|
-
ExecutionTime: number;
|
|
25
|
-
|
|
26
|
-
@Field()
|
|
27
|
-
ErrorMessage: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@ObjectType()
|
|
31
|
-
export class CreateReportResultType {
|
|
32
|
-
@Field()
|
|
33
|
-
ReportID: number;
|
|
34
|
-
|
|
35
|
-
@Field()
|
|
36
|
-
ReportName: string;
|
|
37
|
-
|
|
38
|
-
@Field()
|
|
39
|
-
Success: boolean;
|
|
40
|
-
|
|
41
|
-
@Field()
|
|
42
|
-
ErrorMessage: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Resolver(RunReportResultType)
|
|
46
|
-
export class ReportResolverExtended {
|
|
47
|
-
@Query(() => RunReportResultType)
|
|
48
|
-
async GetReportData(@Arg('ReportID', () => Int) ReportID: number, @Ctx() {}: AppContext): Promise<RunReportResultType> {
|
|
49
|
-
const runReport = new RunReport();
|
|
50
|
-
const result = await runReport.RunReport({ ReportID: ReportID });
|
|
51
|
-
return {
|
|
52
|
-
ReportID: ReportID,
|
|
53
|
-
Success: result.Success,
|
|
54
|
-
Results: JSON.stringify(result.Results),
|
|
55
|
-
RowCount: result.RowCount,
|
|
56
|
-
ExecutionTime: result.ExecutionTime,
|
|
57
|
-
ErrorMessage: result.ErrorMessage,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* This mutation will create a new report from a conversation detail ID
|
|
63
|
-
*/
|
|
64
|
-
@Mutation(() => CreateReportResultType)
|
|
65
|
-
async CreateReportFromConversationDetailID(@Arg('ConversationDetailID', () => Int) ConversationDetailID: number,
|
|
66
|
-
@Ctx() {dataSource, userPayload}: AppContext): Promise<CreateReportResultType> {
|
|
67
|
-
const md = new Metadata();
|
|
68
|
-
|
|
69
|
-
const u = UserCache.Users.find(u => u.Email?.trim().toLowerCase() === userPayload?.email?.trim().toLowerCase());
|
|
70
|
-
if (!u)
|
|
71
|
-
throw new Error('Unable to find user')
|
|
72
|
-
|
|
73
|
-
const cde = md.Entities.find(e => e.Name === 'Conversation Details')
|
|
74
|
-
if (!cde)
|
|
75
|
-
throw new Error('Unable to find Conversation Details Entity metadata')
|
|
76
|
-
|
|
77
|
-
const cd = md.Entities.find(e => e.Name === 'Conversations')
|
|
78
|
-
if (!cd)
|
|
79
|
-
throw new Error('Unable to find Conversations Entity metadata')
|
|
80
|
-
|
|
81
|
-
const sql = `SELECT cd.Message, cd.ConversationID, c.DataContextID
|
|
82
|
-
FROM ${cde.SchemaName}.${cde.BaseView} cd
|
|
83
|
-
INNER JOIN ${cd.SchemaName}.${cd.BaseView} c
|
|
84
|
-
ON cd.ConversationID = c.ID
|
|
85
|
-
WHERE cd.ID=${ConversationDetailID}`
|
|
86
|
-
const result = await dataSource.query(sql);
|
|
87
|
-
if (!result || result.length === 0)
|
|
88
|
-
throw new Error('Unable to retrieve converation details')
|
|
89
|
-
const skipData = <SkipAPIAnalysisCompleteResponse>JSON.parse(result[0].Message);
|
|
90
|
-
|
|
91
|
-
const report = await md.GetEntityObject<ReportEntity>('Reports', u);
|
|
92
|
-
report.NewRecord();
|
|
93
|
-
report.Name = skipData.reportTitle ? skipData.reportTitle : 'Untitled Report';
|
|
94
|
-
report.Description = skipData.userExplanation ? skipData.userExplanation : '';
|
|
95
|
-
report.ConversationID = result[0].ConversationID;
|
|
96
|
-
report.ConversationDetailID = ConversationDetailID;
|
|
97
|
-
|
|
98
|
-
const dc: DataContext = new DataContext();
|
|
99
|
-
await dc.LoadMetadata(result[0].DataContextID, u);
|
|
100
|
-
const newDataContext = await DataContext.Clone(dc, false, u);
|
|
101
|
-
if (!newDataContext)
|
|
102
|
-
throw new Error('Error cloning data context')
|
|
103
|
-
report.DataContextID = newDataContext.ID;
|
|
104
|
-
|
|
105
|
-
// next, strip out the messags from the SkipData object to put them into our Report Configuration as we dont need to store that information as we have a
|
|
106
|
-
// link back to the conversation and conversation detail
|
|
107
|
-
const newSkipData : SkipAPIAnalysisCompleteResponse = JSON.parse(JSON.stringify(skipData));
|
|
108
|
-
newSkipData.messages = [];
|
|
109
|
-
report.Configuration = JSON.stringify(newSkipData)
|
|
110
|
-
|
|
111
|
-
report.SharingScope = 'None'
|
|
112
|
-
report.UserID = u.ID;
|
|
113
|
-
|
|
114
|
-
if (await report.Save()) {
|
|
115
|
-
return {
|
|
116
|
-
ReportID: report.ID,
|
|
117
|
-
ReportName: report.Name,
|
|
118
|
-
Success: true,
|
|
119
|
-
ErrorMessage: ''
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
return {
|
|
124
|
-
ReportID: -1,
|
|
125
|
-
ReportName: '',
|
|
126
|
-
Success: false,
|
|
127
|
-
ErrorMessage: 'Unable to save new report'
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
1
|
+
import { Metadata, RunReport } from '@memberjunction/core';
|
|
2
|
+
import { Arg, Ctx, Field, Int, Mutation, ObjectType, Query, Resolver } from 'type-graphql';
|
|
3
|
+
import { AppContext } from '../types';
|
|
4
|
+
import { ConversationDetailEntity, ReportEntity } from '@memberjunction/core-entities';
|
|
5
|
+
import { SkipAPIAnalysisCompleteResponse } from '@memberjunction/skip-types';
|
|
6
|
+
import { DataContext } from '@memberjunction/data-context';
|
|
7
|
+
import { UserCache } from '@memberjunction/sqlserver-dataprovider';
|
|
8
|
+
|
|
9
|
+
@ObjectType()
|
|
10
|
+
export class RunReportResultType {
|
|
11
|
+
@Field()
|
|
12
|
+
ReportID: number;
|
|
13
|
+
|
|
14
|
+
@Field()
|
|
15
|
+
Success: boolean;
|
|
16
|
+
|
|
17
|
+
@Field()
|
|
18
|
+
Results: string;
|
|
19
|
+
|
|
20
|
+
@Field()
|
|
21
|
+
RowCount: number;
|
|
22
|
+
|
|
23
|
+
@Field()
|
|
24
|
+
ExecutionTime: number;
|
|
25
|
+
|
|
26
|
+
@Field()
|
|
27
|
+
ErrorMessage: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@ObjectType()
|
|
31
|
+
export class CreateReportResultType {
|
|
32
|
+
@Field()
|
|
33
|
+
ReportID: number;
|
|
34
|
+
|
|
35
|
+
@Field()
|
|
36
|
+
ReportName: string;
|
|
37
|
+
|
|
38
|
+
@Field()
|
|
39
|
+
Success: boolean;
|
|
40
|
+
|
|
41
|
+
@Field()
|
|
42
|
+
ErrorMessage: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Resolver(RunReportResultType)
|
|
46
|
+
export class ReportResolverExtended {
|
|
47
|
+
@Query(() => RunReportResultType)
|
|
48
|
+
async GetReportData(@Arg('ReportID', () => Int) ReportID: number, @Ctx() {}: AppContext): Promise<RunReportResultType> {
|
|
49
|
+
const runReport = new RunReport();
|
|
50
|
+
const result = await runReport.RunReport({ ReportID: ReportID });
|
|
51
|
+
return {
|
|
52
|
+
ReportID: ReportID,
|
|
53
|
+
Success: result.Success,
|
|
54
|
+
Results: JSON.stringify(result.Results),
|
|
55
|
+
RowCount: result.RowCount,
|
|
56
|
+
ExecutionTime: result.ExecutionTime,
|
|
57
|
+
ErrorMessage: result.ErrorMessage,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* This mutation will create a new report from a conversation detail ID
|
|
63
|
+
*/
|
|
64
|
+
@Mutation(() => CreateReportResultType)
|
|
65
|
+
async CreateReportFromConversationDetailID(@Arg('ConversationDetailID', () => Int) ConversationDetailID: number,
|
|
66
|
+
@Ctx() {dataSource, userPayload}: AppContext): Promise<CreateReportResultType> {
|
|
67
|
+
const md = new Metadata();
|
|
68
|
+
|
|
69
|
+
const u = UserCache.Users.find(u => u.Email?.trim().toLowerCase() === userPayload?.email?.trim().toLowerCase());
|
|
70
|
+
if (!u)
|
|
71
|
+
throw new Error('Unable to find user')
|
|
72
|
+
|
|
73
|
+
const cde = md.Entities.find(e => e.Name === 'Conversation Details')
|
|
74
|
+
if (!cde)
|
|
75
|
+
throw new Error('Unable to find Conversation Details Entity metadata')
|
|
76
|
+
|
|
77
|
+
const cd = md.Entities.find(e => e.Name === 'Conversations')
|
|
78
|
+
if (!cd)
|
|
79
|
+
throw new Error('Unable to find Conversations Entity metadata')
|
|
80
|
+
|
|
81
|
+
const sql = `SELECT cd.Message, cd.ConversationID, c.DataContextID
|
|
82
|
+
FROM ${cde.SchemaName}.${cde.BaseView} cd
|
|
83
|
+
INNER JOIN ${cd.SchemaName}.${cd.BaseView} c
|
|
84
|
+
ON cd.ConversationID = c.ID
|
|
85
|
+
WHERE cd.ID=${ConversationDetailID}`
|
|
86
|
+
const result = await dataSource.query(sql);
|
|
87
|
+
if (!result || result.length === 0)
|
|
88
|
+
throw new Error('Unable to retrieve converation details')
|
|
89
|
+
const skipData = <SkipAPIAnalysisCompleteResponse>JSON.parse(result[0].Message);
|
|
90
|
+
|
|
91
|
+
const report = await md.GetEntityObject<ReportEntity>('Reports', u);
|
|
92
|
+
report.NewRecord();
|
|
93
|
+
report.Name = skipData.reportTitle ? skipData.reportTitle : 'Untitled Report';
|
|
94
|
+
report.Description = skipData.userExplanation ? skipData.userExplanation : '';
|
|
95
|
+
report.ConversationID = result[0].ConversationID;
|
|
96
|
+
report.ConversationDetailID = ConversationDetailID;
|
|
97
|
+
|
|
98
|
+
const dc: DataContext = new DataContext();
|
|
99
|
+
await dc.LoadMetadata(result[0].DataContextID, u);
|
|
100
|
+
const newDataContext = await DataContext.Clone(dc, false, u);
|
|
101
|
+
if (!newDataContext)
|
|
102
|
+
throw new Error('Error cloning data context')
|
|
103
|
+
report.DataContextID = newDataContext.ID;
|
|
104
|
+
|
|
105
|
+
// next, strip out the messags from the SkipData object to put them into our Report Configuration as we dont need to store that information as we have a
|
|
106
|
+
// link back to the conversation and conversation detail
|
|
107
|
+
const newSkipData : SkipAPIAnalysisCompleteResponse = JSON.parse(JSON.stringify(skipData));
|
|
108
|
+
newSkipData.messages = [];
|
|
109
|
+
report.Configuration = JSON.stringify(newSkipData)
|
|
110
|
+
|
|
111
|
+
report.SharingScope = 'None'
|
|
112
|
+
report.UserID = u.ID;
|
|
113
|
+
|
|
114
|
+
if (await report.Save()) {
|
|
115
|
+
return {
|
|
116
|
+
ReportID: report.ID,
|
|
117
|
+
ReportName: report.Name,
|
|
118
|
+
Success: true,
|
|
119
|
+
ErrorMessage: ''
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return {
|
|
124
|
+
ReportID: -1,
|
|
125
|
+
ReportName: '',
|
|
126
|
+
Success: false,
|
|
127
|
+
ErrorMessage: 'Unable to save new report'
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { Metadata, PrimaryKeyValue } from '@memberjunction/core';
|
|
2
|
-
import { AppContext, Arg, Ctx, Field, InputType, Int, Mutation, ObjectType, PrimaryKeyValueInputType, PrimaryKeyValueOutputType, Query, Resolver } from '@memberjunction/server';
|
|
3
|
-
import { UserCache } from '@memberjunction/sqlserver-dataprovider';
|
|
4
|
-
import { UserFavoriteEntity } from '@memberjunction/core-entities';
|
|
5
|
-
|
|
6
|
-
import { UserFavorite_, UserFavoriteResolverBase } from '../generated/generated';
|
|
7
|
-
|
|
8
|
-
//****************************************************************************
|
|
9
|
-
// INPUT TYPE for User Favorite Queries
|
|
10
|
-
//****************************************************************************
|
|
11
|
-
@InputType()
|
|
12
|
-
export class UserFavoriteSearchParams {
|
|
13
|
-
@Field(() => Int)
|
|
14
|
-
EntityID: number;
|
|
15
|
-
|
|
16
|
-
@Field(() => [PrimaryKeyValueInputType])
|
|
17
|
-
PrimaryKeyValues: PrimaryKeyValue[];
|
|
18
|
-
|
|
19
|
-
@Field(() => Int)
|
|
20
|
-
UserID: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@InputType()
|
|
24
|
-
export class UserFavoriteSetParams {
|
|
25
|
-
@Field(() => Int)
|
|
26
|
-
EntityID: number;
|
|
27
|
-
|
|
28
|
-
@Field(() => [PrimaryKeyValueInputType])
|
|
29
|
-
PrimaryKeyValues: PrimaryKeyValue[];
|
|
30
|
-
|
|
31
|
-
@Field(() => Int)
|
|
32
|
-
UserID: number;
|
|
33
|
-
|
|
34
|
-
@Field(() => Boolean)
|
|
35
|
-
IsFavorite: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@ObjectType()
|
|
39
|
-
export class UserFavoriteResult {
|
|
40
|
-
@Field(() => Int)
|
|
41
|
-
EntityID: number;
|
|
42
|
-
|
|
43
|
-
@Field(() => [PrimaryKeyValueOutputType])
|
|
44
|
-
PrimaryKeyValues: PrimaryKeyValue[];
|
|
45
|
-
|
|
46
|
-
@Field(() => Int)
|
|
47
|
-
UserID: number;
|
|
48
|
-
|
|
49
|
-
@Field(() => Boolean)
|
|
50
|
-
IsFavorite: boolean;
|
|
51
|
-
|
|
52
|
-
@Field(() => Boolean)
|
|
53
|
-
Success: boolean;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@Resolver(UserFavorite_)
|
|
57
|
-
export class UserFavoriteResolver extends UserFavoriteResolverBase {
|
|
58
|
-
@Query(() => [UserFavorite_])
|
|
59
|
-
async UserFavoritesByUserID(@Arg('UserID', () => Int) UserID: number, @Ctx() { dataSource }: AppContext) {
|
|
60
|
-
return await this.findBy(dataSource, 'User Favorites', { UserID });
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@Query(() => [UserFavorite_])
|
|
64
|
-
async UserFavoriteSearchByParams(@Arg('params', () => Int) params: UserFavoriteSearchParams, @Ctx() { dataSource }: AppContext) {
|
|
65
|
-
return await this.findBy(dataSource, 'User Favorites', params);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@Query(() => UserFavoriteResult)
|
|
69
|
-
async GetRecordFavoriteStatus(@Arg('params', () => UserFavoriteSearchParams) params: UserFavoriteSearchParams, @Ctx() {}: AppContext) {
|
|
70
|
-
const md = new Metadata();
|
|
71
|
-
const e = md.Entities.find((e) => e.ID === params.EntityID);
|
|
72
|
-
if (e)
|
|
73
|
-
return {
|
|
74
|
-
EntityID: params.EntityID,
|
|
75
|
-
UserID: params.UserID,
|
|
76
|
-
PrimaryKeyValues: params.PrimaryKeyValues,
|
|
77
|
-
IsFavorite: await md.GetRecordFavoriteStatus(params.UserID, e.Name, params.PrimaryKeyValues),
|
|
78
|
-
Success: true,
|
|
79
|
-
};
|
|
80
|
-
else throw new Error(`Entity ID:${params.EntityID} not found`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@Mutation(() => UserFavoriteResult)
|
|
84
|
-
SetRecordFavoriteStatus(@Arg('params', () => UserFavoriteSetParams) params: UserFavoriteSetParams, @Ctx() { userPayload }: AppContext) {
|
|
85
|
-
const md = new Metadata();
|
|
86
|
-
const e = md.Entities.find((e) => e.ID === params.EntityID);
|
|
87
|
-
const u = UserCache.Users.find((u) => u.ID === userPayload.userRecord.ID);
|
|
88
|
-
if (e) {
|
|
89
|
-
md.SetRecordFavoriteStatus(params.UserID, e.Name, params.PrimaryKeyValues, params.IsFavorite, u);
|
|
90
|
-
return {
|
|
91
|
-
Success: true,
|
|
92
|
-
EntityID: params.EntityID,
|
|
93
|
-
UserID: params.UserID,
|
|
94
|
-
PrimaryKeyValues: params.PrimaryKeyValues,
|
|
95
|
-
IsFavorite: params.IsFavorite,
|
|
96
|
-
};
|
|
97
|
-
} else throw new Error(`Entity ID:${params.EntityID} not found`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export default UserFavoriteResolver;
|
|
1
|
+
import { Metadata, PrimaryKeyValue } from '@memberjunction/core';
|
|
2
|
+
import { AppContext, Arg, Ctx, Field, InputType, Int, Mutation, ObjectType, PrimaryKeyValueInputType, PrimaryKeyValueOutputType, Query, Resolver } from '@memberjunction/server';
|
|
3
|
+
import { UserCache } from '@memberjunction/sqlserver-dataprovider';
|
|
4
|
+
import { UserFavoriteEntity } from '@memberjunction/core-entities';
|
|
5
|
+
|
|
6
|
+
import { UserFavorite_, UserFavoriteResolverBase } from '../generated/generated';
|
|
7
|
+
|
|
8
|
+
//****************************************************************************
|
|
9
|
+
// INPUT TYPE for User Favorite Queries
|
|
10
|
+
//****************************************************************************
|
|
11
|
+
@InputType()
|
|
12
|
+
export class UserFavoriteSearchParams {
|
|
13
|
+
@Field(() => Int)
|
|
14
|
+
EntityID: number;
|
|
15
|
+
|
|
16
|
+
@Field(() => [PrimaryKeyValueInputType])
|
|
17
|
+
PrimaryKeyValues: PrimaryKeyValue[];
|
|
18
|
+
|
|
19
|
+
@Field(() => Int)
|
|
20
|
+
UserID: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@InputType()
|
|
24
|
+
export class UserFavoriteSetParams {
|
|
25
|
+
@Field(() => Int)
|
|
26
|
+
EntityID: number;
|
|
27
|
+
|
|
28
|
+
@Field(() => [PrimaryKeyValueInputType])
|
|
29
|
+
PrimaryKeyValues: PrimaryKeyValue[];
|
|
30
|
+
|
|
31
|
+
@Field(() => Int)
|
|
32
|
+
UserID: number;
|
|
33
|
+
|
|
34
|
+
@Field(() => Boolean)
|
|
35
|
+
IsFavorite: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ObjectType()
|
|
39
|
+
export class UserFavoriteResult {
|
|
40
|
+
@Field(() => Int)
|
|
41
|
+
EntityID: number;
|
|
42
|
+
|
|
43
|
+
@Field(() => [PrimaryKeyValueOutputType])
|
|
44
|
+
PrimaryKeyValues: PrimaryKeyValue[];
|
|
45
|
+
|
|
46
|
+
@Field(() => Int)
|
|
47
|
+
UserID: number;
|
|
48
|
+
|
|
49
|
+
@Field(() => Boolean)
|
|
50
|
+
IsFavorite: boolean;
|
|
51
|
+
|
|
52
|
+
@Field(() => Boolean)
|
|
53
|
+
Success: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Resolver(UserFavorite_)
|
|
57
|
+
export class UserFavoriteResolver extends UserFavoriteResolverBase {
|
|
58
|
+
@Query(() => [UserFavorite_])
|
|
59
|
+
async UserFavoritesByUserID(@Arg('UserID', () => Int) UserID: number, @Ctx() { dataSource }: AppContext) {
|
|
60
|
+
return await this.findBy(dataSource, 'User Favorites', { UserID });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Query(() => [UserFavorite_])
|
|
64
|
+
async UserFavoriteSearchByParams(@Arg('params', () => Int) params: UserFavoriteSearchParams, @Ctx() { dataSource }: AppContext) {
|
|
65
|
+
return await this.findBy(dataSource, 'User Favorites', params);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@Query(() => UserFavoriteResult)
|
|
69
|
+
async GetRecordFavoriteStatus(@Arg('params', () => UserFavoriteSearchParams) params: UserFavoriteSearchParams, @Ctx() {}: AppContext) {
|
|
70
|
+
const md = new Metadata();
|
|
71
|
+
const e = md.Entities.find((e) => e.ID === params.EntityID);
|
|
72
|
+
if (e)
|
|
73
|
+
return {
|
|
74
|
+
EntityID: params.EntityID,
|
|
75
|
+
UserID: params.UserID,
|
|
76
|
+
PrimaryKeyValues: params.PrimaryKeyValues,
|
|
77
|
+
IsFavorite: await md.GetRecordFavoriteStatus(params.UserID, e.Name, params.PrimaryKeyValues),
|
|
78
|
+
Success: true,
|
|
79
|
+
};
|
|
80
|
+
else throw new Error(`Entity ID:${params.EntityID} not found`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Mutation(() => UserFavoriteResult)
|
|
84
|
+
SetRecordFavoriteStatus(@Arg('params', () => UserFavoriteSetParams) params: UserFavoriteSetParams, @Ctx() { userPayload }: AppContext) {
|
|
85
|
+
const md = new Metadata();
|
|
86
|
+
const e = md.Entities.find((e) => e.ID === params.EntityID);
|
|
87
|
+
const u = UserCache.Users.find((u) => u.ID === userPayload.userRecord.ID);
|
|
88
|
+
if (e) {
|
|
89
|
+
md.SetRecordFavoriteStatus(params.UserID, e.Name, params.PrimaryKeyValues, params.IsFavorite, u);
|
|
90
|
+
return {
|
|
91
|
+
Success: true,
|
|
92
|
+
EntityID: params.EntityID,
|
|
93
|
+
UserID: params.UserID,
|
|
94
|
+
PrimaryKeyValues: params.PrimaryKeyValues,
|
|
95
|
+
IsFavorite: params.IsFavorite,
|
|
96
|
+
};
|
|
97
|
+
} else throw new Error(`Entity ID:${params.EntityID} not found`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export default UserFavoriteResolver;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { AppContext, Arg, Ctx, Int, Query, Resolver } from '@memberjunction/server';
|
|
2
|
-
import { User_, UserResolverBase } from '../generated/generated';
|
|
3
|
-
|
|
4
|
-
@Resolver(User_)
|
|
5
|
-
export class UserResolver extends UserResolverBase {
|
|
6
|
-
@Query(() => User_)
|
|
7
|
-
async CurrentUser(@Ctx() { dataSource, userPayload }: AppContext) {
|
|
8
|
-
return await this.UserByEmail(userPayload.email, { dataSource, userPayload });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@Query(() => User_)
|
|
12
|
-
async UserByID(@Arg('ID', () => Int) ID: number, @Ctx() { dataSource }: AppContext) {
|
|
13
|
-
return super.safeFirstArrayElement(await this.findBy(dataSource, 'Users', { ID }));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@Query(() => User_)
|
|
17
|
-
async UserByEmployeeID(@Arg('EmployeeID', () => Int) EmployeeID: number, @Ctx() { dataSource }: AppContext) {
|
|
18
|
-
return super.safeFirstArrayElement(await this.findBy(dataSource, 'Users', { EmployeeID }));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Query(() => User_)
|
|
22
|
-
async UserByEmail(@Arg('Email', () => String) Email: string, @Ctx() { dataSource }: AppContext) {
|
|
23
|
-
// const searchEmail = userEmailMap[Email] ?? Email;
|
|
24
|
-
const searchEmail = Email;
|
|
25
|
-
const returnVal = super.safeFirstArrayElement(await this.findBy(dataSource, 'Users', { Email: searchEmail }));
|
|
26
|
-
return returnVal;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export default UserResolver;
|
|
1
|
+
import { AppContext, Arg, Ctx, Int, Query, Resolver } from '@memberjunction/server';
|
|
2
|
+
import { User_, UserResolverBase } from '../generated/generated';
|
|
3
|
+
|
|
4
|
+
@Resolver(User_)
|
|
5
|
+
export class UserResolver extends UserResolverBase {
|
|
6
|
+
@Query(() => User_)
|
|
7
|
+
async CurrentUser(@Ctx() { dataSource, userPayload }: AppContext) {
|
|
8
|
+
return await this.UserByEmail(userPayload.email, { dataSource, userPayload });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@Query(() => User_)
|
|
12
|
+
async UserByID(@Arg('ID', () => Int) ID: number, @Ctx() { dataSource }: AppContext) {
|
|
13
|
+
return super.safeFirstArrayElement(await this.findBy(dataSource, 'Users', { ID }));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Query(() => User_)
|
|
17
|
+
async UserByEmployeeID(@Arg('EmployeeID', () => Int) EmployeeID: number, @Ctx() { dataSource }: AppContext) {
|
|
18
|
+
return super.safeFirstArrayElement(await this.findBy(dataSource, 'Users', { EmployeeID }));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Query(() => User_)
|
|
22
|
+
async UserByEmail(@Arg('Email', () => String) Email: string, @Ctx() { dataSource }: AppContext) {
|
|
23
|
+
// const searchEmail = userEmailMap[Email] ?? Email;
|
|
24
|
+
const searchEmail = Email;
|
|
25
|
+
const returnVal = super.safeFirstArrayElement(await this.findBy(dataSource, 'Users', { Email: searchEmail }));
|
|
26
|
+
return returnVal;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export default UserResolver;
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Metadata } from '@memberjunction/core';
|
|
3
|
-
import { AppContext, Arg, Ctx, Int, Query, Resolver, UserPayload } from '@memberjunction/server';
|
|
4
|
-
import { DataSource } from 'typeorm';
|
|
5
|
-
import { UserView_, UserViewResolverBase } from '../generated/generated';
|
|
6
|
-
import { UserResolver } from './UserResolver';
|
|
7
|
-
import { UserViewEntity, UserViewEntityExtended } from '@memberjunction/core-entities';
|
|
8
|
-
|
|
9
|
-
@Resolver(UserView_)
|
|
10
|
-
export class UserViewResolver extends UserViewResolverBase {
|
|
11
|
-
@Query(() => [UserView_])
|
|
12
|
-
async UserViewsByUserID(@Arg('UserID', () => Int) UserID: number, @Ctx() { dataSource }: AppContext) {
|
|
13
|
-
return await this.findBy(dataSource, 'User Views', { UserID });
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@Query(() => [UserView_])
|
|
17
|
-
async DefaultViewByUserAndEntity(
|
|
18
|
-
@Arg('UserID', () => Int) UserID: number,
|
|
19
|
-
@Arg('EntityID', () => Int) EntityID: number,
|
|
20
|
-
@Ctx() { dataSource }: AppContext
|
|
21
|
-
) {
|
|
22
|
-
return await this.findBy(dataSource, 'User Views', { UserID, EntityID, IsDefault: true });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@Query(() => [UserView_])
|
|
26
|
-
async CurrentUserDefaultViewByEntityID(@Arg('EntityID', () => Int) EntityID: number, @Ctx() { dataSource, userPayload }: AppContext) {
|
|
27
|
-
return await this.findBy(dataSource, 'User Views', {
|
|
28
|
-
UserID: await this.getCurrentUserID(dataSource, userPayload),
|
|
29
|
-
EntityID,
|
|
30
|
-
IsDefault: true,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
protected async getCurrentUserID(dataSource: DataSource, userPayload: UserPayload): Promise<number> {
|
|
35
|
-
const userResolver = new UserResolver();
|
|
36
|
-
const user = await userResolver.UserByEmail(userPayload.email, { dataSource, userPayload });
|
|
37
|
-
return user.ID;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@Query(() => [UserView_])
|
|
41
|
-
async CurrentUserUserViewsByEntityID(@Arg('EntityID', () => Int) EntityID: number, @Ctx() { dataSource, userPayload }: AppContext) {
|
|
42
|
-
return this.findBy(dataSource, 'User Views', { UserID: await this.getCurrentUserID(dataSource, userPayload), EntityID });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Query(() => [UserView_])
|
|
46
|
-
async UpdateWhereClause(@Arg('ID', () => Int) ID: number, @Ctx() { userPayload }: AppContext) {
|
|
47
|
-
// in this query we want to update the uesrView record in the DB with a new where clause
|
|
48
|
-
// this should normally not be a factor but we have this exposed in the GraphQL API so that
|
|
49
|
-
// a dev can force the update if desired from the client. The normal path is just to update
|
|
50
|
-
// filter state which in turn will be used to update the where clause in the entity sub-class.
|
|
51
|
-
const md = new Metadata();
|
|
52
|
-
const u = this.GetUserFromPayload(userPayload);
|
|
53
|
-
const viewEntity = <UserViewEntityExtended>await md.GetEntityObject('User Views', u);
|
|
54
|
-
await viewEntity.Load(ID);
|
|
55
|
-
viewEntity.UpdateWhereClause();
|
|
56
|
-
if (await viewEntity.Save()) {
|
|
57
|
-
return viewEntity.GetAll();
|
|
58
|
-
} else {
|
|
59
|
-
throw new Error('Failed to update where clause');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export default UserViewResolver;
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { Metadata } from '@memberjunction/core';
|
|
3
|
+
import { AppContext, Arg, Ctx, Int, Query, Resolver, UserPayload } from '@memberjunction/server';
|
|
4
|
+
import { DataSource } from 'typeorm';
|
|
5
|
+
import { UserView_, UserViewResolverBase } from '../generated/generated';
|
|
6
|
+
import { UserResolver } from './UserResolver';
|
|
7
|
+
import { UserViewEntity, UserViewEntityExtended } from '@memberjunction/core-entities';
|
|
8
|
+
|
|
9
|
+
@Resolver(UserView_)
|
|
10
|
+
export class UserViewResolver extends UserViewResolverBase {
|
|
11
|
+
@Query(() => [UserView_])
|
|
12
|
+
async UserViewsByUserID(@Arg('UserID', () => Int) UserID: number, @Ctx() { dataSource }: AppContext) {
|
|
13
|
+
return await this.findBy(dataSource, 'User Views', { UserID });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Query(() => [UserView_])
|
|
17
|
+
async DefaultViewByUserAndEntity(
|
|
18
|
+
@Arg('UserID', () => Int) UserID: number,
|
|
19
|
+
@Arg('EntityID', () => Int) EntityID: number,
|
|
20
|
+
@Ctx() { dataSource }: AppContext
|
|
21
|
+
) {
|
|
22
|
+
return await this.findBy(dataSource, 'User Views', { UserID, EntityID, IsDefault: true });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Query(() => [UserView_])
|
|
26
|
+
async CurrentUserDefaultViewByEntityID(@Arg('EntityID', () => Int) EntityID: number, @Ctx() { dataSource, userPayload }: AppContext) {
|
|
27
|
+
return await this.findBy(dataSource, 'User Views', {
|
|
28
|
+
UserID: await this.getCurrentUserID(dataSource, userPayload),
|
|
29
|
+
EntityID,
|
|
30
|
+
IsDefault: true,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected async getCurrentUserID(dataSource: DataSource, userPayload: UserPayload): Promise<number> {
|
|
35
|
+
const userResolver = new UserResolver();
|
|
36
|
+
const user = await userResolver.UserByEmail(userPayload.email, { dataSource, userPayload });
|
|
37
|
+
return user.ID;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Query(() => [UserView_])
|
|
41
|
+
async CurrentUserUserViewsByEntityID(@Arg('EntityID', () => Int) EntityID: number, @Ctx() { dataSource, userPayload }: AppContext) {
|
|
42
|
+
return this.findBy(dataSource, 'User Views', { UserID: await this.getCurrentUserID(dataSource, userPayload), EntityID });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Query(() => [UserView_])
|
|
46
|
+
async UpdateWhereClause(@Arg('ID', () => Int) ID: number, @Ctx() { userPayload }: AppContext) {
|
|
47
|
+
// in this query we want to update the uesrView record in the DB with a new where clause
|
|
48
|
+
// this should normally not be a factor but we have this exposed in the GraphQL API so that
|
|
49
|
+
// a dev can force the update if desired from the client. The normal path is just to update
|
|
50
|
+
// filter state which in turn will be used to update the where clause in the entity sub-class.
|
|
51
|
+
const md = new Metadata();
|
|
52
|
+
const u = this.GetUserFromPayload(userPayload);
|
|
53
|
+
const viewEntity = <UserViewEntityExtended>await md.GetEntityObject('User Views', u);
|
|
54
|
+
await viewEntity.Load(ID);
|
|
55
|
+
viewEntity.UpdateWhereClause();
|
|
56
|
+
if (await viewEntity.Save()) {
|
|
57
|
+
return viewEntity.GetAll();
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error('Failed to update where clause');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default UserViewResolver;
|