Skip to content

Commit

Permalink
Merge pull request #1 from Duna-System/feat/ProjectsValidation
Browse files Browse the repository at this point in the history
testeValidation DB
  • Loading branch information
EliasFernandes03 authored Nov 1, 2023
2 parents 922e26e + 66cc785 commit 1bedc56
Show file tree
Hide file tree
Showing 58 changed files with 3,154 additions and 152 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Format and Build

on:
push:
branches: ['master']
pull_request:
branches: ['master']

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm install
- run: npx prettier -c .
- run: npm run build
2 changes: 1 addition & 1 deletion build/connection.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export declare function connectToDatabase(url: string): Promise<void>;
export declare function connectToDatabase(url: string, databaseName: string): Promise<void>;
export declare function checkConnectionStatus(): void;
export declare function subscribeToDatabaseEvents(): void;
10 changes: 8 additions & 2 deletions build/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.subscribeToDatabaseEvents = exports.checkConnectionStatus = exports.connectToDatabase = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs");
function connectToDatabase(url) {
function connectToDatabase(url, databaseName) {
return __awaiter(this, void 0, void 0, function* () {
yield mongoose_1.default.connect(url, {});
try {
yield mongoose_1.default.connect(`${url}/${databaseName}`, {});
console.log(`Conectado ao banco de dados: ${databaseName}`);
}
catch (error) {
throw error;
}
});
}
exports.connectToDatabase = connectToDatabase;
Expand Down
41 changes: 41 additions & 0 deletions build/entity/services/EntityService.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/// <reference types="mongoose/types/aggregate" />
/// <reference types="mongoose/types/callback" />
/// <reference types="mongoose/types/collection" />
/// <reference types="mongoose/types/connection" />
/// <reference types="mongoose/types/cursor" />
/// <reference types="mongoose/types/document" />
/// <reference types="mongoose/types/error" />
/// <reference types="mongoose/types/expressions" />
/// <reference types="mongoose/types/helpers" />
/// <reference types="mongoose/types/middlewares" />
/// <reference types="mongoose/types/indexes" />
/// <reference types="mongoose/types/models" />
/// <reference types="mongoose/types/mongooseoptions" />
/// <reference types="mongoose/types/pipelinestage" />
/// <reference types="mongoose/types/populate" />
/// <reference types="mongoose/types/query" />
/// <reference types="mongoose/types/schemaoptions" />
/// <reference types="mongoose/types/schematypes" />
/// <reference types="mongoose/types/session" />
/// <reference types="mongoose/types/types" />
/// <reference types="mongoose/types/utility" />
/// <reference types="mongoose/types/validation" />
/// <reference types="mongoose/types/virtuals" />
/// <reference types="mongoose" />
/// <reference types="mongoose/types/inferschematype" />
import { IEntityDb } from '../../interfaces';
export declare class EntityService {
protected model: import("mongoose").Model<IEntityDb, {}, {}, {}, import("mongoose").Document<unknown, {}, IEntityDb> & IEntityDb & Required<{
_id: string;
}>, any>;
protected configure(): void;
insert(entity: IEntityDb): Promise<IEntityDb>;
get(entity_id: string): Promise<IEntityDb>;
getByName(project_id: string, entity_name: string): Promise<IEntityDb>;
update(entity: IEntityDb): Promise<IEntityDb>;
remove(entity_id: string): Promise<void>;
removeAllFromUser(user_id: string): Promise<void>;
exists(entity_id: string): Promise<boolean>;
existsWithName(project_id: string, entity_name: string): Promise<boolean>;
listAllFromProject(project_id: string): Promise<IEntityDb[]>;
}
124 changes: 124 additions & 0 deletions build/entity/services/EntityService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityService = void 0;
const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs");
const connection_1 = require("../../connection");
const validationEntityModel_1 = require("../validationEntityModel");
class EntityService {
constructor() {
this.model = validationEntityModel_1.entityModel;
}
configure() { }
insert(entity) {
return __awaiter(this, void 0, void 0, function* () {
//Check if mongoDB is connected
(0, connection_1.checkConnectionStatus)();
const entity_record = new this.model(entity);
yield entity_record.save();
return entity_record.toJSON();
});
}
get(entity_id) {
return __awaiter(this, void 0, void 0, function* () {
//Check if mongoDB is connected
(0, connection_1.checkConnectionStatus)();
const entity_record = yield this.model.findById(entity_id).lean().exec();
if (!entity_record) {
const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist;
throw err;
}
return entity_record;
});
}
getByName(project_id, entity_name) {
return __awaiter(this, void 0, void 0, function* () {
//Check if mongoDB is connected
(0, connection_1.checkConnectionStatus)();
const entity_record = yield this.model
.findOne({ projectId: project_id, name: entity_name })
.lean()
.exec();
if (!entity_record) {
const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist;
throw err;
}
return entity_record;
});
}
update(entity) {
return __awaiter(this, void 0, void 0, function* () {
//Check if mongoDB is connected
(0, connection_1.checkConnectionStatus)();
const entity_record = yield this.model
.findByIdAndUpdate(entity._id, entity, {
new: true,
})
.lean()
.exec();
if (!entity_record) {
const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist;
throw err;
}
return entity_record;
});
}
remove(entity_id) {
return __awaiter(this, void 0, void 0, function* () {
//Check if mongoDB is connected
(0, connection_1.checkConnectionStatus)();
const exists = yield this.exists(entity_id);
if (!exists) {
const err = duna_web_platform_error_defs_1.ErrorMessages.EntityDoesNotExist;
throw err;
}
yield this.model.findByIdAndRemove(entity_id);
});
}
removeAllFromUser(user_id) {
return __awaiter(this, void 0, void 0, function* () {
//Check if mongoDB is connected
(0, connection_1.checkConnectionStatus)();
yield this.model.deleteMany({ user_id: user_id });
});
}
exists(entity_id) {
return __awaiter(this, void 0, void 0, function* () {
//Check if mongoDB is connected
(0, connection_1.checkConnectionStatus)();
const exists = (yield this.model.exists({ _id: entity_id }).lean().exec()) != null;
return exists;
});
}
existsWithName(project_id, entity_name) {
return __awaiter(this, void 0, void 0, function* () {
//Check if mongoDB is connected
(0, connection_1.checkConnectionStatus)();
const project = yield this.model
.findOne({ projectId: project_id, name: entity_name })
.lean()
.exec();
return project != null;
});
}
listAllFromProject(project_id) {
return __awaiter(this, void 0, void 0, function* () {
//Check if mongoDB is connected
(0, connection_1.checkConnectionStatus)();
const entities = yield this.model
.find({ proje: project_id })
.lean()
.exec();
return entities;
});
}
}
exports.EntityService = EntityService;
20 changes: 18 additions & 2 deletions build/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import { createUserCollectionWithValidation } from './users/validationDbUsers';
import { UserModel } from './users/validationUserModel';
import { IUsers } from './interfaces';
import { IMemberDb, IUser, IUsers } from './interfaces';
import { connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents } from './connection';
import { IEntityDb } from './interfaces';
import { IProjectDb } from './interfaces';
import { IOrganizationDb } from './interfaces';
import { entityModel } from './entity/validationEntityModel';
import { projectModel } from './projects/validationProjectsModel';
import { organizationModel } from './organizations/validationOrgModel';
import { createEntityCollectionWithValidation } from './entity/validationEntityDb';
export { createUserCollectionWithValidation, connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents, createEntityCollectionWithValidation, UserModel, entityModel, IUsers, IEntityDb };
import { createProjectCollectionWithValidation } from './projects/validationProjectsDb';
import { createOrganizationCollectionWithValidation } from './organizations/validationOrgDb';
import { createUserService } from './users/services/createUserService';
import { getUserByEmail } from './users/services/loginService';
import { deleteUserService } from './users/services/deleteUserService';
import { getOneUserService } from './users/services/getOneUserService';
import { getUsersService } from './users/services/getUsersService';
import { EntityService } from './entity/services/EntityService';
import { ProjectService } from './projects/services/ProjectService';
import { OrganizationService } from './organizations/services/OrganizationService';
import { updateUserService } from './users/services/updateUserService';
import { UserService } from './usersProject/UserService';
export { createUserCollectionWithValidation, connectToDatabase, checkConnectionStatus, subscribeToDatabaseEvents, createEntityCollectionWithValidation, createProjectCollectionWithValidation, createOrganizationCollectionWithValidation, deleteUserService, getOneUserService, getUsersService, createUserService, updateUserService, getUserByEmail, UserService, OrganizationService, EntityService, ProjectService, UserModel, entityModel, organizationModel, IUsers, IUser, IEntityDb, IProjectDb, projectModel, IOrganizationDb, IMemberDb, };
30 changes: 29 additions & 1 deletion build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 71 additions & 3 deletions build/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface IUsers extends Document {
export interface IUsers {
_id: string;
name: string;
lastName: string;
Expand All @@ -18,9 +18,77 @@ export interface IUsers extends Document {
export interface IEntityDb {
_id: string;
projectId: string;
type: string;
type: EntityType;
name: string;
location: string;
sizeMB: number;
shareGroup: string;
shareGroup: ShareGroupType;
}
export interface QuotaInfo {
pointCloudQuotaMB: number;
imageSizeQuotaMB: number;
BIMSizeQuotaMB: number;
pointCloudUsedMB: number;
imageUsedMB: number;
BIMUsedMB: number;
}
export interface IProjectDb {
_id: string;
user_id: string;
name: string;
clientName: string;
type: string;
snapshot?: string;
favorite: boolean;
quota: QuotaInfo;
clouds: Array<string>;
images: Array<string>;
bim: Array<string>;
createdAt: number;
modifiedAt: number;
publicAccessToken: string;
status: ProjectStatus;
owner?: string;
accessType?: ProjectAccessType;
}
export interface IOrganizationDb {
_id: string;
memberLimit: number;
members: Array<IMemberDb>;
name: string;
type: string;
}
export interface IMemberDb {
user: string;
role: OrganizationMemberRole;
}
export interface IUser {
_id: string;
name: string;
lastName: string;
email: string;
}
export declare enum OrganizationMemberRole {
VIEWER = "VIEWER",
EDITOR = "EDITOR",
ADMIN = "ADMIN",
OWNER = "OWNER"
}
export declare enum ProjectStatus {
IN_PROGRESS = "IN_PROGRESS",
FINISHED = "FINISHED"
}
export declare enum ProjectAccessType {
INTERNAL = "INTERNAL",
PRIVATE = "PRIVATE"
}
export declare enum ShareGroupType {
Public = "public",
Private = "private"
}
export declare enum EntityType {
PointCloud = "clouds",
Image = "images",
BIM = "bim",
Unknown = "unknown"
}
30 changes: 30 additions & 0 deletions build/interfaces.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityType = exports.ShareGroupType = exports.ProjectAccessType = exports.ProjectStatus = exports.OrganizationMemberRole = void 0;
var OrganizationMemberRole;
(function (OrganizationMemberRole) {
OrganizationMemberRole["VIEWER"] = "VIEWER";
OrganizationMemberRole["EDITOR"] = "EDITOR";
OrganizationMemberRole["ADMIN"] = "ADMIN";
OrganizationMemberRole["OWNER"] = "OWNER";
})(OrganizationMemberRole || (exports.OrganizationMemberRole = OrganizationMemberRole = {}));
var ProjectStatus;
(function (ProjectStatus) {
ProjectStatus["IN_PROGRESS"] = "IN_PROGRESS";
ProjectStatus["FINISHED"] = "FINISHED";
})(ProjectStatus || (exports.ProjectStatus = ProjectStatus = {}));
var ProjectAccessType;
(function (ProjectAccessType) {
ProjectAccessType["INTERNAL"] = "INTERNAL";
ProjectAccessType["PRIVATE"] = "PRIVATE";
})(ProjectAccessType || (exports.ProjectAccessType = ProjectAccessType = {}));
var ShareGroupType;
(function (ShareGroupType) {
ShareGroupType["Public"] = "public";
ShareGroupType["Private"] = "private";
})(ShareGroupType || (exports.ShareGroupType = ShareGroupType = {}));
var EntityType;
(function (EntityType) {
EntityType["PointCloud"] = "clouds";
EntityType["Image"] = "images";
EntityType["BIM"] = "bim";
EntityType["Unknown"] = "unknown";
})(EntityType || (exports.EntityType = EntityType = {}));
Loading

0 comments on commit 1bedc56

Please sign in to comment.