Skip to content

Commit 8966f3e

Browse files
authored
Merge pull request #108 from strapi/fix/up-users-numeric-ids
add UsersPermissionsUsersManager
2 parents 52f8f96 + ef7a4e2 commit 8966f3e

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/client.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import createDebug from 'debug';
22

33
import { AuthManager } from './auth';
4-
import { CollectionTypeManager, SingleTypeManager } from './content-types';
4+
import {
5+
CollectionTypeManager,
6+
SingleTypeManager,
7+
UsersPermissionsUsersManager,
8+
} from './content-types';
59
import { getWellKnownCollection, getWellKnownSingle } from './content-types/constants';
610
import { StrapiError, StrapiInitializationError } from './errors';
711
import { FilesManager } from './files';
812
import { HttpClient } from './http';
913
import { AuthInterceptors, HttpInterceptors } from './interceptors';
1014
import { StrapiConfigValidator } from './validators';
1115

16+
import type { UsersPermissionsUsersIdOverloads } from './content-types';
1217
import type { ContentTypeManagerOptions } from './content-types/abstract';
1318
import type { HttpClientConfig } from './http';
1419

@@ -360,15 +365,32 @@ export class StrapiClient {
360365
* @see CollectionTypeManager
361366
* @see StrapiClient
362367
*/
363-
collection(resource: string, options: ClientCollectionOptions = {}) {
368+
collection<T extends string>(
369+
resource: T,
370+
options: ClientCollectionOptions = {}
371+
): T extends 'users'
372+
? UsersPermissionsUsersManager & UsersPermissionsUsersIdOverloads
373+
: CollectionTypeManager {
364374
const { path, plugin } = options;
365375

366376
// Auto-detect well-known collection resources and apply their plugin configuration
367377
// if no explicit plugin option is provided
368378
const wellKnownConfig = getWellKnownCollection(resource);
369379
const effectivePlugin = plugin ?? wellKnownConfig?.plugin ?? undefined;
370380

371-
return new CollectionTypeManager({ resource, path, plugin: effectivePlugin }, this._httpClient);
381+
if (resource === 'users' && effectivePlugin?.name === 'users-permissions') {
382+
const manager = new UsersPermissionsUsersManager(
383+
{ resource, path, plugin: effectivePlugin },
384+
this._httpClient
385+
);
386+
387+
return manager as any;
388+
}
389+
390+
return new CollectionTypeManager(
391+
{ resource, path, plugin: effectivePlugin },
392+
this._httpClient
393+
) as any;
372394
}
373395

374396
/**
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export { CollectionTypeManager } from './manager';
2+
export { UsersPermissionsUsersManager } from './users-permissions-users-manager';
3+
export type { UsersPermissionsUsersIdOverloads } from './users-permissions-users-manager';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { CollectionTypeManager } from './manager';
2+
3+
import type * as API from '../../types/content-api';
4+
5+
/**
6+
* Specialized manager for users-permissions `users` collection.
7+
* Runtime behavior is inherited from CollectionTypeManager.
8+
*/
9+
export class UsersPermissionsUsersManager extends CollectionTypeManager {}
10+
11+
/**
12+
* Augmented method signatures for users-permissions `users` to accept numeric IDs
13+
*/
14+
export type UsersPermissionsUsersIdOverloads = {
15+
findOne(id: number, queryParams?: API.BaseQueryParams): Promise<API.DocumentResponse>;
16+
update(
17+
id: number,
18+
data: Record<string, unknown>,
19+
queryParams?: API.BaseQueryParams
20+
): Promise<API.DocumentResponse>;
21+
delete(id: number, queryParams?: API.BaseQueryParams): Promise<void>;
22+
};

0 commit comments

Comments
 (0)