feat: public api
This commit is contained in:
parent
fbd977a21f
commit
0cbf2fbd44
|
|
@ -81,6 +81,10 @@ export class AuthMiddleware implements NestMiddleware {
|
|||
throw new HttpForbiddenException();
|
||||
}
|
||||
|
||||
if (!setOrg.apiKey) {
|
||||
await this._organizationService.updateApiKey(setOrg.id);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
req.user = user;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Role, SubscriptionTier } from '@prisma/client';
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthService } from '@gitroom/helpers/auth/auth.service';
|
||||
import { CreateOrgUserDto } from '@gitroom/nestjs-libraries/dtos/auth/create.org.user.dto';
|
||||
import { makeId } from '@gitroom/nestjs-libraries/services/make.is';
|
||||
|
||||
@Injectable()
|
||||
export class OrganizationRepository {
|
||||
|
|
@ -83,6 +84,17 @@ export class OrganizationRepository {
|
|||
});
|
||||
}
|
||||
|
||||
updateApiKey(orgId: string) {
|
||||
return this._organization.model.organization.update({
|
||||
where: {
|
||||
id: orgId,
|
||||
},
|
||||
data: {
|
||||
apiKey: AuthService.fixedEncryption(makeId(20)),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getOrgsByUserId(userId: string) {
|
||||
return this._organization.model.organization.findMany({
|
||||
where: {
|
||||
|
|
@ -183,6 +195,7 @@ export class OrganizationRepository {
|
|||
return this._organization.model.organization.create({
|
||||
data: {
|
||||
name: body.company,
|
||||
apiKey: AuthService.fixedEncryption(makeId(20)),
|
||||
users: {
|
||||
create: {
|
||||
role: Role.SUPERADMIN,
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ export class OrganizationService {
|
|||
return this._organizationRepository.getOrgsByUserId(userId);
|
||||
}
|
||||
|
||||
updateApiKey(orgId: string) {
|
||||
return this._organizationRepository.updateApiKey(orgId);
|
||||
}
|
||||
|
||||
getTeam(orgId: string) {
|
||||
return this._organizationRepository.getTeam(orgId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,24 +11,25 @@ datasource db {
|
|||
}
|
||||
|
||||
model Organization {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
description String?
|
||||
users UserOrganization[]
|
||||
media Media[]
|
||||
paymentId String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
github GitHub[]
|
||||
subscription Subscription?
|
||||
Integration Integration[]
|
||||
post Post[] @relation("organization")
|
||||
submittedPost Post[] @relation("submittedForOrg")
|
||||
Comments Comments[]
|
||||
notifications Notifications[]
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
description String?
|
||||
apiKey String?
|
||||
users UserOrganization[]
|
||||
media Media[]
|
||||
paymentId String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
github GitHub[]
|
||||
subscription Subscription?
|
||||
Integration Integration[]
|
||||
post Post[] @relation("organization")
|
||||
submittedPost Post[] @relation("submittedForOrg")
|
||||
Comments Comments[]
|
||||
notifications Notifications[]
|
||||
buyerOrganization MessagesGroup[]
|
||||
usedCodes UsedCodes[]
|
||||
credits Credits[]
|
||||
usedCodes UsedCodes[]
|
||||
credits Credits[]
|
||||
}
|
||||
|
||||
model User {
|
||||
|
|
|
|||
Loading…
Reference in New Issue