-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfront.ts
57 lines (44 loc) · 1.51 KB
/
front.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
import { ClientConfig, CrudClient } from "@eicrud/client";
export class DynamicClient {
crudClient: CrudClient<any>;
constructor() {
const initalConfig: ClientConfig = {
url: 'http://localhost:3000',
serviceName: 'user',
}
this.crudClient = new CrudClient(initalConfig);
}
get(serviceName){
this.crudClient.config.serviceName = serviceName;
return this.crudClient;
}
}
import { ICreateAccountDto } from '@eicrud/shared/interfaces';
import { ILoginDto } from '@eicrud/shared/interfaces';
import { Article } from "./src/services/article/article.entity";
async function main() {
const client = new DynamicClient();
// Create account and publish article
const dto: ICreateAccountDto = {
email: '[email protected]',
password: 'p4ssw0rd',
role: 'user',
};
const { userId } = await client.get('user').cmdS('create_account', dto);
console.log('User created!', userId);
const loginDto: ILoginDto = {
email: '[email protected]',
password: 'p4ssw0rd',
};
await client.get('user').login(loginDto);
const newArticle: Partial<Article> = {
title: 'New article',
content: 'This is a new article',
author: userId,
};
await client.get('article').create(newArticle);
// Let's check that our article was created
const userArticles = await client.get('article').find({ author: userId });
console.log('User articles:', userArticles);
}
main();