Skip to content

Commit 2148732

Browse files
authored
Merge pull request #90 from devforth/change-users-resourceid-in-cli
fix(cli): change users resourceId to match table name
2 parents cc645d5 + 6976b2f commit 2148732

File tree

16 files changed

+89
-89
lines changed

16 files changed

+89
-89
lines changed

adminforth/commands/createApp/templates/users.ts.hbs renamed to adminforth/commands/createApp/templates/adminuser.ts.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async function canModifyUsers({ adminUser }: { adminUser: AdminUser }): Promise<
88
export default {
99
dataSource: 'maindb',
1010
table: 'adminuser',
11-
resourceId: 'users',
11+
resourceId: 'adminuser',
1212
label: 'Users',
1313
recordLabel: (r) => `👤 ${r.email}`,
1414
options: {
@@ -44,7 +44,7 @@ export default {
4444
{
4545
name: 'created_at',
4646
type: AdminForthDataTypes.DATETIME,
47-
showIn: [{
47+
showIn: {
4848
edit: false,
4949
create: false,
5050
},

adminforth/commands/createApp/templates/index.ts.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import express from 'express';
22
import AdminForth, { Filters } from 'adminforth';
3-
import usersResource from "./resources/users";
3+
import usersResource from "./resources/adminuser";
44

55
const ADMIN_BASE_URL = '';
66

77
export const admin = new AdminForth({
88
baseUrl: ADMIN_BASE_URL,
99
auth: {
10-
usersResourceId: 'users',
10+
usersResourceId: 'adminuser',
1111
usernameField: 'email',
1212
passwordHashField: 'password_hash',
1313
rememberMeDays: 30,
@@ -51,7 +51,7 @@ export const admin = new AdminForth({
5151
{
5252
label: 'Users',
5353
icon: 'flowbite:user-solid',
54-
resourceId: 'users'
54+
resourceId: 'adminuser'
5555
}
5656
],
5757
});
@@ -68,8 +68,8 @@ if (import.meta.url === `file://${process.argv[1]}`) {
6868
admin.express.serve(app)
6969

7070
admin.discoverDatabases().then(async () => {
71-
if (!await admin.resource('users').get([Filters.EQ('email', 'adminforth')])) {
72-
await admin.resource('users').create({
71+
if (!await admin.resource('adminuser').get([Filters.EQ('email', 'adminforth')])) {
72+
await admin.resource('adminuser').create({
7373
email: 'adminforth',
7474
password_hash: await AdminForth.Utils.generatePasswordHash('adminforth'),
7575
role: 'superadmin',

adminforth/commands/createApp/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ async function writeTemplateFiles(dirname, cwd, options) {
191191
data: { dbUrl, prismaDbUrl },
192192
},
193193
{
194-
src: 'users.ts.hbs',
195-
dest: 'resources/users.ts',
194+
src: 'adminuser.ts.hbs',
195+
dest: 'resources/adminuser.ts',
196196
data: {},
197197
},
198198
{

adminforth/documentation/blog/2024-10-01-ai-blog/index.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ declare var process : {
207207
export const admin = new AdminForth({
208208
baseUrl: '/admin',
209209
auth: {
210-
usersResourceId: 'user', // resource to get user during login
210+
usersResourceId: 'adminuser', // resource to get user during login
211211
usernameField: 'email', // field where username is stored, should exist in resource
212212
passwordHashField: 'passwordHash',
213213
},
@@ -249,7 +249,7 @@ export const admin = new AdminForth({
249249
{
250250
label: 'Users',
251251
icon: 'flowbite:user-solid',
252-
resourceId: 'user',
252+
resourceId: 'adminuser',
253253
}
254254
],
255255
});
@@ -278,7 +278,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
278278
Sorts.DESC('createdAt'),
279279
);
280280
const authorIds = [...new Set(posts.map((p: any) => p.authorId))];
281-
const authors = (await admin.resource('user').list(Filters.IN('id', authorIds)))
281+
const authors = (await admin.resource('adminuser').list(Filters.IN('id', authorIds)))
282282
.reduce((acc: any, a: any) => {acc[a.id] = a; return acc;}, {});
283283
posts.forEach((p: any) => {
284284
const author = authors[p.authorId];
@@ -309,8 +309,8 @@ if (import.meta.url === `file://${process.argv[1]}`) {
309309
admin.express.serve(app)
310310

311311
admin.discoverDatabases().then(async () => {
312-
if (!await admin.resource('user').get([Filters.EQ('email', '[email protected]')])) {
313-
await admin.resource('user').create({
312+
if (!await admin.resource('adminuser').get([Filters.EQ('email', '[email protected]')])) {
313+
await admin.resource('adminuser').create({
314314
315315
passwordHash: await AdminForth.Utils.generatePasswordHash('adminforth'),
316316
});
@@ -325,16 +325,16 @@ if (import.meta.url === `file://${process.argv[1]}`) {
325325

326326
## Step 5: Create resources
327327

328-
Create `res` folder. Create `./res/user.ts` file with following content:
328+
Create `res` folder. Create `./res/adminuser.ts` file with following content:
329329

330-
```ts title="./res/users.ts"
330+
```ts title="./res/adminuser.ts"
331331
import AdminForth, { AdminForthDataTypes } from 'adminforth';
332332
import { randomUUID } from 'crypto';
333333
import UploadPlugin from '@adminforth/upload';
334334

335335
export default {
336336
dataSource: 'maindb',
337-
table: 'user',
337+
table: 'adminuser',
338338
label: 'Users',
339339
recordLabel: (r: any) => `👤 ${r.email}`,
340340
columns: [
@@ -501,7 +501,7 @@ export default {
501501
{
502502
name: 'authorId',
503503
foreignResource: {
504-
resourceId: 'user',
504+
resourceId: 'adminuser',
505505
},
506506
showIn: {
507507
list: false,

adminforth/documentation/docs/tutorial/001-gettingStarted.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ myadmin/
6464
│ ├── package.json # For any custom npm packages you will use in Vue files
6565
│ └── tsconfig.json # Tsconfig for Vue project (adds completion for AdminForth core components)
6666
├── resources
67-
│ └── users.ts # Example resource file for users management
67+
│ └── adminuser.ts # Example resource file for users management
6868
├── schema.prisma # Prisma schema file for database schema
6969
├── index.ts # Main entry point: configures AdminForth & starts the server
7070
├── package.json # Project dependencies
@@ -128,7 +128,7 @@ Also in AdminForth you can define in "Vue" way:
128128

129129
## Adding an `apartments` Model
130130

131-
So far, our freshly generated AdminForth project includes a default `adminuser` model and a corresponding `users` resource.
131+
So far, our freshly generated AdminForth project includes a default `adminuser` model and a corresponding `adminuser` resource.
132132

133133
Let’s expand our app to suport managment of **`apartments`** model. Adding new resource will involve next steps:
134134

@@ -295,7 +295,7 @@ export default {
295295
{
296296
name: 'realtor_id',
297297
foreignResource: {
298-
resourceId: 'users',
298+
resourceId: 'adminuser',
299299
}
300300
}
301301
],
@@ -418,8 +418,8 @@ if (import.meta.url === `file://${process.argv[1]}`) {
418418
...
419419

420420
admin.discoverDatabases().then(async () => {
421-
if (!await admin.resource('users').get([Filters.EQ('email', 'adminforth')])) {
422-
await admin.resource('users').create({
421+
if (!await admin.resource('adminuser').get([Filters.EQ('email', 'adminforth')])) {
422+
await admin.resource('adminuser').create({
423423
email: 'adminforth',
424424
password_hash: await AdminForth.Utils.generatePasswordHash('adminforth'),
425425
role: 'superadmin',

adminforth/documentation/docs/tutorial/01-helloWorld.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ import AdminForth, { AdminForthDataTypes, AdminUser, Filters } from 'adminforth'
126126
export const admin = new AdminForth({
127127
baseUrl: '',
128128
auth: {
129-
usersResourceId: 'users', // resource to get user during login
129+
usersResourceId: 'adminuser', // resource to get user during login
130130
usernameField: 'email', // field where username is stored, should exist in resource
131131
passwordHashField: 'passwordHash',
132132
},
@@ -143,8 +143,8 @@ export const admin = new AdminForth({
143143
resources: [
144144
{
145145
dataSource: 'maindb',
146-
table: 'user',
147-
resourceId: 'users',
146+
table: 'adminuser',
147+
resourceId: 'adminuser',
148148
label: 'Users',
149149
recordLabel: (r: any) => `👤 ${r.email}`,
150150
columns: [
@@ -242,7 +242,7 @@ export const admin = new AdminForth({
242242
{
243243
name: 'authorId',
244244
foreignResource: {
245-
resourceId: 'users',
245+
resourceId: 'adminuser',
246246
},
247247
showIn: {
248248
edit: false,
@@ -275,7 +275,7 @@ export const admin = new AdminForth({
275275
{
276276
label: 'Users',
277277
icon: 'flowbite:user-solid',
278-
resourceId: 'users',
278+
resourceId: 'adminuser',
279279
}
280280
],
281281
});
@@ -296,8 +296,8 @@ if (import.meta.url === `file://${process.argv[1]}`) {
296296
admin.express.serve(app)
297297

298298
admin.discoverDatabases().then(async () => {
299-
if (!await admin.resource('users').get([Filters.EQ('email', 'adminforth')])) {
300-
await admin.resource('users').create({
299+
if (!await admin.resource('adminuser').get([Filters.EQ('email', 'adminforth')])) {
300+
await admin.resource('adminuser').create({
301301
email: 'adminforth',
302302
passwordHash: await AdminForth.Utils.generatePasswordHash('adminforth'),
303303
role: 'superadmin',

adminforth/documentation/docs/tutorial/03-Customization/03-virtualColumns.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ columns: [
8080
8181
## Virtual columns for editing.
8282
83-
Another usecase of `virtual` columns is to add new fields in edit and create view. In the [Getting started](/docs/tutorial/001-gettingStarted.md) we used this feature to add `password` field to the `users` resource.
83+
Another usecase of `virtual` columns is to add new fields in edit and create view. In the [Getting started](/docs/tutorial/001-gettingStarted.md) we used this feature to add `password` field to the `adminuser` resource.
8484
Thing is that password itself can't be stored in the database, but instead their hash is stored.
85-
So we need to add `password` field to the `users` resource and make it `virtual` so it will not be stored in the database.
85+
So we need to add `password` field to the `adminuser` resource and make it `virtual` so it will not be stored in the database.
8686
87-
```ts title="./resources/users.ts"
87+
```ts title="./resources/adminuser.ts"
8888
...
89-
resourceId: 'users',
89+
resourceId: 'adminuser',
9090
...
9191
columns: [
9292
...

adminforth/documentation/docs/tutorial/03-Customization/05-limitingAccess.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ You can use `options.allowedActions` on resource to limit access to the resource
1515

1616
If you want to disable deletion of the resource records for all users:
1717

18-
```ts title="./resources/users.ts"
18+
```ts title="./resources/adminuser.ts"
1919
{
2020
...
21-
resourceId: 'users',
21+
resourceId: 'adminuser',
2222
...
2323
//diff-add
2424
options: {
@@ -69,7 +69,7 @@ import type { AdminUser } from 'adminforth';
6969

7070
Let's disable creating and editing of new users for all users apart from users with role `superadmin`, and at the same time disable deletion for all users:
7171

72-
```ts title="./resources/users.ts"
72+
```ts title="./resources/adminuser.ts"
7373
//diff-add
7474
import type { AdminUser } from 'adminforth';
7575

@@ -82,7 +82,7 @@ async function canModifyUsers({ adminUser }: { adminUser: AdminUser }): Promise<
8282

8383
{
8484
...
85-
resourceId: 'users',
85+
resourceId: 'adminuser',
8686
...
8787
options: {
8888
allowedActions: {

adminforth/documentation/docs/tutorial/03-Customization/10-menuConfiguration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ E.g. create group "Blog" with Items who link to resource "posts" and "categories
4444
{
4545
label: 'Users',
4646
icon: 'flowbite:folder-duplicate-outline',
47-
resourceId: 'users',
47+
resourceId: 'adminuser',
4848
},
4949
},
5050
...

adminforth/documentation/docs/tutorial/03-Customization/11-dataApi.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This allows you to make basic operations on the data with AdminForth without usi
1414
1515
## Usage
1616

17-
Basically you just import `Filters`, `Sorts` from the `adminforth` package and call the awaitable methods on the `admin.resource('users')`.
17+
Basically you just import `Filters`, `Sorts` from the `adminforth` package and call the awaitable methods on the `admin.resource('adminuser')`.
1818

1919
```ts
2020
import { Filters, Sorts } from 'adminforth';
@@ -25,7 +25,7 @@ const admin = new AdminForth({
2525
});
2626

2727
// get the resource object
28-
await admin.resource('users').get([Filters.EQ('id', '1234')]);
28+
await admin.resource('adminuser').get([Filters.EQ('id', '1234')]);
2929
```
3030

3131
Here we will show you how to use the Data API with simple examples.
@@ -44,7 +44,7 @@ Signature:
4444
Get item by ID:
4545

4646
```ts
47-
const user = await admin.resource('users').get(
47+
const user = await admin.resource('adminuser').get(
4848
[Filters.EQ('id', '1234')]
4949
);
5050
```
@@ -61,7 +61,7 @@ const schoolExists = !!(await admin.resource('schools').get(
6161
Get user with name 'John' and role not 'SuperAdmin'
6262

6363
```ts
64-
const user = await admin.resource('users').get(
64+
const user = await admin.resource('adminuser').get(
6565
[Filters.EQ('name', 'John'), Filters.NEQ('role', 'SuperAdmin')]
6666
);
6767
```
@@ -83,21 +83,21 @@ Signature:
8383
Get 15 latest users which role is not Admin:
8484

8585
```ts
86-
const users = await admin.resource('users').list(
86+
const users = await admin.resource('adminuser').list(
8787
[Filters.NEQ('role', 'Admin')], 15, 0, Sorts.DESC('createdAt')
8888
);
8989
```
9090

9191
Get 10 oldest users (with highest age):
9292

9393
```ts
94-
const users = await admin.resource('users').list([], 10, 0, Sorts.ASC('age'));
94+
const users = await admin.resource('adminuser').list([], 10, 0, Sorts.ASC('age'));
9595
```
9696

9797
Get next page of oldest users:
9898

9999
```ts
100-
const users = await admin.resource('users').list([], 10, 10, Sorts.ASC('age'));
100+
const users = await admin.resource('adminuser').list([], 10, 10, Sorts.ASC('age'));
101101
```
102102

103103
Get 10 schools, sort by rating first, then oldest by founded year:
@@ -162,7 +162,7 @@ const dailyReports = await Promise.all(
162162
const dateEnd = new Date(dateStart);
163163
dateEnd.setDate(dateEnd.getDate() + 1);
164164

165-
return admin.resource('users').count(
165+
return admin.resource('adminuser').count(
166166
[Filters.GTE('createdAt', dateStart.toISOString()), Filters.LT('createdAt', dateEnd.toISOString())]
167167
);
168168
})
@@ -217,10 +217,10 @@ Golden rule: create one index per query you are going to use often or where you
217217
For example if you have two queries:
218218

219219
```ts
220-
const users = await admin.resource('users').list(
220+
const users = await admin.resource('adminuser').list(
221221
[Filters.NEQ('role', 'Admin')], 15, 0, Sorts.DESC('createdAt')
222222
);
223-
const users = await admin.resource('users').list(
223+
const users = await admin.resource('adminuser').list(
224224
[Filters.EQ('name', 'John'), Filters.NEQ('role', 'SuperAdmin')]
225225
);
226226
```

0 commit comments

Comments
 (0)