-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmaster.ts
149 lines (137 loc) · 3.04 KB
/
testmaster.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// import entire SDK
import AWS = require("aws-sdk");
///import { AWS } from 'aws-sdk';
const uuidv4 = require("uuid/v4");
//Credentials
var credentials = new AWS.SharedIniFileCredentials({profile: 'default'});
AWS.config.credentials = credentials;
console.log(credentials);
AWS.config.update({
region: "us-east-2"
});
//var ddb = new AWS.DynamoDB({ apiVersion: '2012-08-10' });
//var s3 = new AWS.S3();
var documentClient = new AWS.DynamoDB.DocumentClient();
export class Master {
Id: string;
Name: string;
constructor(name: string) {
this.Name = name;
this.Id = uuidv4();
}
async Save(awsDocuement: IAWSDocument) {
/*
var params = {
AttributeDefinitions: [
{
AttributeName: 'TS_ID',
AttributeType: 'S'
},
{
AttributeName: 'TS_NAME',
AttributeType: 'S'
}
],
KeySchema: [
{
AttributeName: 'TS_ID',
KeyType: 'HASH'
},
{
AttributeName: 'TS_NAME',
KeyType: 'RANGE'
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
},
TableName: 'TS_LIST',
StreamSpecification: {
StreamEnabled: false
}
};
//create table
ddb.createTable(params, function (err, data) {
if (err) {
console.log("Error", err);
return false;
} else {
return true;
}
});
*/
var params = {
TableName: "TS_LIST",
Item: {
TS_ID: awsDocuement.Id,
TS_NAME: awsDocuement.Name,
TS_PROPERTY1: Color[awsDocuement.Property1],
TS_PROPERTY2: awsDocuement.Property2,
TS_PROPERTY3: awsDocuement.Property3
//'TS_PROPERTY4': ts.Property4,
}
};
// Call DynamoDB to put the item into the table
var putObjectPromise = documentClient.put(params).promise();
var p = putObjectPromise.then(function(data){
return new Promise<boolean>(reslove => {
reslove(true);
});
//return true;
}).catch(function(err){
console.log(err);
return new Promise<boolean>(reslove => {
reslove(false);
});
//return false;
})
return p;
}
}
export class Child extends Master {
Property1: Color;
Property2: string;
Property3: IAddress;
Property4: string;
constructor(name: string) {
super(name);
}
public get Address(): IAddress {
return this.Property3;
}
public set Address(address: IAddress) {
this.Property3 = address;
}
async Save() {
const doc: IAWSDocument = {
Id: this.Id,
Name: this.Name,
Property1: this.Property1,
Property2: this.Property2,
Property3: this.Address,
};
return super.Save(doc);
}
}
export interface IAddress {
Address1: string;
Address2: string;
Town: string;
Region: string;
PostalCode: string;
}
export interface IAWSDocument {
Id: string;
Name: string;
Property1: Color;
Property2: string;
Property3: IAddress;
}
export enum Color {
Red,
Green,
Blue,
White,
Purple
}