Skip to content

Commit 103efd3

Browse files
committed
Add global modal component. Add user edit and delete button action stubs.
1 parent b3dcc6e commit 103efd3

18 files changed

+358
-95
lines changed

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
package.json
33
src/assets/vendor
44
docs
5-
*.md
5+
*.md
6+
GraphQLServer

GraphQLServer/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.ts

GraphQLServer/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./*

GraphQLServer/Post/Post.ts

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,62 @@
1-
import { db } from "../Data/Db.ts";
2-
import { ObjectId } from "mongo.ts";
1+
import { db } from '../Data/Db.ts';
2+
import { ObjectId } from 'mongo.ts';
3+
import { User } from '../User/User.ts';
34

45
type PostRecord = {
5-
_id?: ObjectId;
6-
title: string;
7-
body: string;
8-
published?: boolean;
6+
_id?: ObjectId;
7+
authorId?: ObjectId;
8+
title: string;
9+
body: string;
10+
published?: boolean;
911
};
1012

1113
export class Post {
12-
constructor({ _id, title, body, published = true }: PostRecord) {
13-
this.id = _id;
14-
this.title = title;
15-
this.body = body;
16-
this.published = published;
17-
}
18-
19-
id?: ObjectId;
20-
title: string;
21-
body: string;
22-
published?: boolean;
23-
24-
static collection = db.collection("Post");
25-
26-
async save() {
27-
let rec;
28-
if (this.id) {
29-
rec = await Post.collection.updateOne({ _id: this.id }, { $set: this });
30-
} else {
31-
rec = await Post.collection.insertOne(this);
14+
id?: ObjectId;
15+
authorId?: ObjectId;
16+
title: string;
17+
body: string;
18+
published?: boolean;
19+
20+
constructor({ _id, authorId, title, body, published = true }: PostRecord) {
21+
this.id = _id;
22+
this.title = title;
23+
this.body = body;
24+
this.published = published;
25+
this.authorId = authorId;
3226
}
3327

34-
const saved = new Post({ ...this, ...rec });
35-
Object.assign(this, saved);
36-
return saved;
37-
}
38-
39-
static async find(query?: any) {
40-
const records = await Post.collection.find(query).toArray();
41-
return records.map((record) => new Post(record as PostRecord));
42-
}
43-
44-
static async load(_id: string) {
45-
const record = await Post.collection.findOne({ _id: new ObjectId(_id) });
46-
if (typeof record == "undefined") return null;
47-
return new Post(record as PostRecord);
48-
}
28+
static collection = db.collection('Post');
29+
30+
async save() {
31+
let rec;
32+
if (this.id) {
33+
rec = await Post.collection.updateOne(
34+
{ _id: this.id },
35+
{ $set: this },
36+
);
37+
} else {
38+
rec = await Post.collection.insertOne(this);
39+
}
40+
41+
const saved = new Post({ ...this, ...rec });
42+
Object.assign(this, saved);
43+
return saved;
44+
}
45+
46+
static async find(query?: any) {
47+
const records = await Post.collection.find(query).toArray();
48+
return records.map((record) => new Post(record as PostRecord));
49+
}
50+
51+
static async load(_id: string) {
52+
const record = await Post.collection.findOne({
53+
_id: new ObjectId(_id),
54+
});
55+
if (typeof record == 'undefined') return null;
56+
return new Post(record as PostRecord);
57+
}
58+
59+
static async delete(_id: string) {
60+
return await Post.collection.deleteOne({ _id: new ObjectId(_id) });
61+
}
4962
}

GraphQLServer/User/User.ts

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
1-
import { db } from "../Data/Db.ts";
2-
import { ObjectId } from "mongo.ts";
1+
import { db } from '../Data/Db.ts';
2+
import { ObjectId } from 'mongo.ts';
33

44
type UserRecord = {
5-
_id?: ObjectId;
6-
name: string;
7-
email: string;
8-
age?: number;
5+
_id?: ObjectId;
6+
name: string;
7+
email: string;
8+
age?: number;
99
};
1010

1111
export class User {
12-
constructor({ _id, name, email, age }: UserRecord) {
13-
this.id = _id;
14-
this.name = name;
15-
this.email = email;
16-
this.age = age;
17-
}
18-
19-
id?: ObjectId;
20-
name: string;
21-
email: string;
22-
age?: number;
23-
24-
static collection = db.collection("User");
25-
26-
async save() {
27-
let rec;
28-
if (this.id) {
29-
rec = await User.collection.updateOne({ _id: this.id }, { $set: this });
30-
} else {
31-
rec = await User.collection.insertOne(this);
12+
constructor({ _id, name, email, age }: UserRecord) {
13+
this.id = _id;
14+
this.name = name;
15+
this.email = email;
16+
this.age = age;
3217
}
3318

34-
const saved = new User({ ...this, ...rec });
35-
Object.assign(this, saved);
36-
return saved;
37-
}
38-
39-
static async find(query?: any) {
40-
const records = await User.collection.find(query).toArray();
41-
return records.map((record) => new User(record as UserRecord));
42-
}
43-
44-
static async load(_id: string) {
45-
const record = await User.collection.findOne({ _id: new ObjectId(_id) });
46-
if (typeof record == "undefined") return null;
47-
return new User(record as UserRecord);
48-
}
49-
50-
static async delete(_id: string) {
51-
return await User.collection.deleteOne({ _id: new ObjectId(_id) });
52-
}
19+
id?: ObjectId;
20+
name: string;
21+
email: string;
22+
age?: number;
23+
24+
static collection = db.collection('User');
25+
26+
async save() {
27+
let rec;
28+
if (this.id) {
29+
rec = await User.collection.updateOne(
30+
{ _id: this.id },
31+
{ $set: this },
32+
);
33+
} else {
34+
rec = await User.collection.insertOne(this);
35+
}
36+
37+
const saved = new User({ ...this, ...rec });
38+
Object.assign(this, saved);
39+
return saved;
40+
}
41+
42+
static async find(query?: any) {
43+
const records = await User.collection.find(query).toArray();
44+
return records.map((record) => new User(record as UserRecord));
45+
}
46+
47+
static async load(_id: string) {
48+
const record = await User.collection.findOne({
49+
_id: new ObjectId(_id),
50+
});
51+
if (typeof record == 'undefined') return null;
52+
return new User(record as UserRecord);
53+
}
54+
55+
static async delete(_id: string) {
56+
return await User.collection.deleteOne({ _id: new ObjectId(_id) });
57+
}
5358
}

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"parse/node": false
3434
},
3535
"dependencies": {
36+
"@fortawesome/fontawesome-svg-core": "^6.6.0",
37+
"@fortawesome/free-solid-svg-icons": "^6.6.0",
38+
"@fortawesome/react-fontawesome": "^0.2.2",
3639
"react": "^18.2.0"
3740
},
3841
"nodemonConfig": {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useHookComponent } from '@atomic-reactor/reactium-core/sdk';
2+
import React from 'react';
3+
4+
/**
5+
* -----------------------------------------------------------------------------
6+
* Component: AppParent, special top-level component
7+
* -----------------------------------------------------------------------------
8+
*/
9+
export const AppParent = ({ children }) => {
10+
const GlobalModal = useHookComponent('GlobalModal');
11+
return (
12+
<>
13+
<main>{children}</main>
14+
<GlobalModal />
15+
</>
16+
);
17+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.appparent {
2+
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* -----------------------------------------------------------------------------
3+
* DDD Domain AppParent - Change name to place domain artifacts in this directory
4+
* in a different domain.
5+
* -----------------------------------------------------------------------------
6+
*/
7+
module.exports = {
8+
name: 'AppParent',
9+
};

0 commit comments

Comments
 (0)