Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add shared data service in api crud generator #22

Merged
merged 12 commits into from
Mar 17, 2024
134 changes: 67 additions & 67 deletions api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------

input AdminCreateIdentityInput {
ownerId: String!
provider: IdentityProvider!
providerId: String!
}

input AdminCreateUserInput {
password: String
username: String!
}

input AdminFindManyIdentityInput {
ownerId: String
provider: IdentityProvider
}

input AdminFindManyUserInput {
limit: Int = 10
page: Int = 1
role: UserRole
search: String
status: UserStatus
}

input AdminUpdateUserInput {
avatarUrl: String
developer: Boolean
name: String
role: UserRole
status: UserStatus
username: String
}

type AppConfig {
authDiscordEnabled: Boolean!
authGithubEnabled: Boolean!
Expand Down Expand Up @@ -65,6 +32,17 @@ type Identity {
verified: Boolean
}

input IdentityAdminCreateInput {
ownerId: String!
provider: IdentityProvider!
providerId: String!
}

input IdentityAdminFindManyInput {
ownerId: String
provider: IdentityProvider
}

type IdentityChallenge {
challenge: String!
createdAt: DateTime!
Expand All @@ -86,35 +64,52 @@ enum IdentityProvider {
Twitter
}

"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
scalar JSON @specifiedBy(url: "http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf")
input IdentityRequestChallengeInput {
provider: IdentityProvider!
providerId: String!
}

input IdentityUserFindManyInput {
username: String!
}

input LinkIdentityInput {
input IdentityUserLinkInput {
provider: IdentityProvider!
providerId: String!
}

input IdentityVerifyChallengeInput {
challenge: String!
provider: IdentityProvider!
providerId: String!
signature: String!
useLedger: Boolean = false
}

"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
scalar JSON @specifiedBy(url: "http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf")

input LoginInput {
password: String!
username: String!
}

type Mutation {
adminCreateIdentity(input: AdminCreateIdentityInput!): Identity
adminCreateUser(input: AdminCreateUserInput!): User
adminCreateIdentity(input: IdentityAdminCreateInput!): Identity
adminCreateUser(input: UserAdminCreateInput!): User
adminDeleteIdentity(identityId: String!): Boolean
adminDeleteUser(userId: String!): Boolean
adminUpdateUser(input: AdminUpdateUserInput!, userId: String!): User
anonVerifyIdentityChallenge(input: VerifyIdentityChallengeInput!): IdentityChallenge
adminUpdateUser(input: UserAdminUpdateInput!, userId: String!): User
anonVerifyIdentityChallenge(input: IdentityVerifyChallengeInput!): IdentityChallenge
login(input: LoginInput!): User
logout: Boolean
register(input: RegisterInput!): User
userDeleteIdentity(identityId: String!): Boolean
userLinkIdentity(input: LinkIdentityInput!): Identity
userUpdateUser(input: UserUpdateUserInput!): User
userVerifyIdentityChallenge(input: VerifyIdentityChallengeInput!): IdentityChallenge
userLinkIdentity(input: IdentityUserLinkInput!): Identity
userUpdateUser(input: UserUserUpdateInput!): User
userVerifyIdentityChallenge(input: IdentityVerifyChallengeInput!): IdentityChallenge
}

type PagingMeta {
Expand All @@ -128,29 +123,24 @@ type PagingMeta {
}

type Query {
adminFindManyIdentity(input: AdminFindManyIdentityInput!): [Identity!]
adminFindManyUser(input: AdminFindManyUserInput!): UserPaging!
adminFindManyIdentity(input: IdentityAdminFindManyInput!): [Identity!]
adminFindManyUser(input: UserAdminFindManyInput!): UserPaging!
adminFindOneUser(userId: String!): User
anonRequestIdentityChallenge(input: RequestIdentityChallengeInput!): IdentityChallenge
anonRequestIdentityChallenge(input: IdentityRequestChallengeInput!): IdentityChallenge
appConfig: AppConfig!
me: User
uptime: Float!
userFindManyIdentity(input: UserFindManyIdentityInput!): [Identity!]
userFindManyUser(input: UserFindManyUserInput!): UserPaging!
userFindManyIdentity(input: IdentityUserFindManyInput!): [Identity!]
userFindManyUser(input: UserUserFindManyInput!): UserPaging!
userFindOneUser(username: String!): User
userRequestIdentityChallenge(input: RequestIdentityChallengeInput!): IdentityChallenge
userRequestIdentityChallenge(input: IdentityRequestChallengeInput!): IdentityChallenge
}

input RegisterInput {
password: String!
username: String!
}

input RequestIdentityChallengeInput {
provider: IdentityProvider!
providerId: String!
}

type User {
avatarUrl: String
createdAt: DateTime
Expand All @@ -165,14 +155,26 @@ type User {
username: String
}

input UserFindManyIdentityInput {
input UserAdminCreateInput {
password: String
username: String!
}

input UserFindManyUserInput {
input UserAdminFindManyInput {
limit: Int = 10
page: Int = 1
role: UserRole
search: String
status: UserStatus
}

input UserAdminUpdateInput {
avatarUrl: String
developer: Boolean
name: String
role: UserRole
status: UserStatus
username: String
}

type UserPaging {
Expand All @@ -191,16 +193,14 @@ enum UserStatus {
Inactive
}

input UserUpdateUserInput {
input UserUserFindManyInput {
limit: Int = 10
page: Int = 1
search: String
}

input UserUserUpdateInput {
avatarUrl: String
developer: Boolean
name: String
}

input VerifyIdentityChallengeInput {
challenge: String!
provider: IdentityProvider!
providerId: String!
signature: String!
useLedger: Boolean = false
}
30 changes: 15 additions & 15 deletions apps/api-e2e/src/api/api-user-feature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
AdminCreateUserInput,
AdminFindManyUserInput,
AdminUpdateUserInput,
User,
UserAdminCreateInput,
UserAdminFindManyInput,
UserAdminUpdateInput,
UserRole,
UserStatus,
} from '@pubkey-stack/sdk'
Expand All @@ -22,7 +22,7 @@ describe('api-user-feature', () => {
})

it('should create a user', async () => {
const input: AdminCreateUserInput = {
const input: UserAdminCreateInput = {
username: uniqueId('user'),
password: uniqueId('pass'),
}
Expand All @@ -42,13 +42,13 @@ describe('api-user-feature', () => {
})

it('should update a user', async () => {
const createInput: AdminCreateUserInput = {
const createInput: UserAdminCreateInput = {
username: uniqueId('user'),
password: uniqueId('pass'),
}
const createdRes = await sdk.adminCreateUser({ input: createInput }, { cookie })
const userId = createdRes.data.created.id
const input: AdminUpdateUserInput = {
const input: UserAdminUpdateInput = {
avatarUrl: avatarUrl(createdRes.data.created.username),
name: 'John Doe',
role: UserRole.Admin,
Expand All @@ -65,15 +65,15 @@ describe('api-user-feature', () => {
})

it('should not update a user with an existing name', async () => {
const createInput: AdminCreateUserInput = {
const createInput: UserAdminCreateInput = {
username: uniqueId('user'),
password: uniqueId('pass'),
}
const createdRes = await sdk.adminCreateUser({ input: createInput }, { cookie })
const userId = createdRes.data.created.id
expect.assertions(1)

const input: AdminUpdateUserInput = {
const input: UserAdminUpdateInput = {
username: 'alice',
}
try {
Expand All @@ -84,14 +84,14 @@ describe('api-user-feature', () => {
})

it('should find a list of users (find all)', async () => {
const createInput: AdminCreateUserInput = {
const createInput: UserAdminCreateInput = {
username: uniqueId('user'),
password: uniqueId('pass'),
}
const createdRes = await sdk.adminCreateUser({ input: createInput }, { cookie })
const userId = createdRes.data.created.id

const input: AdminFindManyUserInput = {}
const input: UserAdminFindManyInput = {}

const res = await sdk.adminFindManyUser({ input }, { cookie })

Expand All @@ -102,14 +102,14 @@ describe('api-user-feature', () => {
})

it('should find a list of users (find new one)', async () => {
const createInput: AdminCreateUserInput = {
const createInput: UserAdminCreateInput = {
username: uniqueId('user'),
password: uniqueId('pass'),
}
const createdRes = await sdk.adminCreateUser({ input: createInput }, { cookie })
const userId = createdRes.data.created.id

const input: AdminFindManyUserInput = {
const input: UserAdminFindManyInput = {
search: userId,
}

Expand All @@ -121,7 +121,7 @@ describe('api-user-feature', () => {
})

it('should find a user by id', async () => {
const createInput: AdminCreateUserInput = {
const createInput: UserAdminCreateInput = {
username: uniqueId('user'),
password: uniqueId('pass'),
}
Expand All @@ -134,7 +134,7 @@ describe('api-user-feature', () => {
})

it('should delete a user', async () => {
const createInput: AdminCreateUserInput = {
const createInput: UserAdminCreateInput = {
username: uniqueId('user'),
password: uniqueId('pass'),
}
Expand All @@ -159,7 +159,7 @@ describe('api-user-feature', () => {

it('should not create a user', async () => {
expect.assertions(1)
const input: AdminCreateUserInput = {
const input: UserAdminCreateInput = {
username: uniqueId('user'),
password: uniqueId('pass'),
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function bootstrap() {
)
const host = `http://${core.config.host}:${core.config.port}`
await app.listen(core.config.port, core.config.host)
Logger.log(`🚀 RestAPI is running on: ${host}/${core.config.prefix}.`)
Logger.log(`🚀 RestAPI is running on: ${host}${core.config.prefix}.`)
Logger.log(`🚀 GraphQL is running on: ${host}/graphql.`)
Logger.log(`🔋 API_URL: ${core.config.apiUrl}`)
Logger.log(`🔋 WEB_URL: ${core.config.webUrl}`)
Expand Down
5 changes: 5 additions & 0 deletions libs/api/core/data-access/src/lib/dto/paging.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ export function PagingInput() {

return PagingInputClass
}

export interface PagingInputFields {
page?: number
limit?: number
}
14 changes: 7 additions & 7 deletions libs/api/identity/data-access/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export * from './lib/api-identity-data-admin.service'
export * from './lib/api-identity-data-user.service'
export * from './lib/api-identity.data-access.module'
export * from './lib/api-identity.service'
export * from './lib/api-identity-data-user.service'
export * from './lib/dto/admin-create-identity.input'
export * from './lib/dto/admin-find-many-identity.input'
export * from './lib/dto/link-identity-input'
export * from './lib/dto/request-identity-challenge.input'
export * from './lib/dto/user-find-many-identity-input'
export * from './lib/dto/verify-identity-challenge-input'
export * from './lib/dto/identity-admin-create.input'
export * from './lib/dto/identity-admin-find-many.input'
export * from './lib/dto/identity-request-challenge-input'
export * from './lib/dto/identity-user-find-many.input'
export * from './lib/dto/identity-user-link-input'
export * from './lib/dto/identity-verify-challenge-input'
export * from './lib/entity/identity-challenge.entity'
export * from './lib/entity/identity-provider.enum'
export * from './lib/entity/identity.entity'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Injectable } from '@nestjs/common'
import { Identity as PrismaIdentity } from '@prisma/client'
import { ApiCoreService } from '@pubkey-stack/api-core-data-access'
import { AdminCreateIdentityInput } from './dto/admin-create-identity.input'
import { AdminFindManyIdentityInput } from './dto/admin-find-many-identity.input'
import { IdentityAdminCreateInput } from './dto/identity-admin-create.input'
import { IdentityAdminFindManyInput } from './dto/identity-admin-find-many.input'

@Injectable()
export class ApiIdentityDataAdminService {
constructor(private readonly core: ApiCoreService) {}

async createIdentity(input: AdminCreateIdentityInput): Promise<PrismaIdentity> {
async createIdentity(input: IdentityAdminCreateInput): Promise<PrismaIdentity> {
const found = await this.core.data.identity.findUnique({
where: { provider_providerId: { providerId: input.providerId, provider: input.provider } },
})
Expand Down Expand Up @@ -40,7 +40,7 @@ export class ApiIdentityDataAdminService {
return true
}

async findManyIdentity(input: AdminFindManyIdentityInput): Promise<PrismaIdentity[]> {
async findManyIdentity(input: IdentityAdminFindManyInput): Promise<PrismaIdentity[]> {
const items = await this.core.data.identity.findMany({
where: {
ownerId: input.ownerId ? input.ownerId : undefined,
Expand Down
Loading
Loading