Create developer entity
This commit is contained in:
parent
aff93deef8
commit
866ffc55c7
16 changed files with 52 additions and 28 deletions
|
@ -1,7 +1,7 @@
|
|||
import { addSeconds, isAfter } from 'date-fns';
|
||||
import type { FastifyLoggerInstance } from 'fastify';
|
||||
import { nanoid } from 'nanoid';
|
||||
import type { ObjectID } from 'typeorm';
|
||||
import type User from './database/entities/user';
|
||||
import { UnknownCodeError } from './errors';
|
||||
import type { CodeChallenge, CodeContent, CodeInfo } from './types';
|
||||
import { createKey, decryptSymmetrical, encryptSymmetrical } from './utils';
|
||||
|
@ -12,7 +12,7 @@ export function createCode(options: {
|
|||
clientId: string;
|
||||
scopes: string[];
|
||||
studentIds: number[];
|
||||
userId: ObjectID;
|
||||
user: User;
|
||||
publicKey: string;
|
||||
tokenKey: string;
|
||||
encryptedPrivateKey: string;
|
||||
|
@ -31,7 +31,7 @@ export function createCode(options: {
|
|||
expires,
|
||||
id,
|
||||
clientId: options.clientId,
|
||||
userId: options.userId,
|
||||
user: options.user,
|
||||
scopes: options.scopes,
|
||||
studentIds: options.studentIds,
|
||||
publicKey: options.publicKey,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { Connection, Repository } from 'typeorm';
|
||||
import { createConnection } from 'typeorm';
|
||||
import Application from './entities/application';
|
||||
import Developer from './entities/developer';
|
||||
import Token from './entities/token';
|
||||
import User from './entities/user';
|
||||
|
||||
|
@ -13,6 +14,8 @@ class Database {
|
|||
|
||||
public tokenRepo!: Repository<Token>;
|
||||
|
||||
public developerRepo!: Repository<Developer>;
|
||||
|
||||
public async connect(): Promise<void> {
|
||||
this.connection = await createConnection({
|
||||
type: 'mongodb',
|
||||
|
@ -23,6 +26,7 @@ class Database {
|
|||
Application,
|
||||
User,
|
||||
Token,
|
||||
Developer,
|
||||
],
|
||||
useUnifiedTopology: true,
|
||||
logging: false,
|
||||
|
@ -30,6 +34,7 @@ class Database {
|
|||
this.applicationRepo = this.connection.getRepository(Application);
|
||||
this.userRepo = this.connection.getRepository(User);
|
||||
this.tokenRepo = this.connection.getRepository(Token);
|
||||
this.developerRepo = this.connection.getRepository(Developer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,9 @@ import { nanoid } from 'nanoid';
|
|||
import type { ObjectID } from 'typeorm';
|
||||
import {
|
||||
BaseEntity,
|
||||
Column, Entity, ObjectIdColumn,
|
||||
Column, Entity, ManyToOne, ObjectIdColumn,
|
||||
} from 'typeorm';
|
||||
import Developer from './developer';
|
||||
|
||||
@Entity()
|
||||
export default class Application extends BaseEntity {
|
||||
|
@ -31,8 +32,8 @@ export default class Application extends BaseEntity {
|
|||
@Column()
|
||||
public redirectUris!: string[];
|
||||
|
||||
@Column()
|
||||
public ownerGitHubLogin!: string;
|
||||
@ManyToOne(() => Developer)
|
||||
public developer!: Developer;
|
||||
|
||||
@Column()
|
||||
public homepage!: string | null;
|
||||
|
|
16
backend/src/database/entities/developer.ts
Normal file
16
backend/src/database/entities/developer.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import type { ObjectID } from 'typeorm';
|
||||
import {
|
||||
BaseEntity, Column, Entity, ObjectIdColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
export default class Developer extends BaseEntity {
|
||||
@ObjectIdColumn()
|
||||
public _id!: ObjectID;
|
||||
|
||||
@Column()
|
||||
public gitHubLogin!: string;
|
||||
|
||||
@Column()
|
||||
public gitHubId!: string;
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
import { nanoid } from 'nanoid';
|
||||
import type { ObjectID } from 'typeorm';
|
||||
import {
|
||||
BaseEntity, Column, Entity, ObjectIdColumn,
|
||||
BaseEntity, Column, Entity, ManyToOne, ObjectIdColumn,
|
||||
} from 'typeorm';
|
||||
import User from './user';
|
||||
|
||||
@Entity()
|
||||
export default class Token extends BaseEntity {
|
||||
|
@ -24,8 +25,8 @@ export default class Token extends BaseEntity {
|
|||
@Column()
|
||||
public clientId!: string;
|
||||
|
||||
@Column()
|
||||
public userId!: ObjectID;
|
||||
@ManyToOne(() => User)
|
||||
public user!: User;
|
||||
|
||||
@Column()
|
||||
public tokenSecret!: string;
|
||||
|
|
|
@ -111,7 +111,7 @@ export default function registerToken(server: MyFastifyInstance): void {
|
|||
token.scopes = codeInfo.scopes;
|
||||
token.studentIds = codeInfo.studentIds;
|
||||
token.tokenSecret = codeInfo.tokenSecret;
|
||||
token.userId = codeInfo.userId;
|
||||
token.user = codeInfo.user;
|
||||
token.encryptedPassword = codeInfo.encryptedPassword;
|
||||
token.encryptedPrivateKey = codeInfo.encryptedPrivateKey;
|
||||
token.encryptedSDK = codeInfo.encryptedSDK;
|
||||
|
|
|
@ -36,7 +36,7 @@ export default function registerAllow(server: MyFastifyInstance): void {
|
|||
if (!prompt) throw server.httpErrors.badRequest('Prompt data not found');
|
||||
if (!prompt.loginInfo) throw server.httpErrors.badRequest('Login data not provided');
|
||||
if (!prompt.loginInfo.symbolInfo) throw server.httpErrors.badRequest('Symbol not provided');
|
||||
if (!prompt.loginInfo.symbolInfo.userId) throw server.httpErrors.badRequest('User not registered');
|
||||
if (!prompt.loginInfo.symbolInfo.user) throw server.httpErrors.badRequest('User not registered');
|
||||
|
||||
const tokenKey = decryptSymmetrical(encryptedTokenKey, prompt.promptSecret);
|
||||
const serializedClient = JSON.parse(decryptSymmetrical(prompt.loginInfo.encryptedClient, tokenKey)) as SerializedClient;
|
||||
|
@ -67,7 +67,7 @@ export default function registerAllow(server: MyFastifyInstance): void {
|
|||
studentIds,
|
||||
scopes: prompt.scopes,
|
||||
clientId: prompt.clientId,
|
||||
userId: prompt.loginInfo.symbolInfo.userId,
|
||||
user: prompt.loginInfo.symbolInfo.user,
|
||||
publicKey: prompt.loginInfo.publicKey,
|
||||
encryptedSDK: newEncryptedSDK,
|
||||
encryptedPassword: prompt.loginInfo.encryptedPassword,
|
||||
|
|
|
@ -18,7 +18,7 @@ export default class PromptInfoApplication {
|
|||
public verified!: boolean;
|
||||
|
||||
@Field(() => GitHubUser)
|
||||
public owner!: GitHubUser;
|
||||
public developer!: GitHubUser;
|
||||
|
||||
@Field(() => String, {
|
||||
nullable: true,
|
||||
|
|
|
@ -40,7 +40,7 @@ export default class CreateUserResolver {
|
|||
user.loginIds = prompt.loginInfo.symbolInfo.loginIds;
|
||||
user.email = email;
|
||||
await database.userRepo.save(user);
|
||||
prompt.loginInfo.symbolInfo.userId = user._id;
|
||||
prompt.loginInfo.symbolInfo.user = user;
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
|
|
|
@ -33,6 +33,7 @@ export default class PromptInfoResolver implements ResolverInterface<PromptInfo>
|
|||
where: {
|
||||
clientId: prompt.clientId,
|
||||
},
|
||||
relations: ['developer'],
|
||||
});
|
||||
if (!application) throw new Error('Prompt data not found');
|
||||
return {
|
||||
|
@ -41,7 +42,7 @@ export default class PromptInfoResolver implements ResolverInterface<PromptInfo>
|
|||
iconColor: application.iconColor,
|
||||
verified: application.verified,
|
||||
homepage: application.homepage,
|
||||
owner: await getUser(application.ownerGitHubLogin),
|
||||
developer: await getUser(application.developer.gitHubLogin),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ export default class SetSymbolResolver {
|
|||
encryptedDiaries,
|
||||
loginIds,
|
||||
availableStudentIds: students.map(({ studentId }) => studentId),
|
||||
userId: user?._id,
|
||||
user,
|
||||
};
|
||||
return {
|
||||
students,
|
||||
|
|
|
@ -9,7 +9,7 @@ import type {
|
|||
RawServerDefault,
|
||||
} from 'fastify';
|
||||
import { registerEnumType } from 'type-graphql';
|
||||
import type { ObjectID } from 'typeorm';
|
||||
import type User from './database/entities/user';
|
||||
import type SessionData from './session-data';
|
||||
|
||||
export enum StudentsMode {
|
||||
|
@ -47,7 +47,7 @@ export interface AuthPrompt {
|
|||
encryptedDiaries: string;
|
||||
availableStudentIds: number[];
|
||||
loginIds: string[];
|
||||
userId?: ObjectID,
|
||||
user?: User,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ export interface CodeInfo {
|
|||
expires: Date;
|
||||
scopes: string[];
|
||||
clientId: string;
|
||||
userId: ObjectID,
|
||||
user: User,
|
||||
studentIds: number[];
|
||||
tokenSecret: string;
|
||||
publicKey: string;
|
||||
|
|
|
@ -65,14 +65,14 @@
|
|||
<v-list-item-subtitle class="text-overline">
|
||||
Twórca
|
||||
</v-list-item-subtitle>
|
||||
<v-list-item-title v-if="promptInfo.application.owner.name">
|
||||
{{ promptInfo.application.owner.name }}
|
||||
<v-list-item-title v-if="promptInfo.application.developer.name">
|
||||
{{ promptInfo.application.developer.name }}
|
||||
<span class="text--secondary">
|
||||
({{ promptInfo.application.owner.login }})
|
||||
({{ promptInfo.application.developer.login }})
|
||||
</span>
|
||||
</v-list-item-title>
|
||||
<v-list-item-title v-else>
|
||||
{{ promptInfo.application.owner.login }}
|
||||
{{ promptInfo.application.developer.login }}
|
||||
</v-list-item-title>
|
||||
</v-list-item-content>
|
||||
</v-list-item>
|
||||
|
|
|
@ -45,7 +45,7 @@ export type PromptInfoApplication = {
|
|||
iconUrl: Maybe<Scalars['String']>;
|
||||
iconColor: Scalars['String'];
|
||||
verified: Scalars['Boolean'];
|
||||
owner: GitHubUser;
|
||||
developer: GitHubUser;
|
||||
homepage: Maybe<Scalars['String']>;
|
||||
};
|
||||
|
||||
|
@ -161,7 +161,7 @@ export type GetPromptInfoQuery = (
|
|||
& { application: (
|
||||
{ __typename?: 'PromptInfoApplication' }
|
||||
& Pick<PromptInfoApplication, 'name' | 'iconUrl' | 'iconColor' | 'verified' | 'homepage'>
|
||||
& { owner: (
|
||||
& { developer: (
|
||||
{ __typename?: 'GitHubUser' }
|
||||
& Pick<GitHubUser, 'login' | 'name' | 'url'>
|
||||
); }
|
||||
|
@ -212,7 +212,7 @@ export const GetPromptInfoDocument = gql`
|
|||
iconColor
|
||||
verified
|
||||
homepage
|
||||
owner {
|
||||
developer {
|
||||
login
|
||||
name
|
||||
url
|
||||
|
|
|
@ -11,7 +11,7 @@ export default gql`query GetPromptInfo($promptId: String!) {
|
|||
iconColor
|
||||
verified
|
||||
homepage
|
||||
owner {
|
||||
developer {
|
||||
login
|
||||
name
|
||||
url
|
||||
|
|
|
@ -19,7 +19,7 @@ export interface PromptInfo {
|
|||
iconColor: string;
|
||||
verified: boolean;
|
||||
homepage: string | null;
|
||||
owner: {
|
||||
developer: {
|
||||
login: string;
|
||||
name: string | null;
|
||||
url: string;
|
||||
|
|
Loading…
Reference in a new issue