Skip to content

Commit

Permalink
Merge pull request #12 from IndustryFusion/feature/task-003-03-change…
Browse files Browse the repository at this point in the history
…s-in-asset-creation

Feature/task 003 03 changes in asset creation
  • Loading branch information
LahariMIBS authored Apr 17, 2024
2 parents 523c2cc + 8f87d62 commit cb9c135
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 56 deletions.
77 changes: 24 additions & 53 deletions backend/src/endpoints/asset/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,70 +24,41 @@ export class AssetService {

async create(data: any) {
try{
if(data.type && data.type == 'asset'){
let response = await this.assetModel.find({machine_serial_number: data.machine_serial_number});
if(!(response.length > 0)){
let uuid = uuidv5(data.machine_serial_number, this.ifricId);
let ifricId = `urn:ifric:IFX-EUR-NLD-AST-${uuid}`;
const urnData = new this.urnModel({
urn: ifricId,
created_at: moment().format(),
last_updated_at: moment().format()
})
await urnData.save();
let urnResponse = await this.urnModel.find({urn: ifricId});
if(urnResponse.length > 0){
const assetData = new this.assetModel({
machine_serial_number: data.machine_serial_number,
urn_id: urnResponse[0].id,
let objectSubTypeResponse = await this.objectSubTypeModel.find({object_sub_type_code: data.object_sub_type_code.toUpperCase()});
if(objectSubTypeResponse.length > 0){
let objectTypeData = await this.ObjectTypeModel.findById(objectSubTypeResponse[0].object_type_id);
if(objectTypeData && objectTypeData.object_type_code == data.object_type_code){
let response = await this.assetModel.find({machine_serial_number: data.machine_serial_number});
if(!(response.length > 0)){
let uuid = uuidv5(data.machine_serial_number, this.ifricId);
let ifricId = `urn:ifric:${data.dataspace_code.toLowerCase()}-${data.region_code.toLowerCase()}-${data.object_type_code.toLowerCase()}-${data.object_sub_type_code.toLowerCase()}-${uuid}`;
const urnData = new this.urnModel({
urn: ifricId,
created_at: moment().format(),
last_updated_at: moment().format()
})
await assetData.save();
return { status: 201, message: 'Asset created successfully', urn_id: ifricId };
} else{
return { status: 404, message: 'Urn ID does not exist' };
}
}else{
return { status: 400, message: 'Mahcine Serial Number already exists' };
}
}else{
let objectSubTypeResponse = await this.objectSubTypeModel.find({object_sub_type_code: data.object_sub_type_code.toUpperCase()});
if(objectSubTypeResponse.length > 0){
let objectTypeData = await this.ObjectTypeModel.findById(objectSubTypeResponse[0].object_type_id);
if(objectTypeData && objectTypeData.object_type_code == data.object_type_code){
let response = await this.assetModel.find({machine_serial_number: data.machine_serial_number});
if(!(response.length > 0)){
let uuid = uuidv5(data.machine_serial_number, this.ifricId);
let ifricId = `urn:ifric:${data.dataspace_code}-${data.region_code}-${data.object_type_code}-${data.object_sub_type_code}-${uuid}`;
const urnData = new this.urnModel({
urn: ifricId,
await urnData.save();
let urnResponse = await this.urnModel.find({urn: ifricId});
if(urnResponse.length > 0){
const assetData = new this.assetModel({
machine_serial_number: data.machine_serial_number,
urn_id: urnResponse[0].id,
created_at: moment().format(),
last_updated_at: moment().format()
})
await urnData.save();
let urnResponse = await this.urnModel.find({urn: ifricId});
if(urnResponse.length > 0){
const assetData = new this.assetModel({
machine_serial_number: data.machine_serial_number,
urn_id: urnResponse[0].id,
created_at: moment().format(),
last_updated_at: moment().format()
})
await assetData.save();
return { status: 201, message: 'Asset created successfully', urn_id: ifricId };
} else{
return { status: 404, message: 'Urn ID does not exist' };
}
}else{
return { status: 400, message: 'Mahcine Serial Number already exists' };
await assetData.save();
return { status: 201, message: 'Asset created successfully', urn_id: ifricId };
} else{
return { status: 404, message: 'Urn ID does not exist' };
}
}else{
return { status: 400, message: 'Invalid Object Sub Type Code' };
return { status: 400, message: 'Machine Serial Number already exists' };
}
}else{
return { status: 404, message: 'Object Sub Type Code does not exist' };
return { status: 400, message: 'Invalid Object Sub Type Code' };
}
}else{
return { status: 404, message: 'Object Sub Type Code does not exist' };
}
}catch(err){
return err;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/endpoints/company/company.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class CompanyService {
let response = await this.companyModel.find({registration_code: data.registration_code});
if(!response.length){
let uuid = uuidv5(data.country_code.toUpperCase() + data.registration_code, this.ifricId);
let ifricId = `urn:ifric:${data.dataspace_code}-${data.region_code}-${data.object_type_code}-${data.object_sub_type_code}-${uuid}`;
let ifricId = `urn:ifric:${data.dataspace_code.toLowerCase()}-${data.region_code.toLowerCase()}-${data.object_type_code.toLowerCase()}-${data.object_sub_type_code.toLowerCase()}-${uuid}`;
const urnData = new this.urnModel({
urn: ifricId,
created_at: moment().format(),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/endpoints/gateway/gateway.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class GatewayService {
let response = await this.serverModel.find({hardware_uuid: data.hardware_uuid});
if(!response.length){
let uuid = uuidv5(data.hardware_uuid + data.hardware_serial_number, this.ifricId);
let ifricId = `urn:ifric:${data.dataspace_code}-${data.region_code}-${data.object_type_code}-${data.object_sub_type_code}-${uuid}`;
let ifricId = `urn:ifric:${data.dataspace_code.toLowerCase()}-${data.region_code.toLowerCase()}-${data.object_type_code.toLowerCase()}-${data.object_sub_type_code.toLowerCase()}-${uuid}`;
const urnData = new this.urnModel({
urn: ifricId,
created_at: moment().format(),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/endpoints/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class UserService {
let response = await this.userModel.find({employee_code: data.employee_code});
if(!(response.length > 0)){
let uuid = uuidv5(data.employee_code, this.ifricId);
let ifricId = `urn:ifric:${data.dataspace_code}-${data.region_code}-${data.object_type_code}-${data.object_sub_type_code}-${uuid}`;
let ifricId = `urn:ifric:${data.dataspace_code.toLowerCase()}-${data.region_code.toLowerCase()}-${data.object_type_code.toLowerCase()}-${data.object_sub_type_code.toLowerCase()}-${uuid}`;
const urnData = new this.urnModel({
urn: ifricId,
created_at: moment().format(),
Expand Down

0 comments on commit cb9c135

Please sign in to comment.